Introduction

Introduction — Getting started with Log4g

Overview

Log4g is a GObject-based logging utility. The design of Log4g is based on a port of the popular Log4j 1.2 logging package. Log4j has been ported to many programming languages, including (but not limited to) C ++, Perl and Python. Log4g brings this functionality to the C/GLib/GObject programming stack.

For more information on what the Log4g API can do for you, refer to the articles in the references section of this document.

Description

The core components of Log4g are loggers, appenders and layouts.

Log4g elements (i.e. appenders, layouts and filters) are configured via GObject properties. For a summary of the properties available to each element refer to the API documentation.

Loggers

Loggers are the central object in the Log4g package.

Loggers are arranged in a named hierarchy. The naming convention used by Log4g is to separate logger "classes" with a dot (.). For example, the logger named "org.gnome" is an ancestor of the logger named "org.gnome.foo". Loggers can inherit the appenders of their ancestors. This means that any events logged to the logger named "org.gnome.foo" will also be logged to the appenders of "org.gnome". This property is known as logger additivity. By default all loggers are additive. This property can be disabled via a configuration file (the additivity property of loggers) or with log4g_logger_set_additivity().


Appenders

Appenders determine how events are logged.

Log4g ships with the following appenders:

  • Asynchronous appender

  • Console appender

  • File appender

  • Rolling file appender

  • Syslog appender


Layouts

Layouts determine the format of an event before it is logged by an appender.

Log4g ships with the following layouts:

  • HTML layout

  • Pattern layout

  • Simple layout

  • TTCC layout

  • XML layout


Filters

Log4g has builtin filtering rules, however custom filtering is also possible through the use of filters.

Log4g ships with the following filters:

  • Deny all filter

  • Level match filter

  • Level range filter

  • String match filter


Configuration

One powerful feature of Log4g is the ability to easily configure the package in different ways (via configurators) without recompiling your application.

Log4g ships with the following configurators:

  • Basic configurator

  • DOM configurator

Examples

Log4g must be initialized before it can be used in an application. The documentation for log4g_init() & log4g_get_option_group() provides some initialization and usage examples.

See: The Log4g core API (log4g/log4g.h)

References

Other Implementations

Thanks

Copyright & License

Copyright 2010 Michael Steinert

Log4g is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version.

Log4g is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Log4g. If not, see http://www.gnu.org/licenses/.