initial
This commit is contained in:
commit
25439eab5b
10 changed files with 185 additions and 0 deletions
48
config/logging.go
Normal file
48
config/logging.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func LogSetup(mode, lvl string) {
|
||||
l, err := logrus.ParseLevel(lvl)
|
||||
if err != nil {
|
||||
l = logrus.InfoLevel
|
||||
}
|
||||
|
||||
logrus.SetLevel(l)
|
||||
|
||||
switch mode {
|
||||
case "release":
|
||||
case "dev":
|
||||
{
|
||||
logrus.SetReportCaller(true)
|
||||
logrus.SetFormatter(&CustomFormatter{})
|
||||
logrus.SetOutput(os.Stdout)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type CustomFormatter struct{}
|
||||
|
||||
func (f *CustomFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
||||
timestamp := entry.Time.Format("2006-01-02 15:04:05")
|
||||
level := strings.ToUpper(entry.Level.String())
|
||||
msg := entry.Message
|
||||
|
||||
file := ""
|
||||
line := 0
|
||||
if entry.Caller != nil {
|
||||
file = filepath.Base(entry.Caller.File)
|
||||
line = entry.Caller.Line
|
||||
}
|
||||
|
||||
logLine := fmt.Sprintf("[%s][%s][%s:%d] %s\n",
|
||||
level, timestamp, file, line, msg)
|
||||
|
||||
return []byte(logLine), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue