30 lines
538 B
Go
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
|
||
|
}
|