Documentation
¶
Index ¶
- Constants
- func CorrelationID(id string) slog.Attr
- func DurationS(d time.Duration) slog.Attr
- func EnrichRecordWithMetaData(ctx context.Context, r slog.Record) slog.Record
- func ErrorMessage(msg string) slog.Attr
- func ErrorType(errType string) slog.Attr
- func Fields(ctx context.Context) []slog.Attr
- func GitLabUserID(id int) slog.Attr
- func GitLabUserName(name string) slog.Attr
- func HTTPMethod(method string) slog.Attr
- func HTTPStatusCode(code int) slog.Attr
- func HTTPURL(url string) slog.Attr
- func New() *slog.Logger
- func NewContextHandler(baseHandler slog.Handler) slog.Handler
- func NewWithConfig(cfg *Config) *slog.Logger
- func NewWithFile(filePath string, cfg *Config) (*slog.Logger, io.Closer, error)
- func RemoteIP(ip string) slog.Attr
- func TCPAddress(addr string) slog.Attr
- func WithFields(ctx context.Context, attrs ...slog.Attr) context.Context
- type Config
- type ContextHandler
- type TimeFunc
Constants ¶
const GitLabLogLevelEnvVar = "GITLAB_LOG_LEVEL"
GitLabLogLevelEnvVar is the environment variable used to control the minimum log level. Supported values are "DEBUG", "INFO", "WARN", and "ERROR" (case-insensitive). Defaults to "INFO" if unset or invalid.
Variables ¶
This section is empty.
Functions ¶
func CorrelationID ¶ added in v1.39.0
CorrelationID returns an slog.Attr for the correlation_id field.
func DurationS ¶ added in v1.39.0
DurationS returns an slog.Attr for the duration_s field. The duration is converted to seconds automatically.
func ErrorMessage ¶ added in v1.39.0
ErrorMessage returns an slog.Attr for the error_message field.
func GitLabUserID ¶ added in v1.39.0
GitLabUserID returns an slog.Attr for the gl_user_id field.
func GitLabUserName ¶ added in v1.39.0
GitLabUserName returns an slog.Attr for the gl_user_name field.
func HTTPMethod ¶ added in v1.39.0
HTTPMethod returns an slog.Attr for the method field.
func HTTPStatusCode ¶ added in v1.39.0
HTTPStatusCode returns an slog.Attr for the status field.
func New ¶
New - a handy wrapper that configures the slog.Logger in a consistent fashion. Engineers should always default to using this constructor to ensure that they can take advantage of future global enhancements to our logging setup.
func NewWithConfig ¶ added in v1.35.0
NewWithConfig - a constructor that allows you to overwrite some of the core constructs within the Logger for your own nefarious purposes.
func NewWithFile ¶ added in v1.37.0
NewWithFile creates a logger writing to a file. Caller is responsible for closing the returned file. Should there be an error with the opening of the filePath this will gracefully degrade and provide a Stderr logger alongside an error. This allows the consumer to decide how they wish to proceed rather than outright blocking application startup.
func TCPAddress ¶ added in v1.39.0
TCPAddress returns an slog.Attr for the tcp_address field.
func WithFields ¶
WithField - provides a way to inject more fields into a logger that is then persisted in the context. This is useful in situations where they need to employ canonical logging in order to limit the number of log lines that they emit.
Types ¶
type Config ¶
type Config struct {
// Writer - a lower level construct that allows
// engineers to have finer-grained control over
// how and where logs are written to file.
Writer io.Writer
// UseTextFormat - set this to true if you require
// text formatted logs.
UseTextFormat bool
// Clock - allows the consumer to provide their own
// TimeFunc that is used to provide the timestamp when
// emitting logs.
// The logger defaults to UTC to try and ensure
// consistency across our services.
Clock TimeFunc
// LogLevel - represents the minimum log level that should be output by
// the logger. When nil, the value of GITLAB_LOG_LEVEL is used, falling
// back to slog.LevelInfo if the environment variable is unset or invalid.
// Set this explicitly to override the environment variable.
LogLevel *slog.Level
}
Config holds the configuration for creating a new logger.