ulog

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 18 Imported by: 0

README

ulog
build-status go report MIT License coverage docs

blugnu/ulog

A configurable, structured logging library for Go that does not sacrifice (too much) efficiency in exchange for convenience and flexibility.

Features

Features unique to ulog:

  • Automatic Context Enrichment - logs may be enriched with context from the context provided by the caller or from context carried by an error (via support for the blugnu/errorcontext module); automatic contextual enrichment can be embedded by registering ulog.ContextEnricher functions with the logger

  • Multiplexing - (optionally) send logs to multiple destinations simultaneously with independently configured formatting and leveling; for example, full logs could be sent to an aggregator in msgpack or JSON format while logs at error level and above are sent to os.Stderr in in human-readable logfmt format

  • Testable - use the provided mock logger to verify that the logs expected by your observability alerts are actually produced!

Features you'd expect of any logger:

  • Highly Configurable - configure your logger to emit logs in the format you want, with the fields you want, at the level you want, sending them to the destination (or destinations) you want; the default configuration is designed to be sensible and useful out-of-the-box, but can be easily customised to suit your needs

  • Structured Logs - logs are emitted in a structured format (logfmt by default) that can be easily parsed by log aggregators and other tools; a JSON formatter is also provided

  • Efficient - allocations are kept to a minimum and conditional flows eliminated where-ever possible to ensure that the overhead of logging is kept to a minimum

  • Intuitive - a consistent API using Golang idioms that is easy and intuitive to use

Installation

go get github.com/blugnu/ulog

Tech Stack

blugnu/ulog is built on the following main stack:

Full tech stack here

Usage

A logger is created using the ulog.NewLogger factory function.

This function returns a logger, a function to close the logger and an error if the logger could not be created. The close function must be called when the logger is no longer required to release any resources it may have acquired and any batched log entries are flushed.

The logger may be configured using a set of configuration functions that are passed as arguments to the factory function.

A minimal example of using ulog:

package main

func main() {
    ctx := context.Background()

    // create a new logger
    logger, closelog, err := ulog.NewLogger(ctx)
    if err != nil {
      log.Fatalf("error initialising logger: %s", err)
    }
    defer closelog()

    // log a message
    logger.Info("hello world")
    logger.Error("oops!")
}

This example uses a logger with default configuration that writes log entries at InfoLevel and above to os.Stdout in logfmt format.

Running this code would produce output similar to the following:

time=2023-11-23T12:35:04.789346Z level=INFO  msg="hello world"
time=2023-11-23T12:35:04.789347Z level=ERROR msg="oops!"

Configuration

NOTE: This section deals with configuration of a simple logger sending output to a single io.Writer such as os.Stdout. Configuration of a multiplexing logger is described separately.

The default configuration is designed to be sensible and useful out-of-the-box but can be customised to suit your needs.

The Functional Options Pattern is employed for configuration. To configure the logger pass the required option functions as additional arguments to the NewLogger() factory. All options have sensible defaults.

Option Description Options Default (if not configured)
LogCallSite Whether to include the file name and line number of the call-site in the log message true
false
false
LoggerLevel The minimum log level to emit see: Log Levels ulog.InfoLevel
LoggerFormat The formatter to be used when writing logs ulog.NewLogfmtFormatter
ulog.NewJSONFormatter
ulog.NewMsgpackFormatter
ulog.NewLogfmtFormatter()
LoggerOutput The destination to which logs are written any io.Writer os.Stdout
Mux Use a multiplexer to send logs to multiple destinations simultaneously ulog.Mux. See: Mux Configuration -

LoggerLevel

Log Levels

The following levels are supported (in ascending order of significance):

Level Description
ulog.TraceLevel low-level diagnostic logs
ulog.DebugLevel debug messages
ulog.InfoLevel informational messages default
ulog.WarnLevel warning messages
ulog.ErrorLevel error messages
ulog.FatalLevel fatal errors

The default log level may be overridden using the LoggerLevel configuration function to NewLogger, e.g:

ulog.NewLogger(
    ulog.LoggerLevel(ulog.DebugLevel)
)

In this example, the logger is configured to emit logs at DebugLevel and above. TraceLevel logs would not be emitted.

LoggerLevel establishes the minimum log level for the logger.

If the logger is configured with a multiplexer the level for each mux target may be set independently but any target level that is lower than the logger level is effectively ignored.

Mux Target Level Logger Level Effective Mux Target Level
ulog.InfoLevel ulog.InfoLevel ulog.InfoLevel
ulog.DebugLevel ulog.InfoLevel ulog.InfoLevel
ulog.DebugLevel ulog.TraceLevel ulog.DebugLevel
ulog.InfoLevel ulog.WarnLevel ulog.WarnLevel

LoggerFormat

The following formatters are supported:

Format LoggerFormat Option Description
logfmt ulog.NewLogfmtFormatter a simple, structured format that is easy for both humans and machines to read

This is the default formatter if none is configured
JSON ulog.NewJSONFormatter a structured format that is easy for machines to parse but can be noisy for humans
msgpack ulog.NewMsgpackFormatter an efficient structured, binary format for machine use, unintelligible to (most) humans

Formatters offer a number of configuration options that can be set via functions supplied to their factory function. For example, to configure the name used for the time field by a logfmt formatter:

log, closelog, _ := ulog.NewLogger(ctx,
   ulog.LoggerFormat(ulog.LogfmtFormatter(
      ulog.LogfmtFieldNames(map[ulog.FieldId]string{
         ulog.TimeField: "timestamp",
      }),
   )),
)

LoggerOutput

Logger output may be written to any io.Writer. The default output is os.Stdout.

The output may be configured via the LoggerOutput configuration function when configuring a new logger:

logger, closefn, err := ulog.NewLogger(ctx, ulog.LoggerOutput(io.Stderr))

LogCallsite

If desired, the logger may be configured to emit the file name and line number of the call-site that produced the log message. This is disabled by default.

Call-site logging may be enabled via the LogCallSite configuration function when configuring a new logger:

logger, closelog, err := ulog.NewLogger(ctx, ulog.LogCallSite(true))

If LogCallsite is enabled call site information is added to all log entries, including multiplexed output where configured, regardless of the level.

Mux Configuration

Logs may be sent to multiple destinations simultaneously using a ulog.Mux. For example, full logs could be sent to an aggregator using msgpack format, while logfmt formatted logs at error level and above are also sent to os.Stderr.

Documentation

Index

Constants

View Source
const Required = ContextLoggerOption(1)

Variables

View Source
var (
	ErrBackendNotConfigured    = errors.New("a backend must be configured first")
	ErrFormatAlreadyRegistered = errors.New("a format with this id is already registered")
	ErrInvalidConfiguration    = errors.New("invalid configuration")
	ErrInvalidFormatReference  = errors.New("invalid type for format; must be a Formatter or the (string) id of a Formatter previously added to the mux")
	ErrKeyNotSupported         = errors.New("key not supported")
	ErrLogtailConfiguration    = errors.New("logtail transport configuration")
	ErrNoLoggerInContext       = errors.New("no logger in context")
	ErrNotImplemented          = errors.New("not implemented")
	ErrUnknownFormat           = errors.New("unknown format")

	// errors returns by the mock listener when expectations are not met
	ErrExpectationsNotMet      = errors.New("expectations were not met")
	ErrMalformedLogEntry       = errors.New("log entry did not meet expectations")
	ErrMissingExpectedLogEntry = errors.New("missing an expected log entry")
	ErrUnexpectedLogEntry      = errors.New("unexpected log entry")
)
View Source
var ExitFn func(int) = os.Exit

ExitFn is a func var allowing `ulog` code paths that reach an `os.Exit` call to be replaced by a non-exiting behaviour.

This is primarily used in `ulog` unit tests but also allows (e.g.) a microservice to intercept exit calls and perform a controlled exit, even when a log call results in termination of the microservice.

View Source
var JSONFormatter, _ = NewJSONFormatter()()

Functions

func AtLevel added in v0.2.0

func AtLevel(l Level) func(*MockEntry)

AtLevel returns a function that sets the expected log level of an entry.

func ContextWithLogger

func ContextWithLogger(ctx context.Context, lg Logger) context.Context

returns a new context with the supplied logger added to it.

The supplied logger will be enriched with the context to avoid incurring this encrichment every time the logger is retrieved from the context (if the context is further enriched, the logger

then a new

).

Example:

ctx := ulog.ContextWithLogger(ctx, logger)

func EnableTraceLogs added in v0.4.0

func EnableTraceLogs(fn func(...any))

func LogfmtFormatter added in v0.2.0

func LogfmtFormatter(opt ...LogfmtOption) func() (Formatter, error)

LogfmtFormatter configures a logfmt formatter to format entries in the logfmt format:

The default formatter will produce output similar to:

time=2006-01-02T15:04:05.000000Z level=INFO  message="some logged message"

Configuration options are provided to allow the default labels and values for the level field:

LogfmtLabels() may be used to configure the labels used for each of the core fields in an entry: TimestampField, LevelField, MessageField. The order of the fields is fixed and cannot be changed.

LogfmtLevels() may be used to configure the values used for the LevelField value.

func LogtailTransport added in v0.2.0

func LogtailTransport(opts ...LogtailOption) func() (transport, error)

LogtailTransport returns a transport factory function to create and configure a LogtailTransport transport with specified configuration options applied.

func MuxFormat added in v0.2.0

func MuxFormat(id string, f FormatterFactory) func(*mux) error

MuxFormat registers a Formatter with the mux, with a specified id. The id must be unique within the mux.

A Formatter added to the mux may be shared by multiple targets by specifying a TargetFormat(id) option with the same id as the Formatter. The Formatter must already have been added to the mux before it can be referenced by a target.

A Formatter that is not shared by multiple targets does not need to be added to the mux separately; a target-specific Formatter may be configured directly using the TargetFormat(Formatter) option for the relevant target.

func NewLogger

func NewLogger(ctx context.Context, cfg ...LoggerOption) (Logger, CloseFn, error)

NewLogger returns a new logger with the given configuration options applied and a close function that must be called to cleanly shutdown the logger and ensure that log entries are not lost.

If there are any errors in the configuration, a nil logger is returned along with the error. In this situation, the close function returned is a no-op; it is safe to call it, immediately or deferred.

If the logger is configured without a backend, a stdio backend will be used with a logfmt formatter and os.Stdout as the output.

If no Level is configured, the default level is Info.

func NewMock

func NewMock() (Logger, MockLog)

NewMock returns a logger with a listener that sends log entries to a mock listener implementation.

Unlike other backend factories which are used to configure a Logger initialised by the NewLogger() factory, NewMock() initialises and returns a complete Logger, as well as initialising the backend used by that Logger to configure and test expectations.

func RegisterEnrichment

func RegisterEnrichment(d EnrichmentFunc)

RegisterEnrichment registers a specified function.

func WithField added in v0.2.0

func WithField(key string) func(*MockEntry)

WithField returns a function that sets an expected field in an entry.

The expectation will match an entry that has the specified field among its fields, regardless of the value of the field.

func WithFieldValue added in v0.2.0

func WithFieldValue(k, v string) func(*MockEntry)

WithFieldValue returns a function that sets an expected field and value.

The expectation will match an entry if it has, among its fields, the specified field with matching value.

func WithFieldValues added in v0.2.0

func WithFieldValues(fields map[string]string) func(*MockEntry)

WithFieldValues returns a function that sets expected fields in an entry.

The expectation will match if it has fields that, at a minimum, contain all of the specified fields with values matching those expected.

func WithFields added in v0.2.0

func WithFields(key string, moreKeys ...string) func(*MockEntry)

WithFields returns a function that sets one or more expected fields in an entry.

The expectation will match an entry that has the specified fields among its fields, regardless of the value of those fields.

func WithMessage added in v0.2.0

func WithMessage(s string) func(*MockEntry)

WithMessage returns a function that sets an expected message.

The expectation will only match an entry if it has the specified message.

Types

type Batch added in v0.2.0

type Batch struct {
	// contains filtered or unexported fields
}

Batch is a collection of log entries that can be written by a Transport in a single operation.

type ByteWriter

type ByteWriter interface {
	io.Writer
	io.ByteWriter
}

ByteWriter is an interface that implements both io.Writer and io.ByteWriter

type CloseFn

type CloseFn func()

CloseFn is a function that closes a resource

type ContextLoggerOption

type ContextLoggerOption int

type EnrichmentFunc

type EnrichmentFunc func(context.Context) map[string]any

EnrichmentFunc provides the signature of a function that may be registered to extract log enrichment fields from a specified Context

An EnrichmentFunc identifies any values in the supplied Context that should be added to the log entry and returns them in the form of a map[string]any of fields (keys) and values.

type EntryExpectation added in v0.2.0

type EntryExpectation = func(*MockEntry)

EntryExpectation is a function that refines the properties of an expected log entry

type FieldId

type FieldId int

FieldId is the type of a field identifier, providing an id for each standard field in a log entry. "Standard" fields are those that are always present in a log entry (depending on logger configuration).

const (
	TimeField             FieldId = iota // TimeField is the FieldId of the time field
	LevelField                           // LevelKey is the FieldId of the level field
	MessageField                         // MessageKey is the FieldId of the message field
	CallsiteFileField                    // CallsiteFileField is the FieldId of the file field; used only when call-site logging is enabled
	CallsiteFunctionField                // CallsiteFunctionField is the FieldId of the function field; used only when call-site logging is enabled

)

type Formatter

type Formatter interface {
	Format(int, entry, ByteWriter)
}

Formatter is an interface implemented by a log formatter

type FormatterFactory

type FormatterFactory = func() (Formatter, error) // FormatterFactory is a function that returns a new Formatter

func MsgpackFormatter added in v0.2.0

func MsgpackFormatter(opts ...MsgpackOption) FormatterFactory

MsgpackFormatter returns a function that configures a msgpack formatter.

func NewJSONFormatter

func NewJSONFormatter(opt ...JsonFormatterOption) FormatterFactory

NewJSONFormatter returns a function that configures a json formatter.

type JsonFormatterOption

type JsonFormatterOption func(*jsonfmt) error // JsonFormatterOption is a function for configuring a json formatter

func JSONFieldNames added in v0.2.0

func JSONFieldNames(keys map[FieldId]string) JsonFormatterOption

LogfmtLabels configures the labels used for the each of the core fields in a logfmt log: time, level, message, file and function.

A map[FieldId]string is used to override the default label for each field that is required; if a field is not included in the map the default label will continue to be used for that field.

The default labels for each field are:

TimeField:     time
LevelField:    level
MessageField:  message
FileField:     file
FunctionField: function

Although the label for each field may be configured, the inclusion of these fields in a log entry is fixed and cannot be changed, as is the order of the fields in the output.

func JSONLevelLabels added in v0.2.0

func JSONLevelLabels(levels map[Level]string) JsonFormatterOption

JSONLevelLabels configures the values used for the Level field in json formatted log entries.

type Level

type Level int

Level identifies the logging level for a particular log entry. Possible values, in increasing order of severity (decreasing ordinal value), are:

  • TraceLevel (6)
  • DebugLevel
  • InfoLevel
  • WarnLevel
  • ErrorLevel
  • FatalLevel (1)
const (
	FatalLevel Level // FatalLevel indicates a condition that requires the process to terminate; after writing the log ulog.ExitFn is called
	ErrorLevel       // ErrorLevel indicates the log entry relates to an error
	WarnLevel        // WarnLevel indicates the log entry is a warning about some unexpected but recoverable condition
	InfoLevel        // InfoLevel indicates the log entry is an informational message
	DebugLevel       // DebugLevel indicates the log entry is a debug message, typically used during development
	TraceLevel       // TraceLevel indicates the log entry is a trace message, usually to aid in diagnostics

)

func (Level) String

func (lv Level) String() string

String implements the Stringer interface for Level

type LevelLogger

type LevelLogger interface {
	Log(string)                            // Log emits a log entry at the level of the LevelLogger
	Logf(string, ...any)                   // Logf emits a log entry at the level of the LevelLogger, using a specified format string and args
	WithField(string, any) LevelLogger     // WithField returns a new LevelLogger that will add a specified field to all log entries
	WithFields(map[string]any) LevelLogger // WithFields returns a new LevelLogger that will add a specified set of fields to all log entries
}

LevelLogger is an interface for a logger that is limited to emitting log messages at a specified level.

A LevelLogger is obtained by calling Logger.AtLevel(Level). If the specified level is not enabled on the Logger the returned LevelLogger will be a no-op logger.

Example:

logger := ulog.FromContext(ctx)
debug := logger.AtLevel(ulog.DebugLevel)

debug.Log("this is a debug message")

type LogfmtOption

type LogfmtOption func(*logfmt) error // LogfmtOption is a function that configures a logfmt formatter

func LogfmtFieldNames added in v0.2.0

func LogfmtFieldNames(keys map[FieldId]string) LogfmtOption

LogfmtFieldNames configures the labels used for the each of the core fields in a logfmt log entry: time, level and message.

A map[FieldId]string is used to override the default label for each field that is required; if a field is not included in the map, the default label will continue to be used for that field.

The default labels for each field are:

TimeField:     time
LevelField:    level
MessageField:  message

Although the label for each field may be configured, the inclusion of these fields and their order is fixed, and cannot be changed.

func LogfmtLevelLabels added in v0.2.0

func LogfmtLevelLabels(levels map[Level]string) LogfmtOption

LogfmtLevelLabels may be used to override the values used for the Level field in logfmt log entries.

A map[Level]string is used to override the default value for each level that is required; for any Level not included in the map, the currently configured value will be left as-is.

The default labels are:

TraceLevel: TRACE
DebugLevel: DEBUG
InfoLevel:  INFO
WarnLevel:  WARN
ErrorLevel: ERROR
FatalLevel: FATAL

Values are automatically right-padded with spaces to be of equal length to make it easier to visually parse log entries when reading a log, ensuring that the message part of each entry starts at the same position.

type Logger

type Logger interface {
	Log(Level, string)                            // Log emits a log message at a specified level
	Logf(level Level, format string, args ...any) // Logf emits a log message at a specified level using a specified format string and args
	Debug(s string)                               // Debug emits a Debug level log message
	Debugf(format string, args ...any)            // Debugf emits a Debug level log message using a specified format string and args
	Error(err any)                                // Error emits an Error level log message consisting of err
	Errorf(format string, args ...any)            // Errorf emits an Error level log message using a specified format string and args
	Fatal(err any)                                // Fatal emits a Fatal level log message then calls ExitFn(n) with the current exit code (or 1 if not set)
	Fatalf(format string, args ...any)            // Fatalf emits a Fatal level log message using a specified format string and args, then calls ExitFn(n) with the current exit code (or 1 if not set)
	Info(s string)                                // Info emits an Info level log message
	Infof(format string, args ...any)             // Infof emits an Info level log message using a specified format string and args
	Trace(s string)                               // Trace emits a Trace level log message
	Tracef(format string, args ...any)            // Tracef emits a Trace level log message using a specified format string and args
	Warn(s string)                                // Warn emits a Warn level log message
	Warnf(format string, args ...any)             // Warnf emits a Warn level log message using a specified format string and args

	AtLevel(Level) LevelLogger          // AtLevel returns a new LevelLogger with the same Context and Fields (if any) as those on the receiver Logger
	WithContext(context.Context) Logger // WithContext returns a new Logger encapsulating the specific Context
	WithExitCode(int) Logger            // WithExitCode returns a new Logger with a specified exit code set
	WithField(string, any) Logger       // WithField returns a new Logger that will add a specified field to all log entries
	WithFields(map[string]any) Logger   // WithFields returns a new Logger that will add a specified set of fields to all log entries
}

Logger is the interface used by applications and modules to emit log entries and provide enriched context for logging.

func FromContext

func FromContext(ctx context.Context, opt ...ContextLoggerOption) Logger

returns any logger present in the supplied Context.

The result if no logger is present in the context depends on whether a ContextLoggerOption is supplied:

  • if called with ulog.Required and no logger is present, a panic will occur (ErrNoLoggerInContext)

  • if not called with ulog.Required, a no-op logger will be returned

Example:

log := ulog.FromContext(ctx, ulog.Required)

type LoggerOption

type LoggerOption = func(*logger) error

LoggerOption is a function for configuring a logger

func LogCallsite

func LogCallsite(e bool) LoggerOption

LogCallsite returns a function that sets whether or not call site information is included in logs produced by a logger

func LoggerFormat

func LoggerFormat(f FormatterFactory) LoggerOption

LoggerFormat sets the formatter of a logger. This configuration option only makes sense for a non-muxing logger with a backend that supports configurable formatting.

If configured without/before a backend being configured, a stdio backend will be installed using the supplied formatter writing to os.Stdout.

Returns ErrInvalidConfiguration error if configured on a mux logger.

func LoggerLevel

func LoggerLevel(level Level) LoggerOption

LoggerLevel returns a function that sets the log level of a logger

func LoggerOutput

func LoggerOutput(out io.Writer) LoggerOption

LoggerOutput sets the io.Writer of a logger. This configuration option only makes sense for a non-muxing logger.

Returns ErrInvalidConfiguration error if configured on a mux logger.

func Mux

func Mux(opts ...MuxOption) LoggerOption

Mux configures a backend to dispatch log messages to multiple targets.

The Mux factory accepts a slice of configuration functions.

type LogtailOption added in v0.2.0

type LogtailOption = func(*logtail) error // LogtailOption is a function that configures a logtail transport

func LogtailEndpoint added in v0.2.0

func LogtailEndpoint(s string) LogtailOption

LogtailEndpoint configures the endpoint of the BetterStack Logs service.

func LogtailMaxBatch added in v0.2.0

func LogtailMaxBatch(m int) LogtailOption

configures the maximum number of log entries to send to the BetterStack Logs service in a single request. The default value is 16.

A batch is sent to the BetterStack Logs service when the number of entries in the batch reaches this number, even if the max latency time has not been reached.

func LogtailMaxLatency added in v0.2.0

func LogtailMaxLatency(d time.Duration) LogtailOption

configures the maximum time to wait before sending a batch of log entries to the BetterStack Logs service. If the batch contains at least one entry it will be sent after this time has elapsed.

func LogtailSourceToken added in v0.2.0

func LogtailSourceToken(s string) LogtailOption

LogtailSourceToken configures the source token of the log entries sent to the BetterStack Logs service.

The parameter to this function may be:

  • the name of an environment variable holding the source token value
  • the name of a file containing the source token value (and ONLY the source value)
  • a source token value (not recommended, to avoid leaking secrets in source)

type MockEntry added in v0.2.0

type MockEntry struct {
	// contains filtered or unexported fields
}

MockEntry represents a log MockEntry. It may represent an expected MockEntry or an actual one; for an expected entry, the actual field will reference the corresponding entry that was dispatched (if any).

For an expected MockEntry, any field that has a nil expected value is deemed to match as long as that field is present in the target fields (regardless of value), otherwise the value of that field in the target must match the expected field value.

func (*MockEntry) String added in v0.2.0

func (me *MockEntry) String() string

String returns a string representation of the entry.

type MockLog

type MockLog interface {
	ExpectEntry(...EntryExpectation)
	ExpectTrace(...EntryExpectation)
	ExpectDebug(...EntryExpectation)
	ExpectInfo(...EntryExpectation)
	ExpectWarn(...EntryExpectation)
	ExpectFatal(...EntryExpectation)
	ExpectationsWereMet() error
	Reset()
}

MockLog is an interface implemented by a mock logger that can be used to verify that log entries are emitted as expected.

type MsgpackOption added in v0.2.0

type MsgpackOption func(*msgpackfmt) error // MsgpackOption is a function for configuring a msgpack formatter

func MsgpackKeys added in v0.2.0

func MsgpackKeys(keys map[FieldId]string) MsgpackOption

MsgpackKeys configures the keys used for the each of the core fields in a log entry: time, level, message, file and function.

A map[FieldId]string is used to override the default label for each field that is required; if a field is not included in the map, the default label will continue to be used for that field.

The default labels for each field are:

TimeField:     time
LevelField:    level
MessageField:  message

Although the label for each field may be configured, the inclusion of these fields and their order is fixed, and cannot be changed.

func MsgpackLevels added in v0.2.0

func MsgpackLevels(levels map[Level]string) MsgpackOption

MsgpackLevels configures the values used for the Level field in msgpack formatted log entries.

type MuxOption

type MuxOption = func(*mux) error

MuxOption is a configuration function for a mux backend.

func MuxTarget added in v0.2.0

func MuxTarget(cfg ...TargetOption) MuxOption

MuxTarget is a MuxOption that configures and adds a target to a mux.

type StdioTransportOption added in v0.2.0

type StdioTransportOption = func(*stdioTransport) error // StdioOption is a function for configuring a stdio transport

type TargetOption

type TargetOption = func(*mux, *target) error // TargetOption is a function that configures a target

func TargetFormat

func TargetFormat(f any) TargetOption

TargetFormat sets the Formatter for a target. The parameter to this function must be a Formatter or a (string) id of a Formatter previously added to the mux.

func TargetLevel

func TargetLevel(level Level) TargetOption

TargetLevel sets the minimum Level of entries that will be dispatched to a target.

func TargetTransport

func TargetTransport(cfg TransportFactory) TargetOption

TargetTransport sets the Transport for a target.

type TransportFactory

type TransportFactory = func() (transport, error)

func StdioTransport

func StdioTransport(w io.Writer) TransportFactory

Stdio returns a factory that configures a transport to log messages to an io.Writer.

Directories

Path Synopsis
benchmarks module

Jump to

Keyboard shortcuts

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