apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henry Jen <henry...@ztune.net>
Subject A thin adapting layer for logging service
Date Fri, 19 Nov 2004 03:07:09 GMT
Hi,

I am looking for some simple logging API for C when I working on
jxta-c, and since log4c is under LGPL, I decided to start my own work
with a simple API. As discussed briefly in apr@irc.freenode.net, I
thought it may be a nice-to-have for apr-util. 

So, I post this here and apr-util is interested to include it, I will
work on to make it better fit for apr. Noted that this is not
compilable within apr as is. 

The design behind this is simple, a *process*(e.g, shell) needs to setup
a global logger function by calling jpr_log_using(...) function. This
logger function may be a dispatch function for different logs or just as
simple as a wrapper function to vprintf(...).

The *component*(e.g, libjxta) use the global logger function by calling
jpr_log_append(...) function, which will in turn call the logger
function setup by the *process*.

A *selector* class is implemented to assist decision on whether a
message should be logged based on given *category* and *level*.

*category* is basically a free form string except cannot have ','
character and no leading/trailing spaces.

Six *level*s are defined: critical, error, warning, info, debug and
ext_debug.

Selector can be modified with a programatic way so category can be
added/removed dynamically or initialized with a selector string. The
selector string in ABNF is at end of this email.

A simple file logger is implemented to demonstrate how to use selector
and can serve the purpose of a basic file logger. You can refer to the
unit test program as a sample.

Current version is not thread safe, next version will be. I also want
to use apr_pool function for allocating memory for categories, as I
don't think they will change frequently until the program terminate and
the amount of memory is relative small.

The code attached here are working and for your review purpose to see
if there is interest.

jpr_log.h - public header 
jpr_log_priv.h - private header 
jpr_log.c - implementation 
jpr_log_unit_test.c - simple unit test program to verify the function

Your comments are welcome.

Cheers,
-- 
Henry Jen, a.k.a slowhog


PS. Selector string in ABNF form (RFC2234):

selector_string = category_list "." level_list

category_list = "*" / (["!"] *is_space categories)
categories = *is_space category *is_space [("," categories) / (","
*is_space)]
category = 1*cat_char *(*is_space cat_char)
cat_char = %x01-08 / %0C / %x0E-1F / %x21-2B / %2D-7F   ; not isspcae
nor ','

level_list = "*" / (["!"] *is_space level_spec)
level_spec = *is_space level *is_space [("," level) / ("," *is_space)]
level = level_literal [ *is_space "-" *is_space level_literal ]
level_literal = "critical" / "error" / "warning" / "info" / "debug" /
"ext_debug"
is_space = CR / LF / WSP / %x0B          ; %x0B is vtab


Mime
View raw message