Giter Site home page Giter Site logo

log-config's Introduction

log-config

A Clojure library designed to help configure your timbre logging.

The com.palletops.log-config.timbre namespace provides timbre middleware and formatters.

Add [com.palletops/log-config "0.1.4"] to your dependencies.

Filtering Levels by Namespace

The min-level function provides a timbre middleware to filter log messages for a single namespace to those at or above a threshold level.

The min-levels function provides a timbre middleware to filter log messages based on a map from namespace to a threshold level.

The min-level-appender function provides an appender adaptor to filter log messages based on a map from namespace to a threshold level provided in the :min-levels timbre configuration key.

Domain Based Logging

For logs at the domain level, the namespace is often irrelevant. The with-domain macro allows specifying a domain keyword for a dynamic clojure scope. The domain-msg timbre middleware adds this domain keyword to log messages on the :domain key. The format-with-domain timbre formatter will show the domain in preference to the namespace if the :domain key is set.

Logging Contexts

Often, the same code is called in multiple contexts, and the log message would be improved by adding some of that contextual information. The with-context macro allows specifying a data map for a dynamic clojure scope. The context-msg timbre middleware adds this context map to log messages on the :context key. The format-with-context timbre formatter will show the context keys and value in the log message.

There is also a format-with-domain-context that shows both domain and context values.

Tags for Filtering Log Messages

To allow domain level filtering of log messages, use the with-tags macro, specifying a set of keywords. The tags-msg timbre middleware adds this tag set on the :tags key.

Add Log Message Key based on a Var

The add-var function returns a timbre middleware to set a log message key based on the value of the specified var.

Timbre and Java Logging

There are a number of logging choices on the JVM. Different libraries you use may depend on different logging libraries. If you're writing a library, you may wish to allow for logging via Java Logging, while still using timbre.

Logging From Timbre to Java Logging

The com.palletops.log-config.timbre.tools-logging namespace provides the make-tools-logging-appender function, that returns a timbre appender that outputs to tools.logging.

To use it, add an entry in your timbre configuration :appenders:

:appenders {:jl (make-tools-logging-appender {})

Logging java logging to timbre

See taoensso.timbre.tools.logging.

Logging in Tests

Sometimes it is useful to be able to modify log levels in tests. We provide the logging-threshold-fixture function for use as a clojure.test fixture, and suppress-logging which provides a scope where all configured appenders are disabled.

License

Copyright © 2014 Hugo Duncan

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

log-config's People

Contributors

hugoduncan avatar pbors avatar dparis avatar

Watchers

thomas-go avatar

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.