2023-10-14 08:03:45 +02:00
|
|
|
// Copyright Earl Warren <contact@earl-warren.org>
|
|
|
|
// Copyright Loïc Dachary <loic@dachary.org>
|
2023-10-13 11:10:12 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
2024-01-25 10:22:40 +01:00
|
|
|
"bytes"
|
2023-10-13 11:10:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Level int
|
|
|
|
|
|
|
|
const (
|
2024-01-26 12:18:13 +01:00
|
|
|
_ = iota
|
|
|
|
Message Level = iota
|
|
|
|
Trace Level = iota
|
|
|
|
Debug Level = iota
|
|
|
|
Info Level = iota
|
|
|
|
Warn Level = iota
|
|
|
|
Error Level = iota
|
|
|
|
Fatal Level = iota
|
2023-10-13 11:10:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var toString = map[Level]string{
|
2024-01-26 12:18:13 +01:00
|
|
|
Message: "message",
|
|
|
|
Trace: "trace",
|
|
|
|
Debug: "debug",
|
|
|
|
Info: "info",
|
|
|
|
Warn: "warn",
|
|
|
|
Error: "error",
|
|
|
|
Fatal: "fatal",
|
2023-10-13 11:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l Level) String() string {
|
|
|
|
s, ok := toString[l]
|
|
|
|
if ok {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
return "undefined"
|
|
|
|
}
|
|
|
|
|
|
|
|
type Fun func(string, ...any)
|
|
|
|
|
2023-11-27 06:45:33 +01:00
|
|
|
type CaptureInterface interface {
|
2024-01-25 10:22:40 +01:00
|
|
|
Interface
|
|
|
|
GetBuffer() *bytes.Buffer
|
2023-11-27 06:45:33 +01:00
|
|
|
String() string
|
|
|
|
Reset()
|
|
|
|
}
|
|
|
|
|
2023-10-13 11:10:12 +02:00
|
|
|
type MessageInterface interface {
|
|
|
|
Message(string, ...any)
|
|
|
|
Trace(string, ...any)
|
|
|
|
Debug(string, ...any)
|
|
|
|
Info(string, ...any)
|
|
|
|
Warn(string, ...any)
|
|
|
|
Error(string, ...any)
|
|
|
|
Fatal(string, ...any)
|
|
|
|
Log(skip int, level Level, message string, args ...any)
|
|
|
|
}
|
|
|
|
|
|
|
|
type ManageInterface interface {
|
|
|
|
SetLevel(level Level)
|
|
|
|
GetLevel() Level
|
|
|
|
}
|
|
|
|
|
|
|
|
type Interface interface {
|
|
|
|
MessageInterface
|
|
|
|
ManageInterface
|
|
|
|
}
|