A Clojure library for emitting logfmt. Read the annotated source for details. See the changelog for latest updates.
Add the dependency to your project.clj
file:
[bnadlerjr/logfmt "0.1.0"]
(require '[logfmt.core :as log])
(log/info "Some message text." {:foo 1 :bar 2 :baz 3})
The above will print a message formatted like this to STDOUT
:
at=info msg="Some message text." foo=1 bar=2 baz=3
This project also provides Ring middleware for request logging. For example:
(ns hello-world.handler
(:require [compojure.core :refer :all]
[compojure.route :as route]
[logfmt.ring.middleware :refer [wrap-logger]))
(defroutes app-routes
(GET "/hello" [] "Hello World)
(route/not-found "Page not found"))
(def app
(-> app-routes
wrap-logger))
Any GET requests to /hello
will result in two messages being logged to STDOUT
like this:
at=info msg="Started GET '/hello'" method=GET path="/hello" params={} request-id=abc123
at=info msg="Completed 200 in 10ms" method=GET path="/hello" status=200 duration=10ms request-id=abc123
By default the var dev-mode
is set to false
. Setting it to true
like so:
(require '[logfmt.core :as log])
(log/set-dev-mode! true)
(log/info "Some message text." {:foo 1 :bar 2 :baz 3})
will result in messages being output in a more readable format suitable for local development.
info | Some message text. foo=1 bar=2 baz=3
Pre-requisites:
To install a local snapshot:
$ lein install
To push a new release to Clojars:
- Document added, removed , fixed, etc. in CHANGELOG
- Update the version in
project.clj
lein doc
git add . && git commit
git tag -a vx.x.x -m "Tag version x.x.x"
git push --tags && git push
- Wait for successful TravisCI build
lein deploy clojars
Bug reports and pull requests are welcome on GitHub.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Copyright © 2017-2018 Bob Nadler, Jr.
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.