mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-29 23:22:45 +00:00
a156188b3e
* update dependencies, bump Go version to 1.19 * bump test image Go version * update golangci-lint * update gotosocial-drone-build * sign * linting, go fmt * update swagger docs * update swagger docs * whitespace * update contributing.md * fuckin whoopsie doopsie * linterino, linteroni * fix followrequest test not starting processor * fix other api/client tests not starting processor * fix remaining tests where processor not started * bump go-runners version * don't check last-webfingered-at, processor may have updated this * update swagger command * update bun to latest version * fix embed to work the same as before with new bun Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: tsmethurst <tobi.smethurst@protonmail.com>
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
package level
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// LEVEL defines a level of logging.
|
|
type LEVEL uint8
|
|
|
|
// Default levels of logging.
|
|
const (
|
|
UNSET LEVEL = 0
|
|
PANIC LEVEL = 1
|
|
FATAL LEVEL = 50
|
|
ERROR LEVEL = 100
|
|
WARN LEVEL = 150
|
|
INFO LEVEL = 200
|
|
DEBUG LEVEL = 250
|
|
TRACE LEVEL = 254
|
|
ALL LEVEL = ^LEVEL(0)
|
|
)
|
|
|
|
// CanLog returns whether an incoming log of 'lvl' can be logged against receiving level.
|
|
func (loglvl LEVEL) CanLog(lvl LEVEL) bool {
|
|
return loglvl > lvl
|
|
}
|
|
|
|
// Levels defines a mapping of log LEVELs to formatted level strings.
|
|
type Levels [int(ALL) + 1]string
|
|
|
|
// Default returns the default set of log levels.
|
|
func Default() Levels {
|
|
return Levels{
|
|
TRACE: "TRACE",
|
|
DEBUG: "DEBUG",
|
|
INFO: "INFO",
|
|
WARN: "WARN",
|
|
ERROR: "ERROR",
|
|
FATAL: "FATAL",
|
|
PANIC: "PANIC",
|
|
}
|
|
}
|
|
|
|
// Get fetches the level string for the provided value.
|
|
func (l Levels) Get(lvl LEVEL) string {
|
|
return l[int(lvl)]
|
|
}
|
|
|
|
// Parse will attempt to decode a LEVEL from given string, checking (case insensitive) against strings in Levels.
|
|
func (l Levels) Parse(s string) (LEVEL, error) {
|
|
// Ensure consistent casing
|
|
s = strings.ToUpper(s)
|
|
|
|
for lvl := LEVEL(0); int(lvl) < len(l); lvl++ {
|
|
// Compare to eqach known level
|
|
if strings.ToUpper(l[lvl]) == s {
|
|
return lvl, nil
|
|
}
|
|
}
|
|
|
|
return 0, fmt.Errorf("unrecognized log level: %s", s)
|
|
}
|