fix debug mode

This commit is contained in:
andrzej 2024-11-05 22:02:46 +01:00
parent 22d8316f12
commit 1aad6429ae
1 changed files with 5 additions and 10 deletions

15
main.go
View File

@ -20,6 +20,7 @@ var elog = log.New(os.Stdout, "ERROR: ", 3)
func main() {
//SETUP FLAGS
var debugFlag = flag.Bool("debug", false, "help message for flag n")
var dirFlag = flag.String("dir", "", "help message")
flag.Parse()
clog.Println("Welcome to GoPaper!")
@ -47,21 +48,14 @@ func main() {
go slideshow(slideshowDir)
}()
var dir string
args := os.Args[1:]
if len(args) > 0 {
dir = args[0]
} else {
dir = config.Default
}
slideshowDir <- dir
slideshowDir <- *dirFlag
waitGroup.Wait()
}
func openLogfile() (*os.File, error) {
//TODO: log rotation
f, err := os.OpenFile(config.Cache+"/logfile", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
f, err := os.OpenFile(config.Cache+"logfile", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return nil, err
}
@ -136,7 +130,7 @@ func handleProcesses() {
}
func setupLogging(debug bool) {
clog.Printf("debug: %v", debug)
//SETUP LOGGERS
if debug {
logfile, err := openLogfile()
@ -144,6 +138,7 @@ func setupLogging(debug bool) {
elog.Println("failed to load config", err)
os.Exit(1)
}
clog.Printf("Logging to %v", logfile.Name())
log.SetOutput(logfile)
clog.SetOutput(logfile)
elog.SetOutput(logfile)