[Klone-users] Custom log

thomas fossati tho at koanlogic.com
Thu May 15 09:42:47 EDT 2008


Hi Mickael,

On May 15, 2008, at 2:46 PM, Mickael Auger wrote:
> I would like trace message in log file, the same that KLone or  
> another.
> I have tested  with standard "syslog" function without result.
> What function(s) could I use to have custom log message ?

the simplest way is to use the embedded libu::{log,carpal} module.   
You have at your disposal the following macros: dbg(), info(),  
notice(), warning(), err(), crit(), alert(), emerg(), each of which  
corresponds to a standard syslog level/priority.  The syslog facility  
specified via 'syslog.facility' configuration directive is implicitly  
used to route all the messages going through this interface.  All the  
macros take printf-like arguments as input, e.g.: dbg("user %s  
authentication failed", user);

Keep in mind that the dbg(); messages will be active only in case -- 
enable_debug has been used, and also dbg_... is heavily used by klone  
internally, so perhaps it's better to allocate another priority to  
your trace function (e.g. info() or notice()).

So, in an header file of yours (say my_trace.h):

#include <u/libu.h>
#ifdef KLAPP_TRACE_ON
#define TRACE info
#else
#define TRACE u_unused_args
#endif

In the klapp Makefile:

# uncomment the following to enable tracing messages
#WEBAPP_CFLAGS += -DKLAPP_TRACE_ON

In your kl1 code:

<%!
     #include <my_trace.h>
%><%
     TRACE("tracing variable %s", a_string_variable);
%>

and finally in your syslog.conf file - supposing that syslog.facility  
is LOG_LOCAL0:

local0.info	/var/log/my_klapp.trace


Hope it helps.

ciao, t.




More information about the klone-users mailing list