blog

package
v0.20260630.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Acct

func Acct(acctID int64) slog.Attr

Acct returns a slog.Attr whose key is "acct" and whose value is the unique numeric ID of the account.

func Authz

func Authz(authzID int64) slog.Attr

Authz returns a slog.Attr whose key is "authz" and whose value is the unique numeric ID of the authz.

func ContextWith

func ContextWith(ctx context.Context, attrs ...slog.Attr) context.Context

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

func Error(err error) slog.Attr

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

func LogLineChecksum(line string) string

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

func New(conf Config) (*logger, error)

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).

func Order

func Order(orderID int64) slog.Attr

Order returns a slog.Attr whose key is "order" and whose value is the unique numeric ID of the order.

func Serial

func Serial(serial string) slog.Attr

Serial returns a slog.Attr whose key is "serial" and whose value is the given string. The argument should be hex-encoded.

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

func (l Mock) AuditError(ctx context.Context, msg string, err error, attrs ...slog.Attr)

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

func (l Mock) AuditInfo(ctx context.Context, msg string, attrs ...slog.Attr)

AuditInfo logs the given message and other key-value pairs at info level and with the audit tag.

func (*Mock) Clear

func (ml *Mock) Clear()

Clear resets the log buffer.

func (Mock) Debug

func (l Mock) Debug(ctx context.Context, msg string, attrs ...slog.Attr)

Debug logs the given message and other key-value pairs at debug level.

func (Mock) Error

func (l Mock) Error(ctx context.Context, msg string, err error, attrs ...slog.Attr)

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

func (ml *Mock) ExpectMatch(reString string) error

ExpectMatch returns an error if no log lines matching the given regex have been logged since instantiation or the last Clear().

func (*Mock) GetAll

func (ml *Mock) GetAll() []string

GetAll returns all messages logged since instantiation or the last call to Clear().

func (*Mock) GetAllMatching

func (ml *Mock) GetAllMatching(reString string) []string

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.

func (Mock) Info

func (l Mock) Info(ctx context.Context, msg string, attrs ...slog.Attr)

Info logs the given message and other key-value pairs at info level.

func (Mock) Warn

func (l Mock) Warn(ctx context.Context, msg string, attrs ...slog.Attr)

Warn logs the given message and other key-value pairs at warning level.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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