Documentation
¶
Index ¶
- Constants
- func Debug(msg string, args ...any)
- func DebugContext(ctx context.Context, msg string, args ...any)
- func Enabled(ctx context.Context, level slog.Level) bool
- func Error(msg string, args ...any)
- func ErrorContext(ctx context.Context, msg string, args ...any)
- func Fatal(v ...any)
- func Fatalf(format string, v ...any)
- func Fatalln(v ...any)
- func File() string
- func Flags() int
- func Info(msg string, args ...any)
- func InfoContext(ctx context.Context, msg string, args ...any)
- func Level() slog.Level
- func ListenRotateSignal(ctx context.Context, r Rotatable, sig ...os.Signal)
- func Log(ctx context.Context, level slog.Level, msg string, args ...any)
- func LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr)
- func Output(calldepth int, s string) error
- func Panic(v ...any)
- func Panicf(format string, v ...any)
- func Panicln(v ...any)
- func Prefix() string
- func Print(v ...any)
- func Printf(format string, v ...any)
- func Println(v ...any)
- func Rotate()
- func SetDefault(l *Logger)
- func SetExtra(extra io.Writer)
- func SetFile(file string)
- func SetFlags(flag int)
- func SetHandler(h slog.Handler)
- func SetLevel(level slog.Level)
- func SetOutput(file string, extra io.Writer)
- func SetPrefix(prefix string)
- func SlogHandler() slog.Handler
- func Warn(msg string, args ...any)
- func WarnContext(ctx context.Context, msg string, args ...any)
- func Writer() io.Writer
- type Logger
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) DebugContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Enabled(ctx context.Context, level slog.Level) bool
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) File() string
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Level() slog.Level
- func (l *Logger) Log(ctx context.Context, level slog.Level, msg string, args ...any)
- func (l *Logger) LogAttrs(ctx context.Context, level slog.Level, msg string, attrs ...slog.Attr)
- func (l *Logger) Rotate()
- func (l *Logger) SetExtra(extra io.Writer)
- func (l *Logger) SetFile(file string)
- func (l *Logger) SetHandler(h slog.Handler)
- func (l *Logger) SetLevel(level slog.Level)
- func (l *Logger) SetOutput(file string, extra io.Writer) error
- func (l *Logger) SlogHandler() slog.Handler
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) With(args ...any) *Logger
- func (l *Logger) WithGroup(name string) *Logger
- func (l *Logger) Write(b []byte) (int, error)
- type Rotatable
Constants ¶
const ( Ldate = log.Ldate // Include date in log output (e.g., 2009/01/23). Ltime = log.Ltime // Include time in log output (e.g., 01:23:23). Lmicroseconds = log.Lmicroseconds // Include microsecond resolution in time (requires Ltime). Llongfile = log.Llongfile // Include full file name and line number (e.g., /a/b/c/d.go:23). Lshortfile = log.Lshortfile // Include final file name element and line number (e.g., d.go:23), overrides Llongfile. LUTC = log.LUTC // Use UTC for date/time if Ldate or Ltime is set. Lmsgprefix = log.Lmsgprefix // Move prefix to before the message. LstdFlags = log.LstdFlags // Default flags: Ldate | Ltime. )
Constants for log flags, mirrored from the standard log package.
Variables ¶
This section is empty.
Functions ¶
func DebugContext ¶
DebugContext logs a message at Debug level with context using the default Logger.
func ErrorContext ¶
ErrorContext logs a message at Error level with context using the default Logger.
func Fatal ¶
func Fatal(v ...any)
Fatal logs a message and exits using the default Logger's Fatal method.
func Fatalln ¶
func Fatalln(v ...any)
Fatalln logs a message with a newline and exits using the default Logger's Fatalln method.
func InfoContext ¶
InfoContext logs a message at Info level with context using the default Logger.
func ListenRotateSignal ¶
ListenRotateSignal listens for the specified signals and triggers rotation on the Rotatable object. It stops listening when the context is canceled.
func LogAttrs ¶
LogAttrs logs a message at the specified level with attributes using the default Logger.
func Output ¶
Output logs a message with the specified call depth using the default Logger's Output method.
func Panic ¶
func Panic(v ...any)
Panic logs a message and panics using the default Logger's Panic method.
func Panicln ¶
func Panicln(v ...any)
Panicln logs a message with a newline and panics using the default Logger's Panicln method.
func Println ¶
func Println(v ...any)
Println logs a message with a newline using the default Logger's Println method.
func Rotate ¶
func Rotate()
Rotate reopens the log file and rotates the extra writer for the default Logger if applicable.
func SetDefault ¶ added in v0.1.81
func SetDefault(l *Logger)
SetDefault sets the default Logger instance.
func SetExtra ¶
SetExtra sets an additional output destination for the default Logger, keeping the existing file.
func SetFile ¶
func SetFile(file string)
SetFile sets the log file path for the default Logger, keeping the existing extra writer.
func SetHandler ¶
SetHandler sets the slog handler for the default Logger. Note: The new handler may not respect the existing log level (obtained via Level), potentially disabling level control. Ensure the provided handler is configured with the desired log level if needed.
func SetOutput ¶
SetOutput sets the output destination for the default Logger. The file parameter specifies the log file path; if empty, no file output is used. The extra parameter allows an additional output destination (e.g., stderr).
func SetPrefix ¶
func SetPrefix(prefix string)
SetPrefix sets the log prefix for the default Logger.
func SlogHandler ¶ added in v0.1.82
SlogHandler returns the slog handler of the default Logger.
func WarnContext ¶
WarnContext logs a message at Warn level with context using the default Logger.
Types ¶
type Logger ¶
type Logger struct {
*log.Logger // Underlying standard logger.
// contains filtered or unexported fields
}
Logger implements a custom logger that combines the standard log.Logger with slog.Logger, providing flexible output destinations and log level control.
func New ¶
New creates a new Logger instance with the specified file path, prefix, and flags. If file is empty, logs are discarded. Panics if the file cannot be opened.
func With ¶
With returns a new Logger with the specified attributes, leaving the default Logger unchanged.
func WithGroup ¶
WithGroup returns a new Logger with the specified group name, leaving the default Logger unchanged.
func (*Logger) DebugContext ¶
DebugContext logs a message at Debug level with the given context and arguments.
func (*Logger) ErrorContext ¶
ErrorContext logs a message at Error level with the given context and arguments.
func (*Logger) InfoContext ¶
InfoContext logs a message at Info level with the given context and arguments.
func (*Logger) Log ¶
Log logs a message at the specified level with the given context and arguments.
func (*Logger) LogAttrs ¶
LogAttrs logs a message at the specified level with the given context and attributes.
func (*Logger) Rotate ¶
func (l *Logger) Rotate()
Rotate reopens the log file and rotates the extra writer if it implements Rotatable.
func (*Logger) SetExtra ¶
SetExtra sets an additional output destination (e.g., stderr), keeping the existing file.
func (*Logger) SetFile ¶
SetFile sets the log file to the specified path, keeping the existing extra writer.
func (*Logger) SetHandler ¶
SetHandler sets the slog handler for structured logging. Note: The new handler may not respect the existing log level (l.level), potentially disabling level control. Ensure the provided handler is configured with the desired log level if needed.
func (*Logger) SetOutput ¶
SetOutput sets the log output to the specified file path and extra writer. Returns an error if the file cannot be opened.
func (*Logger) SlogHandler ¶ added in v0.1.82
SlogHandler returns the current slog handler.
func (*Logger) WarnContext ¶
WarnContext logs a message at Warn level with the given context and arguments.
func (*Logger) With ¶
With returns a new Logger with the specified attributes, leaving the original unchanged.