From stefan.neumann at freiheit.com Mon Aug 27 22:22:27 2007 From: stefan.neumann at freiheit.com (Stefan Neumann) Date: Tue, 28 Aug 2007 00:22:27 +0200 Subject: [log5-devel] Dynamically set log level Message-ID: <46D34EA3.5050307@freiheit.com> Hi, I am quite new to lisp, so hopefully my question is not too "dumb". ;-) 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))) I know, that it does not work like that, but is there another way than using configure-from-file? Thanks in advanced for your help. Stefan From gwking at metabang.com Tue Aug 28 00:31:54 2007 From: gwking at metabang.com (Gary King) Date: Mon, 27 Aug 2007 20:31:54 -0400 Subject: [log5-devel] Dynamically set log level In-Reply-To: <46D34EA3.5050307@freiheit.com> References: <46D34EA3.5050307@freiheit.com> Message-ID: 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. > 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? > Thanks in advanced for your help. My pleasure. -- Gary Warren King, metabang.com Cell: (413) 559 8738 Fax: (206) 338-4052 gwkkwg on Skype * garethsan on AIM From stefan.neumann at freiheit.com Tue Aug 28 08:20:43 2007 From: stefan.neumann at freiheit.com (Stefan Neumann) Date: Tue, 28 Aug 2007 10:20:43 +0200 Subject: [log5-devel] Dynamically set log level In-Reply-To: References: <46D34EA3.5050307@freiheit.com> Message-ID: <46D3DADB.9080401@freiheit.com> 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 From gwking at metabang.com Tue Aug 28 23:37:19 2007 From: gwking at metabang.com (Gary King) Date: Tue, 28 Aug 2007 19:37:19 -0400 Subject: [log5-devel] Dynamically set log level In-Reply-To: <46D3DADB.9080401@freiheit.com> References: <46D34EA3.5050307@freiheit.com> <46D3DADB.9080401@freiheit.com> Message-ID: <4320DAAF-9E31-4907-92CB-AD09F5A66EA9@metabang.com> Hi Stefan, Your code was close but not quite there. Syntax can really get in the way of things. 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