log

package
v0.0.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package logger provides some utility methods based around the standard library's slog.Logger package. The goal is to make it easier to create a new slog.Logger given a set of options. More specfically, within the context of the project, we want to be able to create a new logger based on the config options provided by the user via environment variables or the CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LevelFromString

func LevelFromString(level string) slog.Level

LevelFromString returns the slog.Level corresponding to the given level string. If the level string is not recognized, slog.LevelInfo is returned.

func NewLogger

func NewLogger(opts Options) *slog.Logger

NewLogger creates a new slog.Logger based on the provided options.

Format can be one of "pretty", "text", or "json". Defaults to "json". IncludeTime indicates whether to include timestamps in log output. Defaults to false. Level can be one of "debug", "info", "warn", or "error". Defaults to "info". Verbose indicates whether to include source information in log output. Defaults to false.

func OpenLogFile

func OpenLogFile(
	path string,
	format string,
	includeTime bool,
	level string,
	verbose bool,
	logger **slog.Logger,
	writer **os.File,
) error

OpenLogFile opens a log file for writing and returns a new logger based on the provided options.

Types

type HoneybadgerLogger

type HoneybadgerLogger struct {
	Logger *slog.Logger
}

HoneybadgerLogger is a type that represents a slog with the capability to log messages using the Honeybadger log format.

func (HoneybadgerLogger) Printf

func (l HoneybadgerLogger) Printf(format string, v ...interface{})

Printf logs a formatted message using the HoneybadgerLogger's underlying logger.

type Options

type Options struct {
	Format      string
	IncludeTime bool
	Level       string
	Verbose     bool
	Writer      io.Writer
}

Options represents the configuration options for a logger.

Format defines the format of log output. Valid values are "pretty", "text", and "json".

IncludeTime indicates whether to include timestamps in log output.

Level specifies the log level. Valid values are "debug", "info", "warn", and "error".

Verbose indicates whether to include source information in log output.

Writer is the io.Writer to which log output will be written. This lets us redirect the output to a file, for example.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL