project move

This commit is contained in:
Pavel Vorobyov
2019-09-24 11:04:48 +03:00
parent eb2a495406
commit 7e2dec0ef0
33 changed files with 5613 additions and 1 deletions

47
log/log.go Normal file
View File

@@ -0,0 +1,47 @@
package log
import (
"io/ioutil"
"os"
logging "github.com/op/go-logging"
)
var (
logger = logging.MustGetLogger("xc")
logfile *os.File
initialized = false
// Debug proxy
Debug = logger.Debug
// Debugf proxy
Debugf = logger.Debugf
)
// Initialize logger
func Initialize(logFilename string) error {
if logFilename == "" {
setupNullLogger()
return nil
}
logfile, err := os.OpenFile(logFilename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
setupNullLogger()
return err
}
backend := logging.NewLogBackend(logfile, "", 0)
format := logging.MustStringFormatter(
`[%{time:15:04:05.000}] %{message}`,
)
backendFormatter := logging.NewBackendFormatter(backend, format)
logging.SetBackend(backendFormatter)
logger.Debug("logger initialized")
initialized = true
return nil
}
func setupNullLogger() {
backend := logging.NewLogBackend(ioutil.Discard, "", 0)
logging.SetBackend(backend)
}