Giter Site home page Giter Site logo

justlogit's Introduction

justlogit

Minimal logging library for Clojure

I don't like clojure.contrib.logging. I like even less log4j and the rest of Java logging paraphernalia. I just want to log.

I like to log to standard error output (read this to get an idea of why) so that's the default for justlogit.

Usage

There are six log levels: fatal, error, warn, info, debug and trace. For each one there are two macros named level and level-t. To the first style macros you pass arguments as in clojure.core/format. To the second class of macros, you pass a Throwable as first argument.

Samples

(fatal "A bad thing happened: %s, aborting" (get-bad-thing))

will output something like

FATAL 2011-04-05T19-55-06.859 [your-ns]: A bad thing happened: bad thing, aborting

If you want to log a Throwable instance, use:

(try
  (danger)
  (catch Exception e
    (warn-t e "So, what now")))

Which will produce something like

WARN 2011-04-05T19-55-06.859 [your-ns]: So, what now
java.lang.Exception: transaction rolled back: foooooo
 at clojure.contrib.sql.internal$throw_rollback.invoke (internal.clj:142)
    clojure.contrib.sql.internal$transaction_STAR_.invoke (internal.clj:169)
.....
.....

Advanced use

If you don't want the defaults you can customize the behaviour using both context macros and global setters:

(set-log-level :warn)
; warn is set as minimum log level globally.
; calls of lower priority won't be logged (nor evaluated)

(with-log-level :warn
  ;inside this context the minimum log level is set to :warn
  (do-your-thing))
  ;and everything is back to normal now


(set-log-writer my-writer) ;sets the global OutputStreamWriter to use for logging

(with-log-writer my-writer
  (do-your-thing))  ;scoped writer

You can also customize the log format, using a function that returns the logged string. This function takes a map with keys: :level: (Keyword), :timestamp (java.util.Date), :namespace (String), :message (string), :throwable (optional Throwable instance)

;set a new formatter globally
(set-log-formatter #(str "Broken: " (:message %)))

;scoped formatter
(with-log-formatter #(str "Broken: " (:message %))
  (debug "I'm here"))

Contributors

License

Copyright (C) 2011 Sebastián Galkin

Distributed under the Eclipse Public License, the same as Clojure.

justlogit's People

Contributors

abscondment avatar paraseba avatar

Stargazers

 avatar

Watchers

 avatar  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.