mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
+14









Ben Schumacher
GitHub
Jesse Hallam
Michael Kochell
Alejandro García Montoro
Alex Dovenmuehle
Michael Kochell
Christopher Poile
İlker Göktuğ Öztürk
Shota Gvinepadze
Ali Farooq
Maria A Nunez
Daniel Espino García
Christopher Speller
Alex Dovenmuehle
Szymon Gibała
Lev
Jason Frerich
Agniva De Sarker
Artur M. Wolff
Madhav Hugar
Joe
Ibrahim Serdar Acikgoz
José Peso
ba79c48dca
Include https://github.com/mattermost/mattermost-plugin-api into the mono repo Co-authored-by: Jesse Hallam <[email protected]> Co-authored-by: Michael Kochell <[email protected]> Co-authored-by: Alejandro García Montoro <[email protected]> Co-authored-by: Ben Schumacher <[email protected]> Co-authored-by: Alex Dovenmuehle <[email protected]> Co-authored-by: Michael Kochell <[email protected]> Co-authored-by: Christopher Poile <[email protected]> Co-authored-by: İlker Göktuğ Öztürk <[email protected]> Co-authored-by: Shota Gvinepadze <[email protected]> Co-authored-by: Ali Farooq <[email protected]> Co-authored-by: Maria A Nunez <[email protected]> Co-authored-by: Daniel Espino García <[email protected]> Co-authored-by: Christopher Speller <[email protected]> Co-authored-by: Alex Dovenmuehle <[email protected]> Co-authored-by: Szymon Gibała <[email protected]> Co-authored-by: Lev <[email protected]> Co-authored-by: Jason Frerich <[email protected]> Co-authored-by: Agniva De Sarker <[email protected]> Co-authored-by: Artur M. Wolff <[email protected]> Co-authored-by: Madhav Hugar <[email protected]> Co-authored-by: Joe <[email protected]> Co-authored-by: Ibrahim Serdar Acikgoz <[email protected]> Co-authored-by: José Peso <[email protected]>
79 lines
1.7 KiB
Go
79 lines
1.7 KiB
Go
package logger
|
|
|
|
import "time"
|
|
|
|
const (
|
|
timed = "__since"
|
|
elapsed = "Elapsed"
|
|
|
|
ErrorKey = "error"
|
|
)
|
|
|
|
// LogLevel defines the level of log messages
|
|
type LogLevel string
|
|
|
|
const (
|
|
// LogLevelDebug denotes debug messages
|
|
LogLevelDebug = "debug"
|
|
// LogLevelInfo denotes info messages
|
|
LogLevelInfo = "info"
|
|
// LogLevelWarn denotes warn messages
|
|
LogLevelWarn = "warn"
|
|
// LogLevelError denotes error messages
|
|
LogLevelError = "error"
|
|
)
|
|
|
|
// LogContext defines the context for the logs.
|
|
type LogContext map[string]interface{}
|
|
|
|
// Logger defines an object able to log messages.
|
|
type Logger interface {
|
|
// With adds a logContext to the logger.
|
|
With(LogContext) Logger
|
|
// WithError adds an Error to the logger.
|
|
WithError(error) Logger
|
|
// Context returns the current context
|
|
Context() LogContext
|
|
// Timed add a timed log context.
|
|
Timed() Logger
|
|
// Debugf logs a formatted string as a debug message.
|
|
Debugf(format string, args ...interface{})
|
|
// Errorf logs a formatted string as an error message.
|
|
Errorf(format string, args ...interface{})
|
|
// Infof logs a formatted string as an info message.
|
|
Infof(format string, args ...interface{})
|
|
// Warnf logs a formatted string as an warning message.
|
|
Warnf(format string, args ...interface{})
|
|
}
|
|
|
|
func measure(lc LogContext) {
|
|
if lc[timed] == nil {
|
|
return
|
|
}
|
|
started := lc[timed].(time.Time)
|
|
lc[elapsed] = time.Since(started).String()
|
|
delete(lc, timed)
|
|
}
|
|
|
|
// Level assigns an integer to the LogLevel string
|
|
func Level(l LogLevel) int {
|
|
switch l {
|
|
case LogLevelDebug:
|
|
return 4
|
|
case LogLevelInfo:
|
|
return 3
|
|
case LogLevelWarn:
|
|
return 2
|
|
case LogLevelError:
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func toKeyValuePairs(in map[string]interface{}) (out []interface{}) {
|
|
for k, v := range in {
|
|
out = append(out, k, v)
|
|
}
|
|
return out
|
|
}
|