ganelon.util.logging documentation

Additional webapp-related utility logging functions, with features such as noir.request/*request* capture
or logging and returning of a value or execution duration logging.

enrich-log-msg

(enrich-log-msg msg)
Enhance log message with :remote-addr and :uri from noir.request/*request* and
session attribute named __user.

Parameters:
  msg - log message

Example:
(enrich-log-msg "This is a test!")
;=> "This is a test! REQUEST: {:remote-addr \"127.0.0.1\", :uri \"/routing/samplel\"} USER: {:screenname \"admin\"}"

handle-exception

macro

(handle-exception e)(handle-exception msg e)
Log exception using clojure.tools.logging with :error log level and enriched message.
Parameters:
  msg - diagnostic message, possibly explaining the conditions in which the error has occured
  e - java.lang.Throwable, which will be logged

Example:
(handle-exception "No need to panic!" (java.lang.Exception. "ooops"))
;SEVERE: No need to panic!
;java.lang.Exception: ooops
;	at ganelon.util.logging$eval4008.invoke(NO_SOURCE_FILE:25)
;	at clojure.lang.Compiler.eval(Compiler.java:6511)
;	at clojure.lang.Compiler.eval(Compiler.java:6477)
;=> nil

log

macro

(log level & msg)
Log enriched message with appropriate clojure.tools.logging log level, taking potential noir.request/*request*
  into account
Parameters:
 level - log level keyword, e.g. :info, :debug, :warn, :error
 & msg - values to be logged

Example:
(log :info "Logged in user " {:login "test"})
;INFO: Logged in user {:login "test"}
;=> nil

log-start-end

macro

(log-start-end level msg & body)
Log execution time, generating random UUID to mark start and end entries in logs.
Parameters:
  level - log level, e.g. :info, :debug, :warn, :error
  msg - message text
  & body - body to be evaluated (and returned)

Example:
(log-start-end :info :operation-x (Thread/sleep 1000) :result-y)
;INFO: 13608266406980 1360826640698 0e4ba5ba-1e93-43d1-adcd-78eb6d37f3c9;Started :operation-x Thread[main,5,main]
;INFO: 13608266406981 1360826640698 0e4ba5ba-1e93-43d1-adcd-78eb6d37f3c9;Ended :operation-x Thread[main,5,main], time: 1003ms
;=> :result-y

log-val

macro

(log-val level msg & val)
Log message with returned value. Then return (last val). Useful for tracing values without introducing unnecessary scopes.
Parameters:
  level - log level, e.g. :info, :debug, :warn, :error
  msg - message text
  val - values that will be logged and the last of them will be returned

Example:
(log-val :info "test! " 1 2 3)
;INFO: test! 123
;=> 3