Log4c : Logging for C Library

Summary Requirements Installation Configuration Customization Thanks Copyright

# Summary

Log4c is a library of C for flexible logging to files, syslog and other destinations. It is modeled after the Log for Java library (http://jakarta.apache.org/log4j/), staying as close to their API as is reasonable. Here is a short introduction to Log4j which describes the API, and design rationale.

Mark Mendel started a parallel log4c projet with a different philosophy. The design is macro oriented, so much lighter and faster which perfect for kernel development.

Log4c is also available from SourceForge (http://www.sourceforge.net/projects/log4c/). This is work in progress.

# Requirements

## Platforms

log4c was successfully compiled and run on the following platforms:

- HP-UX release 11.00
- Tru 64 release 4.0F and 5.1
- Red Hat Linux Intel release 7.x, 8, 9
- Red Hat Enterprise Linux 3, 4
- Solaris Intel release 8, 9, 10
- FreeBSD 6.1-RELEASE
- AIX 5.3 (with xlc compiler)
- Mac OS X
- Windows X
- ...and other Linux distributions

log4c should compile and run on the following platforms:

- The BSD family
- MS Windows

## Software

The following software is needed to generate log4c:

- GCC 3.0.1+, to generate log4c, but hopefully not to use it.
- doxygen 1.2.13+, a documentation system for C/C++ needed to generate the documentation.
- graphviz, the AT&T Graph Visualization Tools also needed to generate the documentation.

For the moment, log4c uses specific GCC extensions, like `__attribute__`, so you will need GCC to compile it. This will probably change one day.

# Installation

## Building from source tarballs

on SourceForge:

- log4c-1.2.4.tar.gz

The log4c package uses the GNU autotools compilation and installation framework. The following commands should build log4c on the supported platforms:

$ gzip -dc log4c-1.2.4.tar.gz | tar tvf -
$ cd log4c-1.2.4/
$ ./configure --prefix=/path/of/installation
$ make
$ make install

Checkout the `INSTALL` file for installation and the generated doxygen documentation for more information.

# Configuration

## Configuration files

log4c searches the following files to load its configuration:

- `${LOG4C_RCPATH}/log4crc`
- `${HOME}/`.log4crc
- ``./log4crc

The environment variable `LOG4C_RCPATH` holds the prefix used for installation.

## Configuration syntax

The `log4crc` configuration file uses an XML syntax. The root element is `` <log4c> and it can be used to control the configuration file version interface with the attribute `"version"`. The following 4 elements are supported: `` <config>, `` <category>, `` <appender> and `` <layout>.

- The `` <config> element controls the global log4c configuration. It has 3 sub elements. The `` <nocleanup> flag inhibits the log4c destructors routines. The `` <bufsize> element sets the buffer size used to format log4c_logging_event_t objects. If is set to 0, the allocation is dynamic (the `` <debug> element is currently unused).

- The `` <category> element has 3 possible attributes: the category `"name"`, the category `"priority"` and the category `"appender"`. Future versions will handle multiple appenders per category.

- The `` <appender> element has 3 possible attributes: the appender `"name"`, the appender `"type"`, and the appender `"layout"`.

- The `` <layout> element has 2 possible attributes: the layout `"name"` and the layout `"type"`.

Here's the `log4crc` configuration file example:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE log4c SYSTEM "">
<log4c>
<config>
<bufsize>0</bufsize>
<debug level="0"/>
<nocleanup>0</nocleanup>
</config>
<!-- root category ========================================= -->
<category name="root" priority="notice"/>
<!-- default appenders ===================================== -->
<appender name="stdout" type="stream" layout="basic"/>
<appender name="stderr" type="stream" layout="dated"/>
<appender name="syslog" type="syslog" layout="basic"/>
<!-- default layouts ======================================= -->
<layout name="basic" type="basic"/>
<layout name="dated" type="dated"/>
</log4c>

This initial version of the log4c configuration file syntax is quite different from log4j. XML seemed the best choice to keep the log4j configuration power in a C API.

## Environment variables

- `LOG4C_RCPATH` holds the path to the main `log4crc` configuration file
- `LOG4C_PRIORITY` holds the `"root"` category priority
- `LOG4C_APPENDER` holds the `"root"` category appender

# Customization

This section will, one day, briefly describe how to define custom appenders and custom layouts. Be patient or checkout the source.

# Thanks

Mark Mendel for his work on a previous version of log4c.

This project would not have existed without Ceki Gulcu, the creator and maintainer of Log4j, nor without Bastiaan Bakker, who initiated me with Log4Cpp.

Many thanks to

- Joel Schaubert for many contributions
- Robert Byrne for Windows port and also many contributions
- Olger Warnier for the Mac OS X port
- Jeff Smith for writing a primer on how to use Log4c effectively

# Copyright

All software in this package is Copyright (C) 2003-2004 Meiosys http://www.meiosys.com and Cedric Le Goater and is distributed under the LGPL License. See the `COPYING` file for full legal details.