mirror of
https://github.com/evilsocket/opensnitch.git
synced 2025-03-04 08:34:40 +01:00
add new log level TRACE
This commit is contained in:
parent
ff3ac6663a
commit
45f5b62978
1 changed files with 15 additions and 6 deletions
|
@ -23,10 +23,11 @@ const (
|
||||||
FG_BLACK = "\033[30m"
|
FG_BLACK = "\033[30m"
|
||||||
FG_WHITE = "\033[97m"
|
FG_WHITE = "\033[97m"
|
||||||
|
|
||||||
BG_DGRAY = "\033[100m"
|
BG_PURPLE = "\033[45m"
|
||||||
BG_RED = "\033[41m"
|
BG_RED = "\033[41m"
|
||||||
BG_GREEN = "\033[42m"
|
BG_GREEN = "\033[42m"
|
||||||
BG_YELLOW = "\033[43m"
|
BG_YELLOW = "\033[43m"
|
||||||
|
BG_DGRAY = "\033[100m"
|
||||||
BG_LBLUE = "\033[104m"
|
BG_LBLUE = "\033[104m"
|
||||||
|
|
||||||
RESET = "\033[0m"
|
RESET = "\033[0m"
|
||||||
|
@ -40,6 +41,8 @@ const (
|
||||||
WARNING
|
WARNING
|
||||||
ERROR
|
ERROR
|
||||||
FATAL
|
FATAL
|
||||||
|
|
||||||
|
TRACE = -1
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -48,12 +51,13 @@ var (
|
||||||
Output = os.Stdout
|
Output = os.Stdout
|
||||||
StdoutFile = "/dev/stdout"
|
StdoutFile = "/dev/stdout"
|
||||||
DateFormat = "2006-01-02 15:04:05"
|
DateFormat = "2006-01-02 15:04:05"
|
||||||
MinLevel = INFO
|
MinLevel = int(INFO)
|
||||||
LogUTC = true
|
LogUTC = true
|
||||||
LogMicro = false
|
LogMicro = false
|
||||||
|
|
||||||
mutex = &sync.RWMutex{}
|
mutex = &sync.RWMutex{}
|
||||||
labels = map[int]string{
|
labels = map[int]string{
|
||||||
|
TRACE: "TRC",
|
||||||
DEBUG: "DBG",
|
DEBUG: "DBG",
|
||||||
INFO: "INF",
|
INFO: "INF",
|
||||||
IMPORTANT: "IMP",
|
IMPORTANT: "IMP",
|
||||||
|
@ -62,6 +66,7 @@ var (
|
||||||
FATAL: "!!!",
|
FATAL: "!!!",
|
||||||
}
|
}
|
||||||
colors = map[int]string{
|
colors = map[int]string{
|
||||||
|
TRACE: FG_WHITE + BG_PURPLE,
|
||||||
DEBUG: DIM + FG_BLACK + BG_DGRAY,
|
DEBUG: DIM + FG_BLACK + BG_DGRAY,
|
||||||
INFO: FG_WHITE + BG_GREEN,
|
INFO: FG_WHITE + BG_GREEN,
|
||||||
IMPORTANT: FG_WHITE + BG_LBLUE,
|
IMPORTANT: FG_WHITE + BG_LBLUE,
|
||||||
|
@ -163,15 +168,14 @@ func GetLogMicro() bool {
|
||||||
|
|
||||||
// Log prints out a text with the given color and format
|
// Log prints out a text with the given color and format
|
||||||
func Log(level int, format string, args ...interface{}) {
|
func Log(level int, format string, args ...interface{}) {
|
||||||
mutex.Lock()
|
mutex.RLock()
|
||||||
defer mutex.Unlock()
|
defer mutex.RUnlock()
|
||||||
if level >= MinLevel {
|
if level >= MinLevel {
|
||||||
label := labels[level]
|
label := labels[level]
|
||||||
color := colors[level]
|
color := colors[level]
|
||||||
|
|
||||||
datefmt := DateFormat
|
datefmt := DateFormat
|
||||||
|
|
||||||
if LogMicro == true {
|
if LogMicro {
|
||||||
datefmt = DateFormat + ".000000"
|
datefmt = DateFormat + ".000000"
|
||||||
}
|
}
|
||||||
when := time.Now().UTC().Format(datefmt)
|
when := time.Now().UTC().Format(datefmt)
|
||||||
|
@ -221,6 +225,11 @@ func Close() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trace is the log level for tracing purposes
|
||||||
|
func Trace(format string, args ...interface{}) {
|
||||||
|
Log(TRACE, format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
// Debug is the log level for debugging purposes
|
// Debug is the log level for debugging purposes
|
||||||
func Debug(format string, args ...interface{}) {
|
func Debug(format string, args ...interface{}) {
|
||||||
Log(DEBUG, format, args...)
|
Log(DEBUG, format, args...)
|
||||||
|
|
Loading…
Add table
Reference in a new issue