Documentation
¶
Index ¶
- Constants
- type Config
- type Level
- type LogService
- func (l *LogService) Configure(config *Config)
- func (l *LogService) Debug(message string, args ...any)
- func (l *LogService) DebugContext(ctx context.Context, message string, args ...any)
- func (l *LogService) Error(message string, args ...any)
- func (l *LogService) ErrorContext(ctx context.Context, message string, args ...any)
- func (l *LogService) Info(message string, args ...any)
- func (l *LogService) InfoContext(ctx context.Context, message string, args ...any)
- func (l *LogService) Level() slog.Level
- func (l *LogService) Log(ctx context.Context, level Level, message string, args ...any)
- func (l *LogService) LogLevel() Level
- func (l *LogService) ServiceName() string
- func (l *LogService) SetLogLevel(level Level)
- func (l *LogService) Warning(message string, args ...any)
- func (l *LogService) WarningContext(ctx context.Context, message string, args ...any)
Constants ¶
const ( Debug = Level(slog.LevelDebug) Info = Level(slog.LevelInfo) Warning = Level(slog.LevelWarn) Error = Level(slog.LevelError) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Level ¶
type Level = int
A Level is the importance or severity of a log event. The higher the level, the more important or severe the event.
Values are arbitrary, but there are four predefined ones.
type LogService ¶
type LogService struct {
// contains filtered or unexported fields
}
func NewWithConfig ¶
func NewWithConfig(config *Config) *LogService
NewWithConfig initialises a logging service with a custom configuration.
func (*LogService) Configure ¶
func (l *LogService) Configure(config *Config)
Configure reconfigures the logger dynamically. If config is nil, it falls back to the default configuration.
func (*LogService) Debug ¶
func (l *LogService) Debug(message string, args ...any)
Debug logs at level Debug.
func (*LogService) DebugContext ¶
func (l *LogService) DebugContext(ctx context.Context, message string, args ...any)
DebugContext logs at level Debug.
func (*LogService) Error ¶
func (l *LogService) Error(message string, args ...any)
Error logs at level Error.
func (*LogService) ErrorContext ¶
func (l *LogService) ErrorContext(ctx context.Context, message string, args ...any)
ErrorContext logs at level Error.
func (*LogService) Info ¶
func (l *LogService) Info(message string, args ...any)
Info logs at level Info.
func (*LogService) InfoContext ¶
func (l *LogService) InfoContext(ctx context.Context, message string, args ...any)
InfoContext logs at level Info.
func (*LogService) Level ¶
func (l *LogService) Level() slog.Level
Level returns the currently configured log level, that is either the one configured initially or the last value passed to [Service.SetLogLevel].
Through this method, [Service] implements the slog.Leveler interface. The intended use case is to propagate the service's dynamic level setting to custom loggers. For example:
logService := log.New()
customLogger := slog.New(slog.NewTextHandler(
customWriter,
&slog.HandlerOptions{
Level: logService,
},
))
logService.Configure(&log.Config{
Logger: customLogger
})
By doing so, setting updates made through [Service.SetLogLevel] will propagate dynamically to the custom logger.
func (*LogService) Log ¶
Log emits a log record with the current time and the given level and message. The Record's attributes consist of the Logger's attributes followed by the attributes specified by args.
The attribute arguments are processed as follows:
- If an argument is a string and this is not the last argument, the following argument is treated as the value and the two are combined into an attribute.
- Otherwise, the argument is treated as a value with key "!BADKEY".
Log feeds the binding call context into the configured logger, so custom handlers may access context values, e.g. the current window.
func (*LogService) LogLevel ¶
func (l *LogService) LogLevel() Level
LogLevel returns the currently configured log level, that is either the one configured initially or the last value passed to [Service.SetLogLevel].
func (*LogService) ServiceName ¶
func (l *LogService) ServiceName() string
ServiceName returns the name of the plugin. You should use the go module format e.g. github.com/myuser/myplugin
func (*LogService) SetLogLevel ¶
func (l *LogService) SetLogLevel(level Level)
SetLogLevel changes the current log level.
func (*LogService) Warning ¶
func (l *LogService) Warning(message string, args ...any)
Warning logs at level Warning.
func (*LogService) WarningContext ¶
func (l *LogService) WarningContext(ctx context.Context, message string, args ...any)
WarningContext logs at level [Warn].