Releases: hermannm/devlog
Releases · hermannm/devlog
v0.6.0
devlog:- Breaking: Remove
InitDefaultLogHandler- This function made it harder to configure other log handlers, which we do not want
- To migrate, replace:
...with:
devlog.InitDefaultLogHandler(output, options)
logHandler := devlog.NewHandler(output, options) slog.SetDefault(slog.New(logHandler))
- Alternatively, use the new
log.SetDefaultfunction fromdevlog/log(see notes below):log.SetDefault(devlog.NewHandler(output, options))
- Alternatively, use the new
- Encode log attributes with values of type
anyas pretty-formatted JSON- This makes
devlog's attribute encoding more consistent with the JSON log handler that you'll typically use for production, to avoid discrepancies between local and production log output
- This makes
- Breaking: Remove
devlog/log:- Add
log.AddContextAttrsfunction for attaching log attributes to acontext.Context - Breaking: Add
context.Contextparameter to all logging functions, to ensure that attributes fromAddContextAttrsare propagated- To migrate, replace:
...with:
log.Info("Message", ...attributes)
log.Info(ctx, "Message", ...attributes)
- If you're in a function without a context parameter, you may pass a
nilcontext:log.Info(nil, "Message", ...attributes)
- If you're in a function without a context parameter, you may pass a
- To migrate, replace:
- Breaking: Remove
log.Error,log.WarnErrorandlog.DebugErrorfunctions that don't take a log message, and replace them with the error-logging functions that previously had aCausesuffix- Renamed functions:
log.ErrorCause->log.Errorlog.ErrorCausef->log.Errorflog.WarnErrorCause->log.WarnErrorlog.WarnErrorCausef->log.WarnErrorflog.DebugErrorCause->log.DebugErrorlog.DebugErrorCausef->log.DebugErrorf
- To migrate uses of
Error,WarnErrorandDebugErrorwithout a log message, you can add a blank log message, which behaves the same (error string is used as the message). Replace:...with:log.Error(err, ...attributes) log.WarnError(err, ...attributes) log.DebugError(err, ...attributes)
log.Error(ctx, err, "", ...attributes) log.WarnError(ctx, err, "", ...attributes) log.DebugError(ctx, err, "", ...attributes)
- Renamed functions:
- Breaking: Change variadic parameter in
log.Errorsto slice of errors, to allow passing log attributes- To migrate, replace:
...with:
log.Errors("Message", err1, err2)
log.Errors(ctx, []error{err1, err2}, "Message")
- To migrate, replace:
- Add functions for wrapping multiple errors with a formatted message:
log.Errorsflog.WarnErrorsflog.DebugErrorsf
- Add functions for logging errors at the
INFOlog level (for completeness with the other error-logging functions):log.InfoErrorlog.InfoErrorflog.InfoErrorslog.InfoErrorsf
- Add log functions that allow passing the log level as a parameter, to dynamically set the level
log.Loglog.Logflog.LogWithErrorlog.LogWithErrorflog.LogWithErrorslog.LogWithErrorsf
- Breaking: Remove
log.JSONattribute function- This is redundant now that
devlogencodesanyvalues as JSON
- This is redundant now that
- Add support for errors with structured log attributes attached
- The hermannm.dev/wrap package uses this, in its
wrap.ErrorWithAttrsfunction
- The hermannm.dev/wrap package uses this, in its
- Add support for errors with
context.Contextattached, in order to propagate attributes fromlog.AddContextAttrsfrom the error's original context- The hermannm.dev/wrap/ctxwrap package uses this
- Add
log.ContextHandler, which wraps aslog.Handlerto support attributes fromlog.AddContextAttrsfor logs made outside of this package - Add
log.SetDefault, short-hand utility for callingslog.SetDefault(slog.New(log.ContextHandler(logHandler))) - Add
log.EnabledandLogger.Enabledfor checking if log output is enabled for a log level - Make error unwrapping of plain errors more robust (check for
Unwrap() errormethod instead of just splitting on ": ")
- Add
v0.5.0
devlog:- Change time format to no longer show date by default (when in local development, one typically only cares about time)
- Add
TimeFormatoption to include date in time format, if one still wants the old behavior - Add
InitDefaultLogHandlerconvenience function, that combinesNewHandlerandslog.SetDefault - Add function name when
AddSourceis enabled, and fix formatting ofsourceattribute - Improve handling of
Handler.WithAttrs- Logs now display log-specific attributes first (i.e. most recent first), and attributes from
WithAttrsafter
- Logs now display log-specific attributes first (i.e. most recent first), and attributes from
- Fix handling of
Handler.WithGroupwhen not followed byHandler.WithAttrs- The previous implementation was broken, leading to subsequent logs getting increasing levels of indentation
devlog/log:- Allow passing log attributes as
...any(key/value pairs) instead of just...slog.Attr, enabling more concise attribute syntax - Add
DebugError,DebugErrorCause,DebugErrorCausefandDebugErrorsfunctions (both at top level and forLogger), for error logging atDEBUGlevel - Breaking: Make
JSONValuestruct no longer public (you likely were not depending on this) - Breaking: Make
WrappedErrorandWrappedErrorsinterfaces no longer public (you likely were not depending on these)
- Allow passing log attributes as
v0.4.1
v0.4.0
devlog:- Add
ForceColoroption to enable colors regardless of terminal color support
- Add
devlog/log:- Add
JSONlog attribute function- Logs a value as prettified JSON when using
devlog.Handler, or normal JSON when using
slog.JSONHandler
- Logs a value as prettified JSON when using
- Breaking: Remove
DebugJSONfunctions, made redundant byJSONlog attribute - Breaking: Rename
ErrorWarning/ErrorWarningf->WarnErrorCause/WarnErrorCausef
for more consistent naming - Add
WarnErrorfunction
- Add
- Breaking: Remove
colorpackage- Merged into
devlog, as that's the only place it's used now
- Merged into
v0.3.2
v0.3.1
v0.3.0
devlog:- Change log attribute output format to reduce noise
- Add formatting for list values in log attributes
devlog/log:- Add
Loggertype to enable use ofWithandWithGroupfor shared log attributes - Change
log.Errorto print only error, and addlog.ErrorCauseto log error with message - Add error interfaces to decouple dependency on
hermannm.dev/wrap - Implement splitting of long error messages
- Add
DebugJSONutility function (usingneilotoole/jsoncolorfor colors)
- Add
- Add
colorsubpackage for shared color constants and terminal color support check