Skip to content

Instantly share code, notes, and snippets.

@MAAARKIN
Created September 10, 2024 21:47
Show Gist options
  • Save MAAARKIN/aaf213bec6332d5f86e555fede6b85e0 to your computer and use it in GitHub Desktop.
Save MAAARKIN/aaf213bec6332d5f86e555fede6b85e0 to your computer and use it in GitHub Desktop.
loggerparser
package logger
func init() {
if logger == nil {
logger = NewZapLogger()
}
}
// Fields Type to pass when we want to call WithFields for structured logging
type Fields map[string]interface{}
var logger Logger
func NewGlobalLogger(logStd Logger) {
logger = logStd
}
// Logger is our contract for the logger
type Logger interface {
// Debug uses fmt.Sprint to construct and log a message.
Debug(args ...interface{})
// Info uses fmt.Sprint to construct and log a message.
Info(args ...interface{})
// Warn uses fmt.Sprint to construct and log a message.
Warn(args ...interface{})
// Error uses fmt.Sprint to construct and log a message.
Error(args ...interface{})
// Panic uses fmt.Sprint to construct and log a message, then panics.
Panic(args ...interface{})
// Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.
Fatal(args ...interface{})
WithFields(keyValues Fields) Logger
}
func Debug(args ...interface{}) {
logger.Debug(args)
}
func Info(args ...interface{}) {
logger.Info(args)
}
func Warn(args ...interface{}) {
logger.Warn(args)
}
func Error(args ...interface{}) {
logger.Error(args)
}
func Panic(args ...interface{}) {
logger.Panic(args)
}
func Fatal(args ...interface{}) {
logger.Fatal(args)
}
func WithFields(keyValues Fields) Logger {
return logger.WithFields(keyValues)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment