Documentation ¶
Index ¶
- func AddFlags(set *pflag.FlagSet)
- func All(items []string) string
- func Any(items []string) string
- type LoggerBuilder
- func (b *LoggerBuilder) AddField(name string, value any) *LoggerBuilder
- func (b *LoggerBuilder) AddFields(values map[string]any) *LoggerBuilder
- func (b *LoggerBuilder) Build() (result *slog.Logger, err error)
- func (b *LoggerBuilder) SetErr(value io.Writer) *LoggerBuilder
- func (b *LoggerBuilder) SetFields(values map[string]any) *LoggerBuilder
- func (b *LoggerBuilder) SetFile(value string) *LoggerBuilder
- func (b *LoggerBuilder) SetFlags(flags *pflag.FlagSet) *LoggerBuilder
- func (b *LoggerBuilder) SetLevel(value string) *LoggerBuilder
- func (b *LoggerBuilder) SetOut(value io.Writer) *LoggerBuilder
- func (b *LoggerBuilder) SetRedact(value bool) *LoggerBuilder
- func (b *LoggerBuilder) SetWriter(value io.Writer) *LoggerBuilder
- type TransportWrapperBuilder
- func (b *TransportWrapperBuilder) AddExclude(value string) *TransportWrapperBuilder
- func (b *TransportWrapperBuilder) AddExcludeFunc(value func(*http.Request) bool) *TransportWrapperBuilder
- func (b *TransportWrapperBuilder) Build() (result func(http.RoundTripper) http.RoundTripper, err error)
- func (b *TransportWrapperBuilder) SetBodies(value bool) *TransportWrapperBuilder
- func (b *TransportWrapperBuilder) SetExclude(value string) *TransportWrapperBuilder
- func (b *TransportWrapperBuilder) SetExcludeFunc(value func(*http.Request) bool) *TransportWrapperBuilder
- func (b *TransportWrapperBuilder) SetFlags(flags *pflag.FlagSet) *TransportWrapperBuilder
- func (b *TransportWrapperBuilder) SetHeaders(value bool) *TransportWrapperBuilder
- func (b *TransportWrapperBuilder) SetLogger(value *slog.Logger) *TransportWrapperBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
func (b *TransportWrapperBuilder) AddExclude(value string) *TransportWrapperBuilder
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 ¶
func (b *TransportWrapperBuilder) SetBodies(value bool) *TransportWrapperBuilder
SetBodies indicates if details about the HTTP bodies should be included in log messages. The default is to not include them.
func (*TransportWrapperBuilder) SetExclude ¶
func (b *TransportWrapperBuilder) SetExclude(value string) *TransportWrapperBuilder
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 ¶
func (b *TransportWrapperBuilder) SetFlags(flags *pflag.FlagSet) *TransportWrapperBuilder
SetFlags sets the command line flags that should be used to configure the logger. This is optional.
func (*TransportWrapperBuilder) SetHeaders ¶
func (b *TransportWrapperBuilder) SetHeaders(value bool) *TransportWrapperBuilder
SetHeaders indicates if HTTP headers should be included in log messages. The default is to not include them.
func (*TransportWrapperBuilder) SetLogger ¶
func (b *TransportWrapperBuilder) SetLogger(value *slog.Logger) *TransportWrapperBuilder
SetLogger sets the logger that will be used to write request and response details to the log. This is mandatory.