Write logs under user config
This commit is contained in:
parent
83fdae4e3b
commit
44e51f3c8b
19
main.go
19
main.go
|
|
@ -221,13 +221,19 @@ Command: ffmpeg %s
|
||||||
|
|
||||||
func getLogsDir() string {
|
func getLogsDir() string {
|
||||||
logsDirOnce.Do(func() {
|
logsDirOnce.Do(func() {
|
||||||
// Prefer a logs folder next to the executable
|
// Prefer user config dir for logs
|
||||||
if exe, err := os.Executable(); err == nil {
|
if cfgDir, err := os.UserConfigDir(); err == nil && cfgDir != "" {
|
||||||
if dir := filepath.Dir(exe); dir != "" {
|
logsDirPath = filepath.Join(cfgDir, "VideoTools", "logs")
|
||||||
logsDirPath = filepath.Join(dir, "logs")
|
}
|
||||||
|
// Fallback to logs folder next to the executable
|
||||||
|
if logsDirPath == "" {
|
||||||
|
if exe, err := os.Executable(); err == nil {
|
||||||
|
if dir := filepath.Dir(exe); dir != "" {
|
||||||
|
logsDirPath = filepath.Join(dir, "logs")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Fallback to cwd/logs
|
// Final fallback to cwd/logs
|
||||||
if logsDirPath == "" {
|
if logsDirPath == "" {
|
||||||
logsDirPath = filepath.Join(".", "logs")
|
logsDirPath = filepath.Join(".", "logs")
|
||||||
}
|
}
|
||||||
|
|
@ -6134,6 +6140,9 @@ func (s *appState) stopPlayer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if os.Getenv("VIDEOTOOLS_LOG_FILE") == "" {
|
||||||
|
_ = os.Setenv("VIDEOTOOLS_LOG_FILE", filepath.Join(getLogsDir(), "videotools.log"))
|
||||||
|
}
|
||||||
logging.Init()
|
logging.Init()
|
||||||
defer logging.Close()
|
defer logging.Close()
|
||||||
defer logging.RecoverPanic() // Catch and log any panics with stack trace
|
defer logging.RecoverPanic() // Catch and log any panics with stack trace
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user