Documentation
¶
Index ¶
- Constants
- Variables
- type Logger
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) DebugContext(ctx context.Context, msg string, args ...interface{})
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Fatal(msg string, args ...any)
- func (l *Logger) FatalContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Panic(msg string, args ...any)
- func (l *Logger) PanicContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Print(msg string, args ...any)
- func (l *Logger) PrintContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) SetCalldepth(calldepth int)
- func (l *Logger) SetLevel(level slog.Level) (oldLevel slog.Level)
- func (l *Logger) StackTrace() slog.Attr
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any)
- type Priority
Constants ¶
Variables ¶
var LevelNames = map[slog.Leveler]string{ LevelTrace: "TRACE", LevelFatal: "FATAL", LevelPanic: "PANIC", }
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger manages logging operations with various log levels and modes.
func New ¶
New creates and initializes a new Logger instance. calldepth: Number of stack frames to ascend for log entries. pc: A slice of uintptr used to store stack trace information.
func (*Logger) Debug ¶
Debug logs a debug-level message with optional arguments. msg: The message to log. args: Additional arguments to format the message.
func (*Logger) DebugContext ¶
DebugContext logs a debug-level message with optional arguments and context. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.
func (*Logger) Error ¶
Error logs an error-level message with optional arguments. msg: The message to log. args: Additional arguments to format the message.
func (*Logger) ErrorContext ¶
ErrorContext logs an error-level message with optional arguments and context. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.
func (*Logger) Fatal ¶
Fatal logs a fatal-level message, then exits the application. msg: The message to log. args: Additional arguments to format the message.
func (*Logger) FatalContext ¶
FatalC logs a fatal-level message with context, then exits the application. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.
func (*Logger) Info ¶
Info logs an info-level message with optional arguments. msg: The message to log. args: Additional arguments to format the message.
func (*Logger) InfoContext ¶
InfoC logs an info-level message with context and optional arguments. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.
func (*Logger) Panic ¶
Panic logs a panic-level message, then panics with the message. msg: The message to log. args: Additional arguments to format the message.
func (*Logger) PanicContext ¶
PanicC logs a panic-level message with context, then panics with the context. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.
func (*Logger) Print ¶
Print logs a trace-level message with optional arguments. msg: The message to log. args: Additional arguments to format the message.
func (*Logger) PrintContext ¶
PrintC logs a trace-level message with context and optional arguments. ctx: The context for the log entry. msg: The message to log. args: Additional arguments to format the message.
func (*Logger) SetCalldepth ¶
SetCalldepth configures the number of stack frames to ascend for logging. calldepth: The number of stack frames to ascend.
func (*Logger) SetLevel ¶
SetLevel sets the logging level for the Logger instance. This method updates the log level to the specified level and returns the previous log level.
Parameters:
level (slog.Level) - The new log level to be set. This determines the severity of the logs that will be captured. Common log levels include DEBUG, INFO, WARN, and ERROR.
Returns:
oldLevel (slog.Level) - The previous log level before it was updated. This can be used to restore the previous log level if needed.
Example usage:
logger := &Logger{} oldLevel := logger.SetLevel(slog.INFO) // The log level is now set to INFO // You can restore the old level if needed logger.SetLevel(oldLevel)
func (*Logger) StackTrace ¶
StackTrace provides a stack trace of up to 10 layers from where the error or incident was generated.