route/vendor/github.com/koding/logging/custom.go

41 lines
874 B
Go
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package logging
import (
"fmt"
"os"
"strings"
)
type CustomFormatter struct{}
func (f *CustomFormatter) Format(rec *Record) string {
paths := strings.Split(rec.Filename, string(os.PathSeparator))
// does even anyone uses root folder as their gopath?
filePath := strings.Join(paths[len(paths)-2:], string(os.PathSeparator))
return fmt.Sprintf("%-24s %-8s [%-15s][PID:%d][%s:%d] %s",
rec.Time.UTC().Format("2006-01-02T15:04:05.999Z"),
LevelNames[rec.Level],
rec.LoggerName,
rec.ProcessID,
filePath,
rec.Line,
fmt.Sprintf(rec.Format, rec.Args...),
)
}
func NewCustom(name string, debug bool) Logger {
log := NewLogger(name)
logHandler := NewWriterHandler(os.Stderr)
logHandler.Formatter = &CustomFormatter{}
logHandler.Colorize = true
log.SetHandler(logHandler)
if debug {
log.SetLevel(DEBUG)
logHandler.SetLevel(DEBUG)
}
return log
}