?

Log in

No account? Create an account

fanf

ANNOUCE: selog - selective logging library

« previous entry | next entry »
10th Apr 2008 | 14:25

I'm pleased to announce the first release of selog, which you can download from <http://dotat.at/prog/selog/>.

Selog is a library of routines that unifies error reporting, activity logging, and debug tracing. It allows programmers to give their users flexible control over which messages are written and where they are written to.

Selog is designed to be as simple as possible while still being extremely efficient, powerful, and flexible. The essence of selog is:

  • Obtain a configuration string from the user, which looks like:

    +log_pid+example@syslog;-example@stderr

  • When the program starts, initialize selog with the user's configuration.

    selog_open(config, spelling)

  • Define a selector for each different kind of message.

    static selog_selector sel = SELINIT("example", SELOG_INFO);

  • Use the selog() function to emit messages instead of printf() or syslog().

    selog(sel, "message number %d", n);

Selectors determine which messages are written and where they are written to, under the control of the user's configuration. You can direct messages to any combination of stderr, syslog, files, pipes, etc. You can omit or include optional parts of messages under the control of selectors. You don't have to signal the program when you rotate its log files.

The C interface consists of just 13 functions, 5 macros, 2 types, and an enum. There are a few variations of the basic selog() one-shot logging function, or you can quickly and easily compose messages in stages. The check to skip disabled messages is extremely small and fast.

Selog comes with shell command and Lua interfaces, plus interposition libraries which you can use to fool old code that calls err() or syslog() into using selog instead.

Selog's origins

I started work on selog when I found myself writing yet another half-arsed logging/debugging module that could only be used by the program it was written for. The problem needed to be solved properly, but I couldn't find a decent existing solution.

Exim's logging and debugging facilities provided the basis for selog's configuration syntax and the idea for the fast check to disable debugging code. Like many other programs, Exim's logging and debugging code is non-orthogonal and non-reusable; selog exists to avoid problems like Exim's fixed set of log files and the lack of debugging redirection.

The architecture of log4j and its many imitators provided many nice ideas to copy, in particular selog's selectors and channels are similar to log4j's loggers and appenders. However log4j is unnecessarily complicated, so selog discards plenty of its ideas, such as hierarchial category names and arbitrarily configurable message layouts. Bloaty log4c provided a salutory anti-pattern.

I've tried to make this first release fairly polished - e.g. it has comprehensive documentation - however it has not had its portability catches polished off, and in particular I'm going to be interested to see how much trouble my use of C99 features causes. The next step is to go back to the program that I wrote selog for, and put the code to use...

| Leave a comment | Share

Comments {11}

Simon Tatham

from: simont
date: 10th Apr 2008 14:36 (UTC)

I'm momentarily confused by the absence of any obvious copyright notice or licence file. I found the line in README saying "You may do anything with this, at your own risk". Am I right in thinking that that is the intent of the licence on this software, or have I managed to miss something more prominent elsewhere?

If the former, are you actually waiving copyright on the code, or merely granting an extremely permissive licence? Using "Written by" in place of "Copyright" suggests your intention might have been to do the former, but if I remember rightly, other copyright waivers I've seen have been rather more explicit and verbose.

Reply | Thread

Tony Finch

from: fanf
date: 10th Apr 2008 14:40 (UTC)

That is the entirety of the licence. I am neither asserting nor waiving copyright.

Reply | Parent | Thread

Simon Tatham

from: simont
date: 10th Apr 2008 17:58 (UTC)

Which probably means that you do still have copyright, since AIUI you automatically have it on anything you write unless you specifically waive it.

So if, hypothetically, I were to include your library in a program of mine which did have a copyright notice, what would I have to do? My guess is that it would be some sort of misrepresentation to simply write "This software is copyright Simon Tatham", since not all of it would be. So presumably what would happen is that I'd have to put your name in the copyright statement, but that I would then have an entirely free choice of what licence to put the whole lot under?

Reply | Parent | Thread

Tony Finch

from: fanf
date: 10th Apr 2008 18:20 (UTC)

Which probably means that you do still have copyright, since AIUI you automatically have it on anything you write unless you specifically waive it.

Yes, and in fact it might not even be possible to waive it in some jurisdictions. There are also aspects of copyright that cannot be transferred, like the author's moral rights. But it seems silly to assert copyright above a license that's this liberal. On the other hand, I suppose a declaration by the author that a work is in the public domain will not be mis-interpreted even if it is technically incorrect.

So if, hypothetically, I were to include your library in a program of mine which did have a copyright notice, what would I have to do?

Anything you like.

Reply | Parent | Thread

Andrew

from: nonameyet
date: 11th Apr 2008 08:16 (UTC)

I would then have an entirely free choice of what licence to put the whole lot under?

Which might be very desirable. You can include it in your GPL'd package and I can include it in mine which is BSD or otherwise incompatible with the GPL...

Reply | Parent | Thread

The Bellinghman

from: bellinghman
date: 10th Apr 2008 15:08 (UTC)

I'm going to be interested to see how much trouble my use of C99 features causes

Without checking the source, I'd be mildly interested to know what particular C99 features you are making use of. I can guess possibly variadic macros and inline functions.

Reply | Thread

Tony Finch

from: fanf
date: 10th Apr 2008 15:13 (UTC)

Good guess :-)

In the end I didn't use inline functions because in (almost) all the cases where I needed speed I had to use variadic macros.

I also use stdbool and a few C++ish declaration positions.

Reply | Parent | Thread

The Bellinghman

from: bellinghman
date: 10th Apr 2008 15:18 (UTC)

I'm rather tempted to take a look at the source and see about a C++ version.

I suspect that that'd use templates quite a bit.

Reply | Parent | Thread

Tony Finch

from: fanf
date: 10th Apr 2008 15:29 (UTC)

One of the things I did in the Lua version which might be translatable into C++ was make selectors callable, so instead of selog(sel, "message") you can write sel("message").

Reply | Parent | Thread

Arnhem

from: arnhem
date: 11th Apr 2008 07:22 (UTC)

It's presumably unwise to use selog in a program that elevates its privilege?

Reply | Thread

Tony Finch

from: fanf
date: 11th Apr 2008 08:27 (UTC)

It's ok if the program is careful about where it gets its configuration from, which at the moment requires clearing the SELOG_CONFIG environment variable. I'll make a note that selog should deal with that itself.

Reply | Parent | Thread