[log5-devel] Dynamically set log level
Gary King
gwking at metabang.com
Tue Aug 28 23:37:19 UTC 2007
Hi Stefan,
Your code was close but not quite there. Syntax can really get in the
way of things. <smile>
Here is a slightly modified version of your code with some extra
comments:
I define this silly human-time so that things work...
> (defun human-time ()
> (get-universal-time))
In the start-sender macro, the category-spec and the output-spec both
get evaluated. This means that the macro doesn't quote them for you
so that you can use functions (which is good, that's what you want to
do!). The only change I've made here is to quote the list
(log5:category human-time log5:message log5:context).
> (defun init-logging (log-level)
> (log5:defoutput human-time (human-time))
> (log5:start-sender
> 'foo
> (log5:stream-sender :location *standard-output*)
> :category-spec (translate-loglevel-from-string log-level)
> :output-spec '(log5:category human-time log5:message
> log5:context)))
Similarly, the return value from the cond expression (log5:error+)
needs to be quoted (as it is below). If you don't quote the
expression, then Lisp will evaluate it. When Lisp evaluates
(log5:error+) it tries to see if the first expression in the list --
i.e., log5:error -- is a function. Since it's not a function, Lisp
complains. When I quote the list, then Lisp knows to just return it.
> (defun translate-loglevel-from-string (log-level)
> (cond ((string= log-level "error")
> '(log5:error+))
> (t
> (error "cannot translate log level: ~s" log-level))))
Let me know if anything is still unclear or if something doesn't work
the way you expect.
--
Gary Warren King, metabang.com
Cell: (413) 559 8738
Fax: (206) 338-4052
gwkkwg on Skype * garethsan on AIM
More information about the Log5-devel
mailing list