logging

package
v0.0.0-...-a7d64e5 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFlags

func AddFlags(set *pflag.FlagSet)

AddFlags adds the flags related to logging to the given flag set.

func All

func All(items []string) string

All generates a human readable representation of the given list of strings, for use in a log file. It puts quotes around each item, separates the first items with commas and the last with the word 'and'.

func Any

func Any(items []string) string

Any generates a human readable representation of the given list of strings, for use in a log file. It puts quotes around each item, separates the first items with commas and the last with the word 'or'.

Types

type LoggerBuilder

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

LoggerBuilder contains the data and logic needed to create a logger. Don't create instances of this directly, use the NewLogger function instead.

func NewLogger

func NewLogger() *LoggerBuilder

NewLogger creates a builder that can then be used to configure and create a logger.

func (*LoggerBuilder) AddField

func (b *LoggerBuilder) AddField(name string, value any) *LoggerBuilder

AddField adds a field that will be added to all the log messages. The following field values have special meanings:

- %p: Is replaced by the process identifier.

Any other field value is added without change.

func (*LoggerBuilder) AddFields

func (b *LoggerBuilder) AddFields(values map[string]any) *LoggerBuilder

AddFields adds a set of fields that will be added to all the log messages. See the AddField method for the meanings of values.

func (*LoggerBuilder) Build

func (b *LoggerBuilder) Build() (result *slog.Logger, err error)

Build uses the data stored in the buider to create a new logger.

func (*LoggerBuilder) SetErr

func (b *LoggerBuilder) SetErr(value io.Writer) *LoggerBuilder

SetErr sets the standard error output stream. This is optional and will only be used when the log file is 'stderr'.

func (*LoggerBuilder) SetFields

func (b *LoggerBuilder) SetFields(values map[string]any) *LoggerBuilder

SetFields sets the fields tht will be added to all the log messages. See the AddField method for the meanings of values. Note that this replaces any previously configured fields. If you want to preserve them use the AddFields method.

func (*LoggerBuilder) SetFile

func (b *LoggerBuilder) SetFile(value string) *LoggerBuilder

SetFile sets the file that the logger will write to. This is optional, and if not specified the the logger will write to the standard output stream of the process.

func (*LoggerBuilder) SetFlags

func (b *LoggerBuilder) SetFlags(flags *pflag.FlagSet) *LoggerBuilder

SetFlags sets the command line flags that should be used to configure the logger. This is optional.

func (*LoggerBuilder) SetLevel

func (b *LoggerBuilder) SetLevel(value string) *LoggerBuilder

SetLevel sets the log level.

func (*LoggerBuilder) SetOut

func (b *LoggerBuilder) SetOut(value io.Writer) *LoggerBuilder

SetOut sets the standard output stream. This is optional and will only be used then the log file is 'stdout'.

func (*LoggerBuilder) SetRedact

func (b *LoggerBuilder) SetRedact(value bool) *LoggerBuilder

Set redact sets the flag that indicates if security sensitive data should be removed from the log. These fields are indicated by adding an exlamation mark in front of the field name. For example, to write a message with a `public` field that isn't sensitive and another `private` field that is:

logger.Info(
	"SSH keys",
	"public", publicKey,
	"!public", privateKey,
)

When redacting is enabled the value of the sensitive field will be replaced be `***`, so in the example above the resulting message will be like this:

{
	"msg": "SSHKeys",
	"public": "ssh-rsa AAA...",
	"private": "***"
}

The exclamation mark will be always removed from the field name.

func (*LoggerBuilder) SetWriter

func (b *LoggerBuilder) SetWriter(value io.Writer) *LoggerBuilder

SetWriter sets the writer that the logger will write to. This is optional, and if not specified the the logger will write to the standard output stream of the process.

type TransportWrapperBuilder

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

TransportWrapperBuilder contains the data and logic needed to build a transport wrapper that dumps to the log the details of HTTP requests and responses. Don't create instances of this type directly, use the NewLoggingTransportWrapper function instead.

func NewTransportWrapper

func NewTransportWrapper() *TransportWrapperBuilder

NewTransportWrapper creates a builder that can then be used to configure and create a logging transport wrapper.

func (*TransportWrapperBuilder) AddExclude

AddExclude adds a regular expression that will be used to decide if a request should be excluded. Note that this is equivalent to creating a function that checks the regular expression and then adding it with the AddExcludedFunc method.

func (*TransportWrapperBuilder) AddExcludeFunc

func (b *TransportWrapperBuilder) AddExcludeFunc(
	value func(*http.Request) bool) *TransportWrapperBuilder

AddExcludeFunc adds a function that will be called to decide if requests should excluded. If the function returns `true` then the request will not be written to the log. If multiple functions are added then the request will be excluded if any of the functions returns true. If no functions are added then no request will be excluded.

func (*TransportWrapperBuilder) Build

func (b *TransportWrapperBuilder) Build() (result func(http.RoundTripper) http.RoundTripper,
	err error)

Build uses the data stored in the builder to create and configure a new logging transport wrapper.

func (*TransportWrapperBuilder) SetBodies

SetBodies indicates if details about the HTTP bodies should be included in log messages. The default is to not include them.

func (*TransportWrapperBuilder) SetExclude

SetExclude sets a regular expression that will be used to decide if a request should be excluded. Note that this is equivalent to creating a function that checks the regular expression and then setting it with the SetExcluede method.

func (*TransportWrapperBuilder) SetExcludeFunc

func (b *TransportWrapperBuilder) SetExcludeFunc(
	value func(*http.Request) bool) *TransportWrapperBuilder

SetExcludeFunc sets a function that will be called to decide if requests should excluded. If the function returns `true` then the request will not be written to the log. This removes any exclude function previously added with the AddExcludeFunc method.

func (*TransportWrapperBuilder) SetFlags

SetFlags sets the command line flags that should be used to configure the logger. This is optional.

func (*TransportWrapperBuilder) SetHeaders

SetHeaders indicates if HTTP headers should be included in log messages. The default is to not include them.

func (*TransportWrapperBuilder) SetLogger

SetLogger sets the logger that will be used to write request and response details to the log. This is mandatory.

Jump to

Keyboard shortcuts

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