Giter VIP home page Giter VIP logo

logger.timbre's Introduction

Duct logger.timbre

Build Status

Integrant multimethods for setting up a Timbre logger for the Duct framework.

Installation

To install, add the following to your project :dependencies:

[duct/logger.timbre "0.5.0"]

Basic usage

The Timbre configuration is stored in the :duct.logger/timbre key. See the configuration section of the Timbre README for full explanation.

Three additional keys are defined that reference core Timbre logging appenders:

  • :duct.logger.timbre/brief
  • :duct.logger.timbre/println
  • :duct.logger.timbre/spit

The brief appender prints to STDOUT only the log message without timestamp or any other information. It's most useful during development.

The println and spit appenders are appenders that come with Timbre. See the built-in appenders section of the Timbre README.

All the appenders also accept a :min-level option, so you can one appender that logs everything, and another appender that logs more selectively.

A basic configuration that logs messages of "INFO" and above to STDOUT looks like this:

{:duct.logger/timbre
 {:level     :info
  :appenders {:println #ig/ref :duct.logger.timbre/println}}

 :duct.logger.timbre/println {}}

When this configuration is initiated with integrant.core/init, the :duct.logger/timbre key is replaced with an implementation of the duct.logger/Logger protocol. See the duct.logger library for how to make use of this.

Legacy integration

It's often useful to integrate with existing logging solutions. In this case, we can set the :set-root-config? option to true:

{:duct.logger/timbre
 {:set-root-config? true
  :level            :info
  :appenders        {:println #ig/ref :duct.logger.timbre/println}}

 :duct.logger.timbre/println {}}

This will call the global taoensso.timbre/set-config! function on init with the configuration in the key, and restore the previous global configuration on halt!.

Note that as this changes a global var, only one system can be running with this option at any one time. Unless you need to interface with legacy global logging systems, it's recommended you keep this option off and use the duct.logger/log function for logging.

License

Copyright © 2021 James Reeves

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

logger.timbre's People

Contributors

eerohele avatar rickmoynihan avatar weavejester avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

rickmoynihan ejoc

logger.timbre's Issues

Update dependencies

The dependencies included in this library is quite old, for example latest timbre is [com.taoensso/timbre "5.1.2"].
I guess you have a lot to maintain. How can I help? Maybe we can setup tools such as Renovate?

Interaction with slf4j-timbre?

Hi, I'm trying to consume logs from a Java library that emits via SLF4J. slf4j-timbre is supposed to do this, but I'm not seeing any logs come through.

Am I missing something in my config? slf4j-timbre is seemingly supposed to be config-less.

My config:

(def system-config
  {:duct.profile/dev {:duct.logger.timbre/brief {:min-level :trace}})
   :duct.module/logging {}})

deps.edn includes:

:deps {com.fzakaria/slf4j-timbre  {:mvn/version "0.3.19"}
       org.slf4j/log4j-over-slf4j {:mvn/version "1.7.30"}}

Exceptions don't render as data

Not sure what you think about this, but currently (for me anyway) exceptions render like this, which seems against the logs as data idea you're trying to pursue:

(duct.logger/log (:duct.logger/timbre system) :info ::event (ex-info "foo" {}))
17-07-27 00:00:54 UnknownHost INFO [user:63] - :user/event
   clojure.core/eval   core.clj: 3105
                 ...                 
      user/eval20333  REPL Input     
clojure.core/ex-info   core.clj: 4617
clojure.lang.ExceptionInfo: foo

Presumably we want it to render as with Throwable->map, though presumably we might also want to pprint them?

Initialising timbre does not set the root timbre config binding

It looks like the duct timbre bindings don’t ever set the root timbre config by calling timbre/set-config!. This is state outside of integrant, but it means that you can’t redirect log4j/jul/etc loggers to the configuration specified in duct.

I’d suggest possibly adding a default key/value in the configuration for :set-config! true, with a that when set triggers the timbre/set-config! side effect when the loggers defmethod is called.

We should also want to capture the value before we do that, and roll it back to the default root binding when halt is called.

I’d imagine most of the time you’d want this behaviour; and if you don’t you could switch it off with :set-config! false.

I'd suggest using the name :set-config! as it's the name of the timbre function for setting the root binding on the *config* var.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.