adept/config/log.go
Gregory Ballantine 4306a9bca5
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
Added logging to file feature
2022-09-02 18:17:42 -04:00

30 lines
538 B
Go

package config
import (
"log"
"os"
"github.com/spf13/viper"
"git.metaunix.net/BitGoblin/adept/util"
)
func InitLogging() *os.File {
var fileHandle *os.File = nil
if viper.GetBool("log_to_file") {
// open a file
var err error
fileHandle, err = os.OpenFile(util.ResolveTilde(viper.GetString("log_file")), os.O_APPEND | os.O_CREATE | os.O_RDWR, 0644)
if err != nil {
log.Fatalf("Error opening log file: %v", err)
os.Exit(1)
}
// set logging to file handle
log.SetOutput(fileHandle)
}
return fileHandle
}