First, import the package in your Go file:
import "github.com/catalystgo/logger/cliYou can set the current log level using the SetLevel function. The available log levels are:
LevelDebugLevelInfoLevelWarnLevelErrorLevelFatal
For example, to set the log level to LevelDebug:
log.SetLevel(log.LevelDebug)You can log messages at different levels using the following functions:
Debug(msg string)Debugf(msg string, args ...interface{})Info(msg string)Infof(msg string, args ...interface{})Warn(msg string)Warnf(msg string, args ...interface{})Error(msg string)Errorf(msg string, args ...interface{})Fatal(msg string)Fatalf(msg string, args ...interface{})
Each log level has its own prefix and color:
Here are some examples of how to use the logging functions:
log.SetLevel(log.LevelDebug)
log.Debug("This is a debug message")
log.Debugf("This is a debug message with a variable: %d", 42)
log.Info("This is an info message")
log.Infof("This is an info message with a variable: %d", 42)
log.Warn("This is a warning message")
log.Warnf("This is a warning message with a variable: %d", 42)
log.Error("This is an error message")
log.Errorf("This is an error message with a variable: %d", 42)
log.Fatal("This is a fatal message")
log.Fatalf("This is a fatal message with a variable: %d", 42)
// Panic functions can't be disabled by setting the log level to a higher value
// since they are meant to be used in critical situations where the application can't continue
log.Panic("This is a panic message")
log.Panicf("This is a panic message with a variable: %d", 42)