Documentation
¶
Index ¶
- func Acct(acctID int64) slog.Attr
- func Authz(authzID int64) slog.Attr
- func ContextWith(ctx context.Context, attrs ...slog.Attr) context.Context
- func Error(err error) slog.Attr
- func Idents(idents ...identifier.ACMEIdentifier) slog.Attr
- func LogLineChecksum(line string) string
- func New(conf Config) (*logger, error)
- func Order(orderID int64) slog.Attr
- func Serial(serial string) slog.Attr
- type Config
- type Logger
- type Mock
- func (l Mock) AuditError(ctx context.Context, msg string, err error, attrs ...slog.Attr)
- func (l Mock) AuditInfo(ctx context.Context, msg string, attrs ...slog.Attr)
- func (ml *Mock) Clear()
- func (l Mock) Debug(ctx context.Context, msg string, attrs ...slog.Attr)
- func (l Mock) Error(ctx context.Context, msg string, err error, attrs ...slog.Attr)
- func (ml *Mock) ExpectMatch(reString string) error
- func (ml *Mock) GetAll() []string
- func (ml *Mock) GetAllMatching(reString string) []string
- func (l Mock) Info(ctx context.Context, msg string, attrs ...slog.Attr)
- func (l Mock) Warn(ctx context.Context, msg string, attrs ...slog.Attr)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Acct ¶
Acct returns a slog.Attr whose key is "acct" and whose value is the unique numeric ID of the account.
func Authz ¶
Authz returns a slog.Attr whose key is "authz" and whose value is the unique numeric ID of the authz.
func ContextWith ¶
ContextWith returns a new context with the given attributes attached, in addition to any already-attached attrs. All subsequent log calls to which the resulting context is passed will include the provided slog.Attrs.
func Error ¶
Error returns a slog.Attr whose key is "error" and whose value is the value from err.Error(). This attribute is used automatically by methods that log at the error level, like blog.Logger.AuditError().
func Idents ¶
func Idents(idents ...identifier.ACMEIdentifier) slog.Attr
Idents returns a slog.Attr whose key is "idents" and whose value is a list of the given identifiers.
func LogLineChecksum ¶
LogLineChecksum computes a CRC32 over the log line, which can be checked to ensure no unexpected log corruption has occurred. This function is exported for use by the log-validator.
func New ¶
New returns a Logger per the config. The logger extracts slog.Attrs from the context, prepends the [AUDIT] tag to calls to its Audit* methods, prepends a checksum to all messages, and then writes the resulting log messages to stdout and/or syslog as configured.
Cannot error if only the stdout logger is enabled (has a non-negative level).
Types ¶
type Config ¶
type Config struct {
// When absent or zero, this causes no logs to be emitted on stdout/stderr.
// Errors and warnings will be emitted on stderr if the configured level
// allows.
StdoutLevel int `validate:"min=-1,max=7"`
// When absent or zero, this defaults to logging all messages of level 6
// or below. To disable syslog logging entirely, set this to -1.
SyslogLevel int `validate:"min=-1,max=7"`
}
Config defines the config for logging to syslog and stdout/stderr. The level meanings are as follows:
-1: suppress all output 0: default, which is -1 for stdout and 6 for syslog 3: log only errors 4: log warnings and above 6: log info and above 7: log debug and above
Values less than -1 or greater than 7 are invalid. Values in between the numbers documented above (e.g. 1) have the same effect as the next larger value (e.g. 3).
type Logger ¶
type Logger interface {
Error(context.Context, string, error, ...slog.Attr)
Warn(context.Context, string, ...slog.Attr)
Info(context.Context, string, ...slog.Attr)
Debug(context.Context, string, ...slog.Attr)
AuditError(context.Context, string, error, ...slog.Attr)
AuditInfo(context.Context, string, ...slog.Attr)
}
Logger is a wrapper around slog.Logger. It exposes methods whose signatures require that a context be provided (from which slog Attrs will be extracted), and that any additional attributes be presented as slog.Attrs (not as comma-separated keys and values). It does not provide affordances for deriving a child logger with additional attrs attached; calling code should attach such persistent attributes to its context object instead.
type Mock ¶
type Mock struct {
// contains filtered or unexported fields
}
Mock implements the blog.Logger interface by virtue of embedding a blog.logger which writes to an in-memory datastore. It also exports methods allowing callers to inspect all log lines which have been written to it.
func NewMock ¶
func NewMock() *Mock
NewMock returns an object which implements the blog.Logger interface, but which also exposes methods allowing callers to inspect all log lines written to it. It always uses the text (i.e. not json) format, and always logs at level 7 (debug).
func (Mock) AuditError ¶
AuditError logs the given message, error, and other key-value pairs at error level and with the audit tag. The error will be included in the attrs under the key "error".
func (Mock) AuditInfo ¶
AuditInfo logs the given message and other key-value pairs at info level and with the audit tag.
func (Mock) Error ¶
Error logs the given message, error, and other key-value pairs at error level. The error will be included in the attrs under the key "error".
func (*Mock) ExpectMatch ¶
ExpectMatch returns an error if no log lines matching the given regex have been logged since instantiation or the last Clear().
func (*Mock) GetAll ¶
GetAll returns all messages logged since instantiation or the last call to Clear().
func (*Mock) GetAllMatching ¶
GetAllMatching returns all messages logged since instantiation or the last Clear() whose text matches the given regexp. The regexp is accepted as a string and compiled on the fly, because convenience is more important than performance.