logger

Table of Contents

1. What

Minimal Clojure logging library, mainly for scripting

2. Why?

There are quite a few logging libraries already available, so why another one? Some goals:

  • Log both to a file and to the console (stdout for now)
  • Include timestamps with both milliseconds and timezone
  • No config files needed
  • Keep it simple, mostly for command line scripts
  • Support multiple log files, e.g. server/daemon and client/script logs.

3. Installation

Leiningen/Boot

[ndevreeze/logger "0.6.0"]

Clojure CLI/deps.edn

ndevreeze/logger {:mvn/version "0.6.0"}

logger.svg

4. Usage

Require:

(ns my.namespace
   (:require [ndevreeze.logger :as log]))

Initialise the logger:

(log/init "/tmp/foo.log" :info)

or, to only log to stderr:

(log/init nil :debug)

or, init with a map, with these keys:

  • level - log level like :info, :debug
  • file - give an explicit full path. Default is nil, use pattern
  • pattern - use a pattern for the log file path, see below
  • location - some pattern defaults/shortcuts, :home, :cwd, :script, :temp, default is nil
  • name - script name, “script” bij default
  • cwd - give an explicit current-working-dir, default is nil
  • overwrite - boolean, overwrite an existing log file, default false

if all of file, pattern and location are nil, do not create a logfile, just log to the console.

To use in pattern:

  • %h = home dir
  • %c = current dir
  • %s = script dir (TBD)
  • %t = temp dir (/tmp, or c:/tmp)
  • %n = script name
  • %d = datetime, as yyyy-mm-ddTHH-MM-SS“

Then log at different levels:

(log/error "A different logfile, error level")
(log/warn "warn level")
(log/debug "One line at debug level")
(log/info "At info level")

5. Developing

5.1. Testing

$ lein midje

or:

$ lein repl (or start in Cider)
(use 'midje.repl)
(autotest)

5.2. API Docs

5.3. Creating docs

lein codox
# commit and push to github
# wait a few minutes for github to push to ndvreeze.github.io

Also build Clojars docs from the site: https://cljdoc.org/d/ndevreeze/logger/0.6.0/doc/readme

5.4. Publish to Clojars

lein deploy clojars

5.5. Other docs

5.6. Bugs

:CUSTOMID: bugs

  • No known errors. Use Github issues if you want to report a bug.

7. Version history

  • 0.6.0 - use Log4j 2.17.1

8. License

Copyright © 2020, 2021, 2022 Nico de Vreeze.

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

Author: Nico de Vreeze (orig)

Created: 2022-01-19 wo 21:06

Validate