Documentation
¶
Overview ¶
Package harelog provides a structured, level-based logging solution. It is designed to be flexible, thread-safe, and particularly well-suited for use with Google Cloud Logging by supporting its special JSON fields.
Index ¶
- Constants
- Variables
- func Close() error
- func Criticalf(format string, v ...interface{})
- func CriticalfCtx(ctx context.Context, format string, v ...interface{})
- func Criticalw(msg string, kvs ...interface{})
- func CriticalwCtx(ctx context.Context, msg string, kvs ...interface{})
- func Debugf(format string, v ...interface{})
- func DebugfCtx(ctx context.Context, format string, v ...interface{})
- func Debugw(msg string, kvs ...interface{})
- func DebugwCtx(ctx context.Context, msg string, kvs ...interface{})
- func Errorf(format string, v ...interface{})
- func ErrorfCtx(ctx context.Context, format string, v ...interface{})
- func Errorw(msg string, kvs ...interface{})
- func ErrorwCtx(ctx context.Context, msg string, kvs ...interface{})
- func Fatal(v ...interface{})
- func FatalCtx(ctx context.Context, v ...interface{})
- func Fatalf(format string, v ...interface{})
- func FatalfCtx(ctx context.Context, format string, v ...interface{})
- func Fatalln(v ...interface{})
- func FatallnCtx(ctx context.Context, v ...interface{})
- func Fatalw(msg string, kvs ...interface{})
- func FatalwCtx(ctx context.Context, msg string, kvs ...interface{})
- func Infof(format string, v ...interface{})
- func InfofCtx(ctx context.Context, format string, v ...interface{})
- func Infow(msg string, kvs ...interface{})
- func InfowCtx(ctx context.Context, msg string, kvs ...interface{})
- func IsCriticalEnabled() bool
- func IsDebugEnabled() bool
- func IsErrorEnabled() bool
- func IsInfoEnabled() bool
- func IsWarnEnabled() bool
- func NewConsoleFormatter(opts ...ConsoleFormatterOption) *consoleFormatterdeprecated
- func NewJSONFormatter() *jsonFormatterdeprecated
- func NewLogfmtFormatter() *logfmtFormatterdeprecated
- func NewTextFormatter() *textFormatterdeprecated
- func Print(v ...interface{})
- func PrintCtx(ctx context.Context, v ...interface{})
- func Printf(format string, v ...interface{})
- func PrintfCtx(ctx context.Context, format string, v ...interface{})
- func Println(v ...interface{})
- func PrintlnCtx(ctx context.Context, v ...interface{})
- func RemoveDefaultLabels(keys ...string)
- func SetDefaultAutoSource(mode sourceLocationMode)
- func SetDefaultFormatter(f Formatter)
- func SetDefaultHooks(hooks ...Hook)
- func SetDefaultLabels(labels map[string]string)
- func SetDefaultLogLevel(level LogLevel)
- func SetDefaultOutput(w io.Writer)
- func SetDefaultPrefix(prefix string)
- func SetDefaultProjectID(projectID string)
- func SetDefaultTraceContextKey(key interface{})
- func Warnf(format string, v ...interface{})
- func WarnfCtx(ctx context.Context, format string, v ...interface{})
- func Warnw(msg string, kvs ...interface{})
- func WarnwCtx(ctx context.Context, msg string, kvs ...interface{})
- type ColorAttribute
- type ConsoleFormatterOption
- type Formatter
- type HTTPRequest
- type Hook
- type JSONFormatterOption
- type LogEntry
- type LogLevel
- type LogfmtFormatterOption
- type Logger
- func (l *Logger) Clone() *Logger
- func (l *Logger) Close() error
- func (l *Logger) Criticalf(format string, v ...interface{})
- func (l *Logger) CriticalfCtx(ctx context.Context, format string, v ...interface{})
- func (l *Logger) Criticalw(msg string, kvs ...interface{})
- func (l *Logger) CriticalwCtx(ctx context.Context, msg string, kvs ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) DebugfCtx(ctx context.Context, format string, v ...interface{})
- func (l *Logger) Debugw(msg string, kvs ...interface{})
- func (l *Logger) DebugwCtx(ctx context.Context, msg string, kvs ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) ErrorfCtx(ctx context.Context, format string, v ...interface{})
- func (l *Logger) Errorw(msg string, kvs ...interface{})
- func (l *Logger) ErrorwCtx(ctx context.Context, msg string, kvs ...interface{})
- func (l *Logger) Fatal(v ...interface{})
- func (l *Logger) FatalCtx(ctx context.Context, v ...interface{})
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) FatalfCtx(ctx context.Context, format string, v ...interface{})
- func (l *Logger) Fatalln(v ...interface{})
- func (l *Logger) FatallnCtx(ctx context.Context, v ...interface{})
- func (l *Logger) Fatalw(msg string, kvs ...interface{})
- func (l *Logger) FatalwCtx(ctx context.Context, msg string, kvs ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) InfofCtx(ctx context.Context, format string, v ...interface{})
- func (l *Logger) Infow(msg string, kvs ...interface{})
- func (l *Logger) InfowCtx(ctx context.Context, msg string, kvs ...interface{})
- func (l *Logger) IsCriticalEnabled() bool
- func (l *Logger) IsDebugEnabled() bool
- func (l *Logger) IsErrorEnabled() bool
- func (l *Logger) IsInfoEnabled() bool
- func (l *Logger) IsWarnEnabled() bool
- func (l *Logger) Print(v ...interface{})
- func (l *Logger) PrintCtx(ctx context.Context, v ...interface{})
- func (l *Logger) Printf(format string, v ...interface{})
- func (l *Logger) PrintfCtx(ctx context.Context, format string, v ...interface{})
- func (l *Logger) Println(v ...interface{})
- func (l *Logger) PrintlnCtx(ctx context.Context, v ...interface{})
- func (l *Logger) SetLogLevel(level LogLevel)
- func (l *Logger) Warnf(format string, v ...interface{})
- func (l *Logger) WarnfCtx(ctx context.Context, format string, v ...interface{})
- func (l *Logger) Warnw(msg string, kvs ...interface{})
- func (l *Logger) WarnwCtx(ctx context.Context, msg string, kvs ...interface{})
- func (l *Logger) With(kvs ...interface{}) *Logger
- func (l *Logger) WithAutoSource(mode sourceLocationMode) *Logger
- func (l *Logger) WithCorrelationID(correlationID string) *Logger
- func (l *Logger) WithFormatter(f Formatter) *Logger
- func (l *Logger) WithLabels(labels map[string]string) *Logger
- func (l *Logger) WithLogLevel(level LogLevel) *Logger
- func (l *Logger) WithOutput(w io.Writer) *Logger
- func (l *Logger) WithPrefix(prefix string) *Logger
- func (l *Logger) WithProjectID(projectID string) *Logger
- func (l *Logger) WithSpanId(spanId string) *Logger
- func (l *Logger) WithTrace(trace string) *Logger
- func (l *Logger) WithTraceContextKey(key interface{}) *Logger
- func (l *Logger) WithTraceSampled(traceSampled *bool) *Logger
- func (l *Logger) WithoutLabels(keys ...string) *Logger
- type Option
- func WithAutoSource(mode sourceLocationMode) Option
- func WithFields(kvs ...interface{}) Option
- func WithFormatter(f Formatter) Option
- func WithHookBufferSize(size int) Option
- func WithHooks(hooks ...Hook) Option
- func WithLabels(labels map[string]string) Option
- func WithLogLevel(level LogLevel) Option
- func WithOutput(w io.Writer) Option
- func WithPrefix(prefix string) Option
- func WithProjectID(id string) Option
- func WithTraceContextKey(key interface{}) Option
- type SourceLocation
- type TextFormatterOption
Constants ¶
const ( // SourceLocationModeNever disables automatic source location capturing. // This provides the best performance. This is the default behavior. SourceLocationModeNever sourceLocationMode = iota // SourceLocationModeAlways enables automatic source location capturing for all log levels. // This is very useful for development and debugging, but has a performance cost. SourceLocationModeAlways // SourceLocationModeErrorOrAbove enables automatic source location capturing only for // logs of ERROR severity or higher. This is a balanced mode for capturing // critical debug information in production with minimal performance impact. SourceLocationModeErrorOrAbove )
Variables ¶
var Console = consoleOptions{}
var JSON = jsonOptions{}
var Logfmt = logfmtOptions{}
var Text = textOptions{}
Functions ¶
func Close ¶ added in v1.7.0
func Close() error
Close gracefully shuts down the default logger's background processes, such as the hook worker. It's recommended to call this via defer in the main function to ensure all buffered logs for hooks are processed before the application exits.
func Criticalf ¶
func Criticalf(format string, v ...interface{})
Criticalf logs a formatted message at the Critical level using the default logger.
func CriticalfCtx ¶ added in v1.4.0
CriticalfCtx logs a formatted message at the Critical level using the default logger. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Criticalw ¶
func Criticalw(msg string, kvs ...interface{})
Criticalw logs a message at the Critical level using the default logger.
func CriticalwCtx ¶ added in v1.4.0
CriticalwCtx logs a message at the Critical level using the default logger. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Debugf ¶
func Debugf(format string, v ...interface{})
Debugf logs a formatted message at the Debug level using the default logger.
func DebugfCtx ¶ added in v1.4.0
DebugfCtx logs a formatted message at the Debug level using the default logger. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Debugw ¶
func Debugw(msg string, kvs ...interface{})
Debugw logs a message at the Debug level using the default logger.
func DebugwCtx ¶ added in v1.4.0
DebugwCtx logs a message at the Debug level using the default logger. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf logs a formatted message at the Error level using the default logger.
func ErrorfCtx ¶ added in v1.4.0
ErrorfCtx logs a formatted message at the Error level using the default logger. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Errorw ¶
func Errorw(msg string, kvs ...interface{})
Errorw logs a message at the Error level using the default logger.
func ErrorwCtx ¶ added in v1.4.0
ErrorwCtx logs a message at the Error level using the default logger. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Fatal ¶ added in v1.1.0
func Fatal(v ...interface{})
Fatal logs its arguments at the Critical level and then calls os.Exit(1).
func FatalCtx ¶ added in v1.4.0
FatalCtx logs its arguments at the Critical level and then calls os.Exit(1). It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Fatalf ¶ added in v1.1.0
func Fatalf(format string, v ...interface{})
Fatalf logs a formatted message at the Critical level and then calls os.Exit(1).
func FatalfCtx ¶ added in v1.4.0
FatalfCtx logs a formatted message at the Critical level and then calls os.Exit(1). It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Fatalln ¶ added in v1.1.0
func Fatalln(v ...interface{})
Fatalln logs its arguments at the Critical level and then calls os.Exit(1).
func FatallnCtx ¶ added in v1.4.0
FatallnCtx logs its arguments at the Critical level and then calls os.Exit(1). It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Fatalw ¶ added in v1.3.0
func Fatalw(msg string, kvs ...interface{})
Fatalw logs a message with structured key-value pairs at the Critical level using the default logger and then calls os.Exit(1).
func FatalwCtx ¶ added in v1.4.0
FatalwCtx logs a message with structured key-value pairs at the Critical level using the default logger and then calls os.Exit(1). It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Infof ¶
func Infof(format string, v ...interface{})
Infof logs a formatted message at the Info level using the default logger.
func InfofCtx ¶ added in v1.4.0
InfofCtx logs a formatted message at the Info level using the default logger. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Infow ¶
func Infow(msg string, kvs ...interface{})
Infow logs a message at the Info level using the default logger.
func InfowCtx ¶ added in v1.4.0
InfowCtx logs a message at the Info level using the default logger. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func IsCriticalEnabled ¶
func IsCriticalEnabled() bool
IsCriticalEnabled checks if the Critical level is enabled for the default logger.
func IsDebugEnabled ¶
func IsDebugEnabled() bool
IsDebugEnabled checks if the Debug level is enabled for the default logger.
func IsErrorEnabled ¶
func IsErrorEnabled() bool
IsErrorEnabled checks if the Error level is enabled for the default logger.
func IsInfoEnabled ¶
func IsInfoEnabled() bool
IsInfoEnabled checks if the Info level is enabled for the default logger.
func IsWarnEnabled ¶
func IsWarnEnabled() bool
IsWarnEnabled checks if the Warn level is enabled for the default logger.
func NewConsoleFormatter
deprecated
added in
v1.8.0
func NewConsoleFormatter(opts ...ConsoleFormatterOption) *consoleFormatter
Deprecated: Use harelog.Console.NewFormatter instead.
func NewJSONFormatter
deprecated
added in
v1.2.0
func NewJSONFormatter() *jsonFormatter
Deprecated: Use harelog.JSON.NewFormatter instead.
func NewLogfmtFormatter
deprecated
added in
v1.10.0
func NewLogfmtFormatter() *logfmtFormatter
Deprecated: Use harelog.Logfmt.NewFormatter instead.
func NewTextFormatter
deprecated
added in
v1.2.0
func NewTextFormatter() *textFormatter
Deprecated: Use harelog.Text.NewFormatter instead.
func Print ¶ added in v1.1.0
func Print(v ...interface{})
Print logs its arguments at the Info level using the default logger.
func PrintCtx ¶ added in v1.4.0
PrintCtx logs its arguments at the Info level using the default logger. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Printf ¶ added in v1.1.0
func Printf(format string, v ...interface{})
Printf logs a formatted message at the Info level using the default logger.
func PrintfCtx ¶ added in v1.4.0
PrintfCtx logs a formatted message at the Info level using the default logger. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func Println ¶ added in v1.1.0
func Println(v ...interface{})
Println logs its arguments at the Info level using the default logger.
func PrintlnCtx ¶ added in v1.4.0
PrintlnCtx logs its arguments at the Info level using the default logger. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func RemoveDefaultLabels ¶
func RemoveDefaultLabels(keys ...string)
RemoveDefaultLabels removes labels from the default logger.
func SetDefaultAutoSource ¶ added in v1.6.0
func SetDefaultAutoSource(mode sourceLocationMode)
SetDefaultAutoSource sets the automatic source location capturing mode.
func SetDefaultFormatter ¶ added in v1.2.1
func SetDefaultFormatter(f Formatter)
SetDefaultFormatter sets the formatter for the default logger.
func SetDefaultHooks ¶ added in v1.7.0
func SetDefaultHooks(hooks ...Hook)
SetDefaultHooks sets hooks for the default logger. This function is safe for concurrent use. It replaces the existing default logger with a new one containing the specified hooks.
func SetDefaultLabels ¶
SetDefaultLabels sets labels for the default logger. These labels will be included in all logs from the default logger.
func SetDefaultLogLevel ¶
func SetDefaultLogLevel(level LogLevel)
SetDefaultLogLevel sets the log level for the default logger. The provided level should be validated with ParseLogLevel first.
func SetDefaultOutput ¶
SetDefaultOutput sets the output destination for the default logger.
func SetDefaultPrefix ¶
func SetDefaultPrefix(prefix string)
SetDefaultPrefix sets the message prefix for the default logger.
func SetDefaultProjectID ¶ added in v1.6.0
func SetDefaultProjectID(projectID string)
WithProjectID sets the initial Google Cloud Project ID.
func SetDefaultTraceContextKey ¶ added in v1.6.0
func SetDefaultTraceContextKey(key interface{})
WithTraceContextKey sets the initial context key for tracing.
func Warnf ¶
func Warnf(format string, v ...interface{})
Warnf logs a formatted message at the Warn level using the default logger.
func WarnfCtx ¶ added in v1.4.0
WarnfCtx logs a formatted message at the Warn level using the default logger. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
Types ¶
type ColorAttribute ¶ added in v1.8.0
type ColorAttribute int
ColorAttribute defines a text attribute like color or style for the ConsoleFormatter.
const ( FgBlack ColorAttribute = iota + 1 FgRed FgGreen FgYellow FgBlue FgMagenta FgCyan FgWhite )
Constants for foreground text colors.
const ( AttrBold ColorAttribute = iota + 20 AttrUnderline )
Constants for text style attributes.
type ConsoleFormatterOption ¶ added in v1.8.0
type ConsoleFormatterOption func(*consoleFormatter)
ConsoleFormatterOption is a functional option for configuring a ConsoleFormatter.
func WithKeyHighlight
deprecated
added in
v1.8.0
func WithKeyHighlight(key string, attrs ...ColorAttribute) ConsoleFormatterOption
Deprecated: Use harelog.Console.WithKeyHighlight instead.
func WithLogLevelColor
deprecated
added in
v1.10.0
func WithLogLevelColor(enabled bool) ConsoleFormatterOption
Deprecated: Use harelog.Console.WithLogLevelColor instead.
type Formatter ¶ added in v1.2.0
type Formatter interface {
Format(entry *LogEntry) ([]byte, error)
FormatMessageOnly(entry *LogEntry) ([]byte, error)
}
Formatter is an interface for converting a logEntry into a byte slice.
type HTTPRequest ¶
type HTTPRequest struct {
RequestMethod string `json:"requestMethod,omitempty"`
RequestURL string `json:"requestUrl,omitempty"`
Status int `json:"status,omitempty"`
UserAgent string `json:"userAgent,omitempty"`
RemoteIP string `json:"remoteIp,omitempty"`
Latency string `json:"latency,omitempty"`
}
HTTPRequest bundles information about an HTTP request for structured logging. When included in a log entry, Cloud Logging can interpret it to display request details.
type Hook ¶ added in v1.7.0
type Hook interface {
// Levels returns the log levels that this hook should be fired for.
// If an empty slice is returned, the hook will be fired for all levels.
Levels() []LogLevel
// Fire is called when a log entry is created for a level that the hook
// is configured for. The received logEntry is a defensive copy, so modifications
// to it will not affect other hooks or the main log output.
Fire(entry *LogEntry) error
}
Hook is an interface that allows you to process log entries. Hooks can be used to send logs to external services like Sentry or Slack.
The Fire method will be called asynchronously in a dedicated goroutine, so it does not block the application's logging calls. Implementations of Fire must be safe for concurrent use if the hook instance is shared.
type JSONFormatterOption ¶ added in v1.11.0
type JSONFormatterOption func(f *jsonFormatter)
type LogEntry ¶ added in v1.7.0
type LogEntry struct {
Message string `json:"message"`
Severity LogLevel `json:"severity,omitempty"`
Trace string `json:"logging.googleapis.com/trace,omitempty"`
SpanID string `json:"logging.googleapis.com/spanId,omitempty"`
TraceSampled *bool `json:"logging.googleapis.com/trace_sampled,omitempty"`
HTTPRequest *HTTPRequest `json:"httpRequest,omitempty"`
SourceLocation *SourceLocation `json:"logging.googleapis.com/sourceLocation,omitempty"`
Time time.Time `json:"timestamp,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
CorrelationID string `json:"correlationId,omitempty"`
// Any fields you want to output as `jsonPayload` are stored in this map.
Payload map[string]interface{} `json:"-"`
}
LogEntry is the internal data container for a single log entry.
type LogLevel ¶ added in v1.7.0
type LogLevel string
LogLevel defines the severity level of a log entry.
func ParseLogLevel ¶
ParseLogLevel parses a string into a LogLevel. It is case-insensitive. It returns an error if the input string is not a valid log level.
type LogfmtFormatterOption ¶ added in v1.11.0
type LogfmtFormatterOption func(f *logfmtFormatter)
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a structured logger that provides leveled logging. Instances of Logger are safe for concurrent use.
func Default ¶ added in v1.13.0
func Default() *Logger
Default returns the standard logger configured by the library.
func New ¶
New creates a new Logger with default settings. The default log level is LevelInfo and the default output is os.Stderr.
func (*Logger) Close ¶ added in v1.7.0
Close gracefully shuts down the logger's background processes, such as the hook worker. It ensures that all buffered log entries for hooks are processed before returning. It's recommended to call this via defer when the application is shutting down.
func (*Logger) CriticalfCtx ¶ added in v1.4.0
CriticalfCtx logs a formatted message at the Critical level. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) Criticalw ¶
Criticalw logs a message at the Critical level with structured key-value pairs.
func (*Logger) CriticalwCtx ¶ added in v1.4.0
CriticalwCtx logs a formatted message at the Critical level. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) DebugfCtx ¶ added in v1.4.0
DebugfCtx logs a formatted message at the Debug level. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) DebugwCtx ¶ added in v1.4.0
DebugwCtx logs a formatted message at the Debug level. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) ErrorfCtx ¶ added in v1.4.0
ErrorfCtx logs a formatted message at the Error level. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) ErrorwCtx ¶ added in v1.4.0
ErrorwCtx logs a formatted message at the Error level. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) Fatal ¶ added in v1.1.0
func (l *Logger) Fatal(v ...interface{})
Fatal logs its arguments at the Critical level and then calls os.Exit(1).
func (*Logger) FatalCtx ¶ added in v1.4.0
FatalCtx logs its arguments at the Critical level and then calls os.Exit(1). It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) Fatalf ¶ added in v1.1.0
Fatalf logs a formatted message at the Critical level and then calls os.Exit(1).
func (*Logger) FatalfCtx ¶ added in v1.4.0
FatalCtxf logs a formatted message at the Critical level and then calls os.Exit(1). It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) Fatalln ¶ added in v1.1.0
func (l *Logger) Fatalln(v ...interface{})
Fatalln logs its arguments at the Critical level and then calls os.Exit(1).
func (*Logger) FatallnCtx ¶ added in v1.4.0
FatallnCtx logs its arguments at the Critical level and then calls os.Exit(1). It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) Fatalw ¶ added in v1.3.0
Fatalw logs a message with structured key-value pairs at the Critical level and then calls os.Exit(1).
func (*Logger) FatalwCtx ¶ added in v1.4.0
FatalwCtx logs a message with structured key-value pairs at the Critical level and then calls os.Exit(1). It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) InfofCtx ¶ added in v1.4.0
InfofCtx logs a formatted message at the Info level. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) InfowCtx ¶ added in v1.4.0
InfowCtx logs a formatted message at the Info level. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) IsCriticalEnabled ¶
IsCriticalEnabled checks if the Critical level is enabled for the logger.
func (*Logger) IsDebugEnabled ¶
IsDebugEnabled checks if the Debug level is enabled for the logger.
func (*Logger) IsErrorEnabled ¶
IsErrorEnabled checks if the Error level is enabled for the logger.
func (*Logger) IsInfoEnabled ¶
IsInfoEnabled checks if the Info level is enabled for the logger.
func (*Logger) IsWarnEnabled ¶
IsWarnEnabled checks if the Warn level is enabled for the logger.
func (*Logger) Print ¶ added in v1.1.0
func (l *Logger) Print(v ...interface{})
Print logs its arguments at the Info level, like log.Print.
func (*Logger) PrintCtx ¶ added in v1.4.0
PrintCtx logs its arguments at the Info level, like log.Print. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) Printf ¶ added in v1.1.0
Printf logs a formatted message at the Info level, like log.Printf.
func (*Logger) PrintfCtx ¶ added in v1.4.0
PrintfCtx logs a formatted message at the Info level, like log.Printf. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) Println ¶ added in v1.1.0
func (l *Logger) Println(v ...interface{})
Println logs its arguments at the Info level, like log.Println.
func (*Logger) PrintlnCtx ¶ added in v1.4.0
PrintlnCtx logs its arguments at the Info level, like log.Println. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) SetLogLevel ¶ added in v1.12.0
SetLogLevel dynamically updates the logger's log level. This operation is thread-safe.
func (*Logger) WarnfCtx ¶ added in v1.4.0
WarnfCtx logs a formatted message at the Warn level. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) WarnwCtx ¶ added in v1.4.0
WarnwCtx logs a formatted message at the Warn level. It extracts values from the provided context, such as Google Cloud Trace identifiers, and includes them in the log entry.
func (*Logger) With ¶ added in v1.4.0
With returns a new logger instance with the provided key-value pairs added to its context. It panics if the number of arguments is odd or if a key is not a string.
func (*Logger) WithAutoSource ¶ added in v1.6.0
WithAutoSource returns a new logger with a different source location mode.
func (*Logger) WithCorrelationID ¶
WithCorrelationID returns a new logger instance with the specified correlation ID.
func (*Logger) WithFormatter ¶ added in v1.2.1
WithFormatter returns a new logger instance with the specified formatter.
func (*Logger) WithLabels ¶
WithLabels returns a new logger instance with the provided labels added.
func (*Logger) WithLogLevel ¶
WithLogLevel returns a new logger instance with the specified log level.
func (*Logger) WithOutput ¶
WithOutput returns a new logger instance that writes to the provided io.Writer.
func (*Logger) WithPrefix ¶
WithPrefix returns a new logger instance with the specified message prefix.
func (*Logger) WithProjectID ¶ added in v1.6.0
WithProjectID returns a new logger with a different Project ID.
func (*Logger) WithSpanId ¶
WithSpanId returns a new logger instance with the specified GCP spanId identifier.
func (*Logger) WithTrace ¶
WithTrace returns a new logger instance with the specified GCP trace identifier.
func (*Logger) WithTraceContextKey ¶ added in v1.6.0
WithTraceContextKey returns a new logger with a different trace context key.
func (*Logger) WithTraceSampled ¶
WithTraceSampled returns a new logger instance with the specified GCP traceSampled identifier.
func (*Logger) WithoutLabels ¶
WithoutLabels returns a new logger instance with the provided labels removed.
type Option ¶ added in v1.2.0
type Option func(*Logger)
Option configures a Logger.
func WithAutoSource ¶ added in v1.5.0
func WithAutoSource(mode sourceLocationMode) Option
WithAutoSource is a functional option that configures the logger's behavior for automatically capturing the source code location (file, line, function name). Note: Enabling this feature, especially with SourceLocationModeAlways, has a non-trivial performance cost due to the use of runtime.Callers.
func WithFields ¶ added in v1.6.0
func WithFields(kvs ...interface{}) Option
WithFields sets the initial set of contextual key-value fields (payload).
func WithFormatter ¶ added in v1.2.0
WithFormatter sets the formatter for the logger.
func WithHookBufferSize ¶ added in v1.7.0
WithHookBufferSize sets the buffer size for the hook channel. The default is 100. A larger buffer can handle higher log volumes without dropping hook events, but consumes more memory.
func WithHooks ¶ added in v1.7.0
WithHooks is a functional option that registers hooks with the logger. Hooks are triggered asynchronously when a log entry is created at a level specified in the hook's Levels() method.
func WithLabels ¶ added in v1.6.0
WithLabels sets the initial set of labels.
func WithLogLevel ¶ added in v1.5.0
WithLogLevel is a functional option that sets the initial log level for the logger.
func WithOutput ¶ added in v1.2.0
WithOutput sets the writer for the logger.
func WithPrefix ¶ added in v1.6.0
WithPrefix sets the initial message prefix.
func WithProjectID ¶ added in v1.4.0
WithProjectID sets the Google Cloud Project ID to be used for formatting trace identifiers.
func WithTraceContextKey ¶ added in v1.4.0
func WithTraceContextKey(key interface{}) Option
WithTraceContextKey sets the key used to extract Google Cloud Trace data from a context.Context.
type SourceLocation ¶
type SourceLocation struct {
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
Function string `json:"function,omitempty"`
}
SourceLocation represents the location in the source code where a log entry was generated.
type TextFormatterOption ¶ added in v1.4.0
type TextFormatterOption func(*textFormatter)
TextFormatterOption is a functional option for configuring a TextFormatter.