log to file
This commit is contained in:
@@ -70,7 +70,7 @@ func runGameIntegrated(parentWindow fyne.Window, shellCmd string) error {
|
||||
scanner := bufio.NewScanner(stdout)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
log.Debugf("GAME STDOUT: %s", line)
|
||||
log.WineLoggerStdout(line)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -78,7 +78,7 @@ func runGameIntegrated(parentWindow fyne.Window, shellCmd string) error {
|
||||
scanner := bufio.NewScanner(stderr)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
log.Debugf("GAME STDERR: %s", line)
|
||||
log.WineLoggerStderr(line)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -200,29 +200,12 @@ func continueLaunch(myWindow fyne.Window, wowExePath string) {
|
||||
utils.QuotePathForShell(wineloader2Path),
|
||||
utils.QuotePathForShell(wowExePath))
|
||||
|
||||
// Check user preference for terminal display
|
||||
prefs, _ := utils.LoadPrefs()
|
||||
|
||||
if prefs.ShowTerminalNormally {
|
||||
// Use the old method with external Terminal.app
|
||||
escapedShellCmd := utils.EscapeStringForAppleScript(shellCmd)
|
||||
cmd2Script := fmt.Sprintf("tell application \"Terminal\" to do script \"%s\"", escapedShellCmd)
|
||||
|
||||
log.Debug("Executing WoW launch command via AppleScript...")
|
||||
if !utils.RunOsascript(cmd2Script, myWindow) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Debug("Launch command executed. Check the new terminal window.")
|
||||
} else {
|
||||
// Use integrated terminal
|
||||
log.Debugf("Shell command for integrated terminal: %s", shellCmd)
|
||||
log.Debug("Executing WoW launch command with integrated terminal...")
|
||||
if err := runGameIntegrated(myWindow, shellCmd); err != nil {
|
||||
dialog.ShowError(fmt.Errorf("failed to launch game: %v", err), myWindow)
|
||||
return
|
||||
}
|
||||
log.Debug("Game launched with integrated terminal. Check the application logs for output.")
|
||||
// Use integrated terminal
|
||||
log.Debugf("Shell command for integrated terminal: %s", shellCmd)
|
||||
log.Debug("Executing WoW launch command with integrated terminal...")
|
||||
if err := runGameIntegrated(myWindow, shellCmd); err != nil {
|
||||
dialog.ShowError(fmt.Errorf("failed to launch game: %v", err), myWindow)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,44 +2,87 @@ package log
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const ApplicationSupportDir = "/Library/Application Support/EpochSilicon"
|
||||
|
||||
var (
|
||||
logger zerolog.Logger
|
||||
logFilePointer *os.File
|
||||
logFilePath = filepath.Join(ApplicationSupportDir, "EpochSilicon.log")
|
||||
logger zerolog.Logger
|
||||
wineLogger zerolog.Logger
|
||||
)
|
||||
|
||||
func SetupLogging() {
|
||||
logFilePointer = nil
|
||||
ToConsole(zerolog.DebugLevel)
|
||||
}
|
||||
|
||||
func Close() {
|
||||
if logFilePointer != nil {
|
||||
logFilePointer.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func ToFile(level zerolog.Level) {
|
||||
Close()
|
||||
var err error
|
||||
logFilePointer, err = os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
// App logs
|
||||
path, err := getLogfilePath()
|
||||
if err != nil {
|
||||
logger.Error().Msg(err.Error())
|
||||
log.Error().Err(err).Str("path", path).Msg("Failed to get log path")
|
||||
return
|
||||
}
|
||||
multi := zerolog.MultiLevelWriter(logFilePointer, os.Stdout)
|
||||
logger = zerolog.New(multi).With().Timestamp().Logger().Level(level)
|
||||
|
||||
var mw io.Writer
|
||||
l := createLogWriter(path, 10, 3)
|
||||
if l != nil {
|
||||
mw = io.MultiWriter(zerolog.ConsoleWriter{Out: os.Stdout}, l)
|
||||
} else {
|
||||
mw = io.MultiWriter(zerolog.ConsoleWriter{Out: os.Stdout})
|
||||
}
|
||||
logger = zerolog.New(mw).With().Timestamp().Logger()
|
||||
SetLevelInfo()
|
||||
|
||||
// Wine logs
|
||||
wineLogPath, err := getWineLogfilePath()
|
||||
if err != nil {
|
||||
Errorf("Failed to get wine log path: %v", err)
|
||||
return
|
||||
}
|
||||
l = createLogWriter(wineLogPath, 25, 1)
|
||||
if l != nil {
|
||||
mw = io.MultiWriter(zerolog.ConsoleWriter{Out: os.Stdout}, l)
|
||||
} else {
|
||||
mw = io.MultiWriter(zerolog.ConsoleWriter{Out: os.Stdout})
|
||||
}
|
||||
wineLogger = zerolog.New(mw).With().Timestamp().Logger()
|
||||
wineLogger.Level(zerolog.InfoLevel)
|
||||
}
|
||||
|
||||
func ToConsole(level zerolog.Level) {
|
||||
Close()
|
||||
logger = zerolog.New(os.Stdout).With().Timestamp().Logger().Level(level)
|
||||
func createLogWriter(path string, maxSize int, maxBackups int) io.Writer {
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
log.Error().Err(err).Str("path", path).Msg("Failed to create log path")
|
||||
return nil
|
||||
}
|
||||
|
||||
return &lumberjack.Logger{
|
||||
Filename: path,
|
||||
MaxSize: maxSize,
|
||||
MaxBackups: maxBackups,
|
||||
}
|
||||
}
|
||||
|
||||
func SetLevelDebug() {
|
||||
logger.Level(zerolog.DebugLevel)
|
||||
}
|
||||
|
||||
func SetLevelInfo() {
|
||||
logger.Level(zerolog.InfoLevel)
|
||||
}
|
||||
|
||||
func getLogfilePath() (string, error) {
|
||||
dir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(dir, "EpochSilicon", "epochsilicon.log"), nil
|
||||
}
|
||||
|
||||
func getWineLogfilePath() (string, error) {
|
||||
dir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(dir, "EpochSilicon", "epochsilicon.log"), nil
|
||||
}
|
||||
|
||||
func Debug(msg string) {
|
||||
@@ -89,3 +132,11 @@ func Panic(msg string) {
|
||||
func Panicf(format string, args ...interface{}) {
|
||||
logger.Panic().Msgf(format, args...)
|
||||
}
|
||||
|
||||
func WineLoggerStdout(msg string) {
|
||||
wineLogger.Info().Msgf("STDOUT: %s", msg)
|
||||
}
|
||||
|
||||
func WineLoggerStderr(msg string) {
|
||||
wineLogger.Info().Msgf("STDERR: %s", msg)
|
||||
}
|
||||
|
@@ -41,6 +41,21 @@ func createOptionsComponents() {
|
||||
})
|
||||
showTerminalCheckbox.SetChecked(prefs.ShowTerminalNormally)
|
||||
|
||||
advancedLoggingCheckbox = widget.NewCheck("Advanced Logging", func(checked bool) {
|
||||
// Save to preferences
|
||||
prefs, _ := utils.LoadPrefs()
|
||||
prefs.AdvancedLogging = checked
|
||||
utils.SavePrefs(prefs)
|
||||
log.Debugf("Advanced logging set to %v", checked)
|
||||
|
||||
if checked {
|
||||
log.SetLevelDebug()
|
||||
} else {
|
||||
log.SetLevelInfo()
|
||||
}
|
||||
})
|
||||
advancedLoggingCheckbox.SetChecked(prefs.AdvancedLogging)
|
||||
|
||||
autoDeleteWdbCheckbox = widget.NewCheck("Auto-delete WDB directory on launch", func(checked bool) {
|
||||
launcher.AutoDeleteWdb = checked
|
||||
// Save to preferences
|
||||
|
@@ -30,6 +30,7 @@ func showOptionsPopup() {
|
||||
generalContainer := container.NewVBox(
|
||||
generalTitle,
|
||||
widget.NewSeparator(),
|
||||
advancedLoggingCheckbox,
|
||||
metalHudCheckbox,
|
||||
showTerminalCheckbox,
|
||||
autoDeleteWdbCheckbox,
|
||||
@@ -222,11 +223,11 @@ func showTroubleshootingPopup() {
|
||||
troubleshootingCloseButton = widget.NewButton("Close", func() {})
|
||||
|
||||
popupContent := container.NewBorder(
|
||||
nil, // top
|
||||
nil, // top
|
||||
container.NewCenter(troubleshootingCloseButton), // bottom
|
||||
nil, // left
|
||||
nil, // right
|
||||
container.NewPadded(scrollContainer), // center
|
||||
nil, // left
|
||||
nil, // right
|
||||
container.NewPadded(scrollContainer), // center
|
||||
)
|
||||
|
||||
windowSize := currentWindow.Content().Size()
|
||||
|
@@ -28,9 +28,10 @@ var (
|
||||
stopServiceButton *widget.Button
|
||||
|
||||
// Option checkboxes
|
||||
metalHudCheckbox *widget.Check
|
||||
showTerminalCheckbox *widget.Check
|
||||
autoDeleteWdbCheckbox *widget.Check
|
||||
metalHudCheckbox *widget.Check
|
||||
showTerminalCheckbox *widget.Check
|
||||
autoDeleteWdbCheckbox *widget.Check
|
||||
advancedLoggingCheckbox *widget.Check
|
||||
|
||||
// Recommended settings button
|
||||
applyRecommendedSettingsButton *widget.Button
|
||||
|
@@ -16,6 +16,7 @@ type UserPrefs struct {
|
||||
RemapOptionAsAlt bool `json:"remap_option_as_alt"`
|
||||
AutoDeleteWdb bool `json:"auto_delete_wdb"`
|
||||
EnableMetalHud bool `json:"enable_metal_hud"`
|
||||
AdvancedLogging bool `json:"advanced_logging"`
|
||||
}
|
||||
|
||||
func getPrefsPath() (string, error) {
|
||||
|
Reference in New Issue
Block a user