Added logging to file feature
This commit is contained in:
parent
579450a537
commit
4306a9bca5
8
adept.go
8
adept.go
@ -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
29
config/log.go
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user