Skip to content

log-format helps generate log output ready for parsing by services like Librato

License

Notifications You must be signed in to change notification settings

listora/log-format

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

log-format

Build Status log-format helps generate log output ready for parsing by services like Librato.

Installation

Available via Clojars.

[listora/log-format "0.0.1"]

Usage

Require the library and generate a string ready for logging:

(require '[log-format.core :as lf])

(lf/metrics {:count {:wins 4 :losses 0}})
;; => "count#wins=4 count#losses=0"

Counts, measures, and samples are all supported out-of-the-box. For more information on how Librato's log format works check out their Heroku devcenter article.

To reduce the amount of lines you output to your logs, you can build up a hash-map of the metrics you want to log, and write them out just once (say at the end of a web request).

To add new metrics you simply assoc them into the relevant part of your hash-map, which might look something like:

(require '[log-format.core :as lf])

(defn work [context]
  (-> context
     (assoc-in [:metrics :count :wins] 4)
     (assoc-in [:metrics :count :losses] 0)))

(defn handle [context]
  (let [return-value (work context)]
    (logger/debug (lf/metrics (:metrics return-value)))
    (dissoc :metrics return-value)))

License

Copyright © 2014 Listora

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

About

log-format helps generate log output ready for parsing by services like Librato

Resources

License

Stars

Watchers

Forks

Packages

No packages published