[log5-devel] Dynamically set log level

Stefan Neumann stefan.neumann at freiheit.com
Tue Aug 28 08:20:43 UTC 2007


Hi Gary,

Gary King wrote:
> Hi Stefan,
> 
>> I'm curious if it is possible to dynamically set the log level when
>> creating a sender like:
>>
>> (defun init-logging (log-level)
>>   (log5:defoutput human-time (human-time))
>>   (log5:start-sender *my-logger*
>>              (log5:stream-sender :location *standard-output*)
>>              :category-spec log-level
>>              :output-spec (log5:category human-time log5:message
>> log5:context)))
> 
> Other than moving the defoutput from inside the defun to outside it (for
> efficiency reasons), I think that what you have there is exactly right.

Since I init the logger only once during the program run it is fine ;-)

>> I know, that it does not work like that, but is there another way than
>> using configure-from-file?
>
> Both the start-sender macro and configure-from-file call the
> start-sender-fn so your definition ought to work. What happens when you
> try it?
>

OK, my fault. I could have been more verbose:

I tried it in several ways:

(defun init-logging (log-level)

  (log5:defoutput human-time (human-time))
    (log5:start-sender *my-logger*
      (log5:stream-sender :location *standard-output*)
	  :category-spec (translate-loglevel-from-string log-level)
	  :output-spec (log5:category human-time log5:message log5:context))))

(defun translate-loglevel-from-string (log-level)
  (cond ((string= "error")
         (log5:error+))
..

It that case it does not work because sbcl can't find the function
"error+". If I don't use the paranthesis, the stream-sender raises an
error complaining that translate-loglevel-from-string is not a known
category.

To sum up, I have a program, which gets the log-level as a string. I
want to translate this string to a log5 log level and pass it to the
creation of a logger. I hope I could give you an image, of what I would
need.

>> Thanks in advanced for your help.
> 
> My pleasure.

Once again, I really appreciate your help.

Stefan




More information about the Log5-devel mailing list