Added logging to file feature
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-09-02 18:17:42 -04:00
parent 579450a537
commit 4306a9bca5
2 changed files with 37 additions and 0 deletions

View File

@ -13,8 +13,16 @@ import (
)
func main() {
// load configuration via Viper
config.LoadConfig()
// configure our app logging
logHandle := config.InitLogging()
if logHandle != nil {
defer logHandle.Close()
}
// initialize the video repository
r := transcoder.NewRepository(viper.GetString("transcoder.repository"))
// main program loop - runs infinitely until externally terminated

29
config/log.go Normal file
View File

@ -0,0 +1,29 @@
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
}