Start logging to file for debugging

This commit is contained in:
HikariKnight 2023-04-10 13:10:19 +02:00
parent 9204f72e91
commit 7f5a75dd94
4 changed files with 30 additions and 2 deletions

3
.gitignore vendored
View file

@ -5,4 +5,5 @@ utils.old/
bin/
dist/
main
quickpassthrough
quickpassthrough
debug.log

View file

@ -6,6 +6,7 @@ import (
"regexp"
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
"github.com/HikariKnight/quickpassthrough/internal/logger"
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
"github.com/HikariKnight/quickpassthrough/pkg/uname"
"github.com/klauspost/cpuid/v2"
@ -83,6 +84,9 @@ func InitConfigs() {
// If the path exists
if fileio.FileExist(syspath) {
// Write to log
logger.Printf("%s found on the system\nCreating %s", syspath, confpath)
// Create the directories for our configs
err := os.MkdirAll(confpath, os.ModePerm)
errorcheck.ErrorCheck(err)
@ -103,6 +107,9 @@ func InitConfigs() {
// If the file exists
if fileio.FileExist(sysfile) {
// Write to log
logger.Printf("%s found on the system\nCreating %s", sysfile, conffile)
// Create the directories for our configs
file, err := os.Create(conffile)
errorcheck.ErrorCheck(err)

12
internal/logger/logger.go Normal file
View file

@ -0,0 +1,12 @@
package logger
import (
"fmt"
"log"
)
// Formats our log output to \n%s\n\n for readability
func Printf(content string, v ...any) {
content = fmt.Sprintf("\n%s\n\n", content)
log.Printf(content, v...)
}

View file

@ -4,17 +4,25 @@ package internal
// from the Bubbles component library.
import (
"os"
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
tea "github.com/charmbracelet/bubbletea"
)
// This is where we build everything
func Tui() {
// Log all errors to a new logfile
os.Remove("debug.log")
logfile, err := tea.LogToFile("debug.log", "")
errorcheck.ErrorCheck(err, "Error creating log file")
defer logfile.Close()
// Make a blank model to keep our state in
m := NewModel()
// Start the program with the model
p := tea.NewProgram(m, tea.WithAltScreen())
_, err := p.Run()
_, err = p.Run()
errorcheck.ErrorCheck(err, "Failed to initialize UI")
}