update go app
This commit is contained in:
20
config/logger.go
Normal file
20
config/logger.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// InitializeLogger sets up logging to a file.
|
||||
func InitializeLogger(logFileName string) {
|
||||
// Open the log file for writing (create if it doesn't exist, append if it does)
|
||||
file, err := os.OpenFile(logFileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open log file: %v", err)
|
||||
}
|
||||
|
||||
// Set the output of the default logger to the file
|
||||
log.SetOutput(file)
|
||||
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
||||
log.Println("Logging initialized")
|
||||
}
|
||||
Reference in New Issue
Block a user