Documentation
¶
Index ¶
- Constants
- func PrettyLogHandler(env string, level slog.Level) *slog.Logger
- type AppLogger
- func (l *AppLogger) Close() error
- func (l *AppLogger) DebugContext(ctx context.Context, msg string, keyvals ...any)
- func (l *AppLogger) Debugf(msg string, args ...interface{})
- func (l *AppLogger) EnableFileLogging(filePath string) error
- func (l *AppLogger) Error(msg string, err error, keyvals ...any)
- func (l *AppLogger) ErrorContext(ctx context.Context, msg string, err error, keyvals ...any)
- func (l *AppLogger) ErrorWithStack(msg string, err error)
- func (l *AppLogger) Errorf(msg string, args ...interface{})
- func (l *AppLogger) Fatalf(msg string, args ...interface{})
- func (l *AppLogger) InfoContext(ctx context.Context, msg string, keyvals ...any)
- func (l *AppLogger) Infof(msg string, args ...interface{})
- func (l *AppLogger) WarnContext(ctx context.Context, msg string, keyvals ...any)
- func (l *AppLogger) Warnf(msg string, args ...interface{})
- func (l *AppLogger) With(args ...any) *AppLogger
- func (l *AppLogger) WithContext(ctx context.Context) *slog.Logger
- func (l *AppLogger) WithGroup(name string) *AppLogger
Constants ¶
const ( EnvProd = "prod" EnvDev = "dev" )
Environment constants
const ( LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError )
Log levels
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AppLogger ¶
AppLogger wraps slog.Logger with additional functionality
func GetLoggerInstance ¶
func GetLoggerInstance() *AppLogger
GetLoggerInstance returns the logger singleton instance Panics if the logger has not been initialized
func InitLogger ¶
InitLogger initializes the logger singleton with the specified environment and log level If level is not specified (0), it will default to Info for prod and Debug for dev
func (*AppLogger) DebugContext ¶
DebugContext logs a debug message with context and structured data
func (*AppLogger) EnableFileLogging ¶
EnableFileLogging enables logging to a file in addition to the console
func (*AppLogger) ErrorContext ¶
ErrorContext logs an error message with context and structured data
func (*AppLogger) ErrorWithStack ¶
ErrorWithStack logs an error with its stack trace if available
func (*AppLogger) InfoContext ¶
InfoContext logs an info message with context and structured data
func (*AppLogger) WarnContext ¶
WarnContext logs a warning message with context and structured data
func (*AppLogger) WithContext ¶
WithContext returns a logger with context values