amperity / dialog

Simple just-enough logging library for Clojure
MIT License
39 stars 2 forks source link

Is there a way to reload / update logging configuration at runtime? #23

Closed ieugen closed 2 years ago

ieugen commented 2 years ago

Is there a way to update the logging configuration / levels at runtime without restarting the app?

I imagine this to be useful during long REPL sessions or even in production.

Is there a way to to the same by reloading the config on disk? This is for OPS where no repl is available / desired.

In unix ops the process is usually:

I think for dialog is enough to implement logic to apply configuration changes. Loading can happen on the client side.

greglook commented 2 years ago

Yes, you can call dialog.logger/initialize! to reload the configuration wholesale: https://github.com/amperity/dialog/blob/10a22a24d4d21b8eb56fe08df3bf0843e2d75c22/src/clojure/dialog/logger.clj#L49-L51

To manage individual logger levels at runtime, use dialog.logger/set-level! https://github.com/amperity/dialog/blob/10a22a24d4d21b8eb56fe08df3bf0843e2d75c22/src/clojure/dialog/logger.clj#L143-L146

We expose this as part of an administrative endpoint on our service instances, which also supports things like health checks and graceful shutdowns.

ieugen commented 2 years ago

Configuration can be altered at runtime in two ways:

  ;; see current configuration
  log/config

  (log/initialize!)
  (dialog.logger/set-level! "dev.start" :debug)
  (dialog.logger/debug "Dialog info")
  (clojure.tools.logging/debug "tools.logging info")
  (dialog.logger/set-level! "dev.start" :info)
  (dialog.logger/debug "Dialog info")
  (clojure.tools.logging/debug "tools.logging info")

  (dialog.logger/set-level! "com.zaxxer.hikari.util.DriverDataSource" :info)
ieugen commented 2 years ago

Tooling for doing this at runtime can be constructed as an external functionality using these primitives.