Hi all.
What i want to do is to log some trace massages when *trace-enabled*
flag is set to t.
Due to real time requirements when *trace-enabled* is set to nil
trace code must not be present in function definition.
My aproach is the following:
(defmacro def-some-function ()
`(defun some-function (arg)
,(if *trace-enabled*
`(progn
(log-to-file *trace-file* (format nil "~A" arg))
arg)
'arg)))
changing *trace-enabled* to t and reevaluating (def-some-function) take
the desired behavior but the code to support this is not so clean
Any better ideas?
Thanks in advance.
········@hotmail.com (Vasilis Margioulas) writes:
> Hi all.
>
> What i want to do is to log some trace massages when *trace-enabled*
> flag is set to t.
> Due to real time requirements when *trace-enabled* is set to nil
> trace code must not be present in function definition.
I'm not sure this actually makes your code any more realtime, but it's
still a nice thing to be able to remove logging compile-time if you
find there is a need for it.
> (defmacro def-some-function ()
> `(defun some-function (arg)
> ,(if *trace-enabled*
> `(progn
> (log-to-file *trace-file* (format nil "~A" arg))
> arg)
> 'arg)))
I guess this is just an example, but anyway, why would you want a
function (SOME-FUNCTION) to do nothing but return its argument?
Anyway, can't you just say:
(defun some-function (arg)
(log-to-file *trace-file* (format nil "~A" arg))
arg)
And let log-to-file be a macro (or maybe a compiler-macro?) which
expands to nil if *trace-enabled* is set to nil and to an actual call
to the log-function otherwise?
I would also let the actual log-function check *trace-enabled* to be
able to turn logging on when compiling, but on or off dynamically
run-time.
You should probably also look in to log4cl
http://www.common-lisp.net/project/log4cl/
I haven't tried this myself, but I have used the java-version which it
is based on quite a bit and I'm very happy with it.
rolf rander
--
http://www.pvv.org/~rolfn/
"Den som kun tar sp�k for sp�k og alvor kun alvorligt, han og hun har
faktisk fattet begge deler d�rlig" -- Piet Hein