mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-07-21 19:48:59 +02:00
* Update CI following latest plugindemo version * disable some linter * Disable some linter * Fix linter in redis, add error logger * 🚨 Fix lint errors in private packages * 🚨 Update lints in package and core code * 🚨 exclude unfixable lint errors * 🚨 update lint at package level and ignore necessary global variable * 🍱 fix lint qnd merge * 🚨 Fix Lint for string * 🚨 Fix lint for bouncer * 🚨 Fix error * Fix weird linter error Co-authored-by: Max Lerebourg <maxlerebourg@gmail.com>
40 lines
1003 B
Go
40 lines
1003 B
Go
// Package logger implements utility routines to write to stdout and stderr.
|
|
// It supports debug, info and error level
|
|
package logger
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"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
|
|
)
|
|
|
|
// 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)
|
|
if logLevel == "DEBUG" {
|
|
loggerDebug.SetOutput(os.Stdout)
|
|
}
|
|
}
|
|
|
|
// Info log to Stdout.
|
|
func Info(str string) {
|
|
loggerInfo.Printf(str)
|
|
}
|
|
|
|
// Debug log to Stdout.
|
|
func Debug(str string) {
|
|
loggerDebug.Printf(str)
|
|
}
|
|
|
|
// Error log to Stderr.
|
|
func Error(str string) {
|
|
loggerError.Printf(str)
|
|
}
|