Documentation
ΒΆ
Index ΒΆ
- Constants
- Variables
- func Context(ctx context.Context) *request
- func Debug(i ...any)
- func Debugf(format string, i ...any)
- func Error(i ...any)
- func Errorf(format string, i ...any)
- func Fatal(i ...any)
- func Fatalf(msg string, i ...any)
- func GetCaller(level string, skip int) string
- func Info(i ...any)
- func Infof(format string, i ...any)
- func Init()
- func InitWithConfig(cfg Config)
- func NewRequest() *request
- func NewTrace(method, url string, reqHeader, reqBody any, addToExtraData bool) trace
- func Warn(i ...any)
- func Warnf(format string, i ...any)
- type Config
Constants ΒΆ
View Source
const ( // Logging level from least important to most important LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarning = slog.LevelWarn LevelError = slog.LevelError LevelFatal = slog.Level(12) LevelTrace = slog.Level(16) // Trace service to service communication LevelRequest = slog.Level(17) // Request log )
Variables ΒΆ
View Source
var ( DefaultConfig = Config{ LogToTerminal: true, LogToFile: false, Location: "/log/", FileLogName: "server_log", FileFormat: ".%Y-%b-%d-%H-%M.log", MaxAge: 30, RotationFile: 24, Level: LevelDebug, CustomWriter: nil, HideSensitiveData: false, } )
Functions ΒΆ
func GetCaller ΒΆ
GetCaller return trimmed location of the file who call the log function example project_name/usecase/user.go:34
func InitWithConfig ΒΆ
func InitWithConfig(cfg Config)
func NewRequest ΒΆ
func NewRequest() *request
NewRequest will create new log data model for incoming request
Types ΒΆ
type Config ΒΆ
type Config struct {
LogToTerminal bool // Set log output to stdout
LogToFile bool // Set log output to file
Location string // Location file log will be save. Default "project_directory/log/".
FileLogName string // File log name. Default "server_log".
FileFormat string // Default "FileLogName.2021-Oct-22-00-00.log"
MaxAge int // Days before deleting log file. Default 30 days.
RotationFile int // Hour before creating new file. Default 24 hour.
Level slog.Level // Log output level. Default level DEBUG
CustomWriter io.Writer // Specify custom writer for log output
HideSensitiveData bool // Enable hide sensitive data with struct tag `log:"hide"`
}
Click to show internal directories.
Click to hide internal directories.