Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try out using the new log/slog library for layered logging information #202

Open
wants to merge 5 commits into
base: v2
Choose a base branch
from

Conversation

PaulSonOfLars
Copy link
Owner

What

A few breaking changes to use the new slog packages. This will ultimately allow for customising the output format of any log output, thus integrating with existing solutions (and allowing for text/json/custom output), and potentially adding more debug information to the dispatcher logic

Impact

  • Are your changes backwards compatible? No
  • Have you included documentation, or updated existing documentation? Yes
  • Do errors and log messages provide enough context? Yes

Copy link

@rusq rusq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ext/dispatcher.go Outdated Show resolved Hide resolved
ext/updater.go Outdated Show resolved Hide resolved
@PaulSonOfLars PaulSonOfLars changed the title Try out using the new log/slog library for layerd logging information Try out using the new log/slog library for layered logging information Dec 22, 2024
@@ -143,7 +141,7 @@ func NewDispatcher(opts *DispatcherOpts) *Dispatcher {
errHandler = opts.Error
panicHandler = opts.Panic
unhandledErrFunc = opts.UnhandledErrFunc
errLog = opts.ErrorLog
logger = opts.Logger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is opinionated, but I find that having this type of helper function may help in some cases:

func iftrue[T any](cond bool, t T, f T) T {
   if cond {
      return t
   }
   return f
}

(addressing the lack of C-style ternary condition operator ?: in Go)

and then:

logger = iftrue(opts.Logger == nil, logger, opts.Logger)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, I like that, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants