1
0
Fork 0
forked from forgejo/forgejo

Use gitea forked macaron (#7933)

Signed-off-by: Tamal Saha <tamal@appscode.com>
This commit is contained in:
Tamal Saha 2019-08-23 09:40:30 -07:00 committed by techknowlogick
parent ca6fb004ac
commit 171b359877
408 changed files with 14882 additions and 13217 deletions

View file

@ -36,6 +36,7 @@ const (
TEXTFORMATTER = LogEntryFormatter(iota)
JSONFORMATTER
KVFORMATTER
UNIFORMFORMATTER
)
func (level Level) String() string {
@ -476,6 +477,6 @@ func Stackf(level Level, fmt string, args ...interface{}) {
}
func init() {
logger = NewLogger(os.Stderr, INFO, TEXTFORMATTER)
logger := NewLogger(os.Stderr, INFO, TEXTFORMATTER)
SetLogger(logger)
}

View file

@ -1,4 +1,4 @@
// Copyright (c) 2016 Couchbase, Inc.
// Copyright (c) 2016-2019 Couchbase, Inc.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
@ -31,7 +31,7 @@ const (
_RLEVEL = "_rlevel"
)
func NewLogger(out io.Writer, lvl Level, fmtLogging LogEntryFormatter) *goLogger {
func NewLogger(out io.Writer, lvl Level, fmtLogging LogEntryFormatter, fmtArgs ...interface{}) *goLogger {
logger := &goLogger{
logger: log.New(out, "", 0),
level: lvl,
@ -40,6 +40,10 @@ func NewLogger(out io.Writer, lvl Level, fmtLogging LogEntryFormatter) *goLogger
logger.entryFormatter = &jsonFormatter{}
} else if fmtLogging == KVFORMATTER {
logger.entryFormatter = &keyvalueFormatter{}
} else if fmtLogging == UNIFORMFORMATTER {
logger.entryFormatter = &uniformFormatter{
callback: fmtArgs[0].(ComponentCallback),
}
} else {
logger.entryFormatter = &textFormatter{}
}
@ -316,3 +320,46 @@ func (*jsonFormatter) format(newEntry *logEntry) string {
s := bytes.NewBuffer(append(serialized, '\n'))
return s.String()
}
type ComponentCallback func() string
type uniformFormatter struct {
callback ComponentCallback
}
// ex. 2019-03-15T11:28:07.652-04:00 DEBU COMPONENT.subcomponent This is a message from test in uniform format
var _LEVEL_UNIFORM = []string{
DEBUG: "DEBU",
TRACE: "TRAC",
REQUEST: "REQU",
INFO: "INFO",
WARN: "WARN",
ERROR: "ERRO",
SEVERE: "SEVE",
FATAL: "FATA",
NONE: "NONE",
}
func (level Level) UniformString() string {
return _LEVEL_UNIFORM[level]
}
func (uf *uniformFormatter) format(newEntry *logEntry) string {
b := &bytes.Buffer{}
appendValue(b, newEntry.Time)
component := uf.callback()
if newEntry.Rlevel != NONE {
// not really any accommodation for a composite level in the uniform standard; just output as abbr,abbr
fmt.Fprintf(b, "%s,%s %s ", newEntry.Level.UniformString(), newEntry.Rlevel.UniformString(), component)
} else {
fmt.Fprintf(b, "%s %s ", newEntry.Level.UniformString(), component)
}
appendValue(b, newEntry.Message)
for key, value := range newEntry.Data {
appendKeyValue(b, key, value)
}
b.WriteByte('\n')
s := bytes.NewBuffer(b.Bytes())
return s.String()
}