Start logging to file for debugging
This commit is contained in:
parent
9204f72e91
commit
7f5a75dd94
4 changed files with 30 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@ bin/
|
||||||
dist/
|
dist/
|
||||||
main
|
main
|
||||||
quickpassthrough
|
quickpassthrough
|
||||||
|
debug.log
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||||
|
"github.com/HikariKnight/quickpassthrough/internal/logger"
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/uname"
|
"github.com/HikariKnight/quickpassthrough/pkg/uname"
|
||||||
"github.com/klauspost/cpuid/v2"
|
"github.com/klauspost/cpuid/v2"
|
||||||
|
@ -83,6 +84,9 @@ func InitConfigs() {
|
||||||
|
|
||||||
// If the path exists
|
// If the path exists
|
||||||
if fileio.FileExist(syspath) {
|
if fileio.FileExist(syspath) {
|
||||||
|
// Write to log
|
||||||
|
logger.Printf("%s found on the system\nCreating %s", syspath, confpath)
|
||||||
|
|
||||||
// Create the directories for our configs
|
// Create the directories for our configs
|
||||||
err := os.MkdirAll(confpath, os.ModePerm)
|
err := os.MkdirAll(confpath, os.ModePerm)
|
||||||
errorcheck.ErrorCheck(err)
|
errorcheck.ErrorCheck(err)
|
||||||
|
@ -103,6 +107,9 @@ func InitConfigs() {
|
||||||
|
|
||||||
// If the file exists
|
// If the file exists
|
||||||
if fileio.FileExist(sysfile) {
|
if fileio.FileExist(sysfile) {
|
||||||
|
// Write to log
|
||||||
|
logger.Printf("%s found on the system\nCreating %s", sysfile, conffile)
|
||||||
|
|
||||||
// Create the directories for our configs
|
// Create the directories for our configs
|
||||||
file, err := os.Create(conffile)
|
file, err := os.Create(conffile)
|
||||||
errorcheck.ErrorCheck(err)
|
errorcheck.ErrorCheck(err)
|
||||||
|
|
12
internal/logger/logger.go
Normal file
12
internal/logger/logger.go
Normal 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...)
|
||||||
|
}
|
|
@ -4,17 +4,25 @@ package internal
|
||||||
// from the Bubbles component library.
|
// from the Bubbles component library.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This is where we build everything
|
// This is where we build everything
|
||||||
func Tui() {
|
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
|
// Make a blank model to keep our state in
|
||||||
m := NewModel()
|
m := NewModel()
|
||||||
|
|
||||||
// Start the program with the model
|
// Start the program with the model
|
||||||
p := tea.NewProgram(m, tea.WithAltScreen())
|
p := tea.NewProgram(m, tea.WithAltScreen())
|
||||||
_, err := p.Run()
|
_, err = p.Run()
|
||||||
errorcheck.ErrorCheck(err, "Failed to initialize UI")
|
errorcheck.ErrorCheck(err, "Failed to initialize UI")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue