mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-07-21 11:38:59 +02:00
✨ Add a logger instance to bouncer instance (#134)
* ✨ Add a logger instance to bouncer instance * 🍱 fix test * 🍱 fix lint * 🍱 fix lint * 🍱 fix lint * 🍱 fix lint * 🍱 fix lint * 🍱 fix test * 🍱 fix test * 🍱 fix lint + test * 🍱 fix test * 🍱 fix test * 🍱 fix test * 🍱 fix lint * 🍱 fix lint
This commit is contained in:
+25
-16
@@ -8,32 +8,41 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
loggerInfo = log.New(io.Discard, "INFO: CrowdsecBouncerTraefikPlugin: ", log.Ldate|log.Ltime) //nolint:gochecknoglobals
|
||||
loggerDebug = log.New(io.Discard, "DEBUG: CrowdsecBouncerTraefikPlugin: ", log.Ldate|log.Ltime) //nolint:gochecknoglobals
|
||||
loggerError = log.New(io.Discard, "ERROR: CrowdsecBouncerTraefikPlugin: ", log.Ldate|log.Ltime) //nolint:gochecknoglobals
|
||||
)
|
||||
// Log Logger struct.
|
||||
type Log struct {
|
||||
logError *log.Logger
|
||||
logInfo *log.Logger
|
||||
logDebug *log.Logger
|
||||
}
|
||||
|
||||
// Init Set Default log level to info in case log level to defined.
|
||||
func Init(logLevel string) {
|
||||
loggerError.SetOutput(os.Stderr)
|
||||
loggerInfo.SetOutput(os.Stdout)
|
||||
// New Set Default log level to info in case log level to defined.
|
||||
func New(logLevel string) *Log {
|
||||
logError := log.New(io.Discard, "ERROR: CrowdsecBouncerTraefikPlugin: ", log.Ldate|log.Ltime)
|
||||
logInfo := log.New(io.Discard, "INFO: CrowdsecBouncerTraefikPlugin: ", log.Ldate|log.Ltime)
|
||||
logDebug := log.New(io.Discard, "DEBUG: CrowdsecBouncerTraefikPlugin: ", log.Ldate|log.Ltime)
|
||||
logError.SetOutput(os.Stderr)
|
||||
logInfo.SetOutput(os.Stdout)
|
||||
if logLevel == "DEBUG" {
|
||||
loggerDebug.SetOutput(os.Stdout)
|
||||
logDebug.SetOutput(os.Stdout)
|
||||
}
|
||||
return &Log{
|
||||
logError: logError,
|
||||
logInfo: logInfo,
|
||||
logDebug: logDebug,
|
||||
}
|
||||
}
|
||||
|
||||
// Info log to Stdout.
|
||||
func Info(str string) {
|
||||
loggerInfo.Printf(str)
|
||||
func (l *Log) Info(str string) {
|
||||
l.logInfo.Printf(str)
|
||||
}
|
||||
|
||||
// Debug log to Stdout.
|
||||
func Debug(str string) {
|
||||
loggerDebug.Printf(str)
|
||||
func (l *Log) Debug(str string) {
|
||||
l.logDebug.Printf(str)
|
||||
}
|
||||
|
||||
// Error log to Stderr.
|
||||
func Error(str string) {
|
||||
loggerError.Printf(str)
|
||||
func (l *Log) Error(str string) {
|
||||
l.logError.Printf(str)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user