X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fdoc%2Flog.txt;h=28265f7290af6c4795cb5d85e8736f75df062435;hb=f501fcf311379b78506474478a17d82382b753e4;hp=a24a50ddddfea3549f1df2fed874fe855f6c9fbd;hpb=2ef1656793bb6e85835e0be7a5045d0473023b60;p=libucw.git diff --git a/ucw/doc/log.txt b/ucw/doc/log.txt index a24a50dd..28265f72 100644 --- a/ucw/doc/log.txt +++ b/ucw/doc/log.txt @@ -18,9 +18,8 @@ A newline character is automatically appended; the message should not contain any control characters. The first argument of `msg` can be OR'ed with additional flags. Most notably, you can -add `L_SIGHANDLER` if you wish to log a message from a signal handler (calling -time-related functions in libc from signal handlers is generally unsafe, so -`msg` does not log a timestamp in such cases). +add `L_SIGHANDLER` if you wish to log a message from a signal handler (see below +for discussion on signals and reentrancy in general). By default, all messages are logged to stderr. If you wish to use a log file, call `log_file(@name)`. All subsequent logging will use this file and stderr @@ -83,12 +82,21 @@ Example int main(int argc, char **argv) { log_init(argv[0]); - struct log_stream *ls = log_new_file("/var/log/utterances"); + struct log_stream *ls = log_new_file("/var/log/utterances", 0); msg(L_INFO | ls->regnum, "Aye captain, we have a log file"); msg(L_INFO, "Alas, stderr still works"); return 0; } +Message types +------------- +Messages can also have types, which can be used for further filtering inside streams. +By default, there is only the default message type. To obtain an identifier of a new +type (again to be OR'ed to the log level when calling <>), use <>. +The number of types is currently limited to 32. + +If you want non-default types to be visible, enable the `LSFMT_TYPE` format flag. + Processes, threads and signals ------------------------------ When you fork a new process, it automatically inherits all currently configured log @@ -109,6 +117,38 @@ LibUCW therefore offers only limited logging services in such situations and you must use the `L_SIGHANDLER` flag to request it. Otherwise, deadlocks get ready to happen. +Messages logged with `L_SIGHANDLER` set are written directly to stderr (which +is usually an alias for the main log file, at least if you use <>) +and they do not carry a timestamp. Logging of sighandler messages to general +log streams or to syslog is therefore not supported. + ucw/log.h --------- !!ucw/log.h + +Limiting rate: ucw/tbf.h +------------------------ + +LibUCW also offers simple means of limiting the rate of log messages (or of any other +events) by means of a so called 'Token Bucket Filter.' The idea behind this filter is +simple: To log a message, we need a token. The available tokens are accumulated in +a bucket which has a fixed 'filling rate' (the number of tokens arriving in the bucket +per second, which may be a fractional number) and fixed 'maximum capacity.' The +bucket receives the tokens continuously with the given rate and when it reaches +the maximum capacity, the extra tokens are dropped on the floor. When a message +has to be sent, we take a single token from the bucket and if there wasn't any, +we drop the message. + +The filling rate therefore describes the maximum sustained rate of messages, +while the bucket capacity tells the filter the maximum length of a short burst, +which can temporarily exceed the rate. + +A general bucket filter is available in `ucw/tbf.h`. The usual way of using it +to limit logging is to set up a filter hook of a stream which asks the TBF for +every message. (Remember, though, that if your program is multithreaded, the +filter hook can be run in multiple threads in parallel, so it has to guard the +TBF by a lock.) The configuration interface for log streams described above +is able to attach rate limiters to streams per user's request, so you usually +need not take any extra care. + +!!ucw/tbf.h