Log4g Reference Manual | ||||
---|---|---|---|---|
Top | Description |
#define LOG4G_LOG_DOMAIN void log4g_init (int *argc
,char ***argv
); void log4g_finalize (void
); GOptionGroup * log4g_get_option_group (void
); #define log4g_get_logger (name) #define log4g_get_root_logger #define log4g_assert (assertion, format, args...) #define log4g_logger_assert (logger, assertion, format, args...) #define log4g_is_trace_enabled #define log4g_trace (format, args...) #define log4g_logger_trace (logger, format, args...) #define log4g_is_debug_enabled #define log4g_debug (format, args...) #define log4g_logger_debug (logger, format, args...) #define log4g_is_info_enabled #define log4g_info (format, args...) #define log4g_logger_info (logger, format, args...) #define log4g_is_warn_enabled #define log4g_warn (format, args...) #define log4g_logger_warn (logger, format, args...) #define log4g_is_error_enabled #define log4g_error (format, args...) #define log4g_logger_error (logger, format, args...) #define log4g_is_fatal_enabled #define log4g_fatal (format, args...) #define log4g_logger_fatal (logger, format, args...)
The file defines the API that most users of Log4g will want to use. Sticking to this API will allow you to easily compile Log4g out of your application by defining LOG4G_DISABLE before including this file (i.e. in config.h, etc).
You may also wish to refer to the documentation for NDC (nested data contexts) & MDC (mapped data contexts). The NDC & MDC APIs can also be compiled out of your code.
Defining LOG4G_LOG_DOMAIN before you include log4g/log4g.h will set the log domain for the current file. Log statements that do not specify a logger will use the LOG4G_LOG_DOMAIN logger by default.
Example (log a message to the "org.gnome.test" logger):
#define LOG4G_LOG_DOMAIN "org.gnome.test" #include <log4g/log4g.h> void foo(void) { log4g_warn("you had better watch out"); }
If LOG4G_LOG_DOMAIN is not defined then log statements will use the root logger by default. You may also explicitly specify a logger when you log a message.
void log4g_init (int *argc
,char ***argv
);
Initialize the Log4g package.
Log4g accepts some standard command line arguments (all prepended with
"log4g"). Calling this function will parse out the arguments Log4g
understands and removes them from the argument list. If you call
log4g_init()
before parsing application options your application will
not see the Log4g arguments.
Example (initialize Log4g):
#include <log4g/log4g.h> #include <stdlib.h> int main(int argc, char **argv) { g_thread_init(NULL); log4g_init(&argc, &argv); log4g_info("Log4g is initialized & ready to go!"); return EXIT_SUCCESS; }
Log4g accepts the following command line arguments:
--log4g-configuration=<FILE.xml>
Specify an XML configuration file to load. If the XML configuration file could not be loaded (or if none was specified) then Log4g will be configured using the basic configurator.
--log4g-flags=<FLAGS>
Specify flags that modify the behavior of Log4g. Currently Log4g understands two flags.
debug: enable debug output on stdout
quiet: disable all error and debug output
--log4g-main-thread=<NAME>
Set the name of the main thread (the default is "main").
After calling this function the Log4g API is ready for use within your application.
|
A pointer to main's argc variable.
|
|
A pointer to main's argv variable.
|
Since 0.1
void log4g_finalize (void
);
Finalize the Log4g package.
It is not strictly necessary to call this function to use Log4g.
Calling this function will destroy the logger hierarchy and any cleanup
any instance data used by Log4g. One advantage of calling log4g_finalize()
is to allow asynchronous appenders a chance to flush any pending log
messages before your application exits.
Example (initialize & cleanup Log4g):
#include <log4g/log4g.h> #include <stdlib.h> int main(int argc, char **argv) { g_thread_init(NULL); log4g_init(&argc, &argv); log4g_info("Log4g is initialized & ready to go!"); log4g_finalize(); return EXIT_SUCCESS; }
If you call this function you must call log4g_init()
again before using
the Log4g API.
Since 0.1
GOptionGroup * log4g_get_option_group (void
);
Retrieve the option group used by the Log4g package.
If your application is using the GLib option parser then you may call this function to retrieve the option group parsed by Log4g.
Example (initialize Log4g via a GOptionGroup):
#include <log4g/log4g.h> #include <stdlib.h> #define GETTEXT_PACKAGE "test-app" #include <glib/gi18n-lib.h> int main(int argc, char **argv) { GError *error = NULL; GOptionContext *context; GOptionEntry entries[] = { { NULL } }; g_thread_init(NULL); context = g_option_context_new("- demonstrate Log4g initialization"); if (!context) { return EXIT_FAILURE; } g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE); g_option_context_add_group(context, log4g_get_option_group()) if (!g_option_context_parse(context, &argc, &argv, &error)) { log4g_error("failed to parse options: %s", error->mesasge); g_error_free(error); return EXIT_FAILURE; } g_option_context_free(); log4g_info("Log4g is initialized & ready to go!"); log4g_finalize(); return EXIT_SUCCESS; }
If you use the returned option group in a GLib option parser you do not
need to call log4g_init()
.
Returns : |
A GLib option group. |
Since 0.1
#define log4g_get_logger(name)
Retrieve a named logger from the repository.
If the named logger exists in the repository that instance is returned. If the named logger does not exist it will be created.
See
: Log4gLoggerClass, log4g_logger_get_logger()
|
The name of the logger to retrieve. |
Returns : |
The logger named name .
|
Since 0.1
#define log4g_get_root_logger()
Retrieve the root logger.
See
: Log4gRootLoggerClass
Returns : |
The root logger. |
Since 0.1
#define log4g_assert(assertion, format, args...)
Log an error if an assertion
is FALSE
.
Example:
log4g_assert((pointer != NULL), "%s: pointer is NULL!", "ERROR");
See
: log4g_logger_assert()
, _log4g_logger_assert()
|
The assertion to evaluate. |
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_logger_assert(logger, assertion, format, args...)
Log an error if an assertion
is FALSE
.
Example:
log4g_logger_assert(log4g_get_logger("org.gnome.debug"), (NULL != pointer), "%s: pointer is NULL!", "ERROR");
See
: log4g_assert()
, _log4g_logger_assert()
|
A logger object. |
|
The assertion to evaluate. |
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_is_trace_enabled()
Check if the trace level is enabled.
Use this macro if you need to perform a resource-intensive operation before logging a message.
Example:
if (log4g_is_trace_enabled()) { char *string = perform_IO_intensive_operation(); log4g_trace("here I am: %s", string); }
A similar macro exists for all of the default log levels.
See
: log4g_logger_is_trace_enabled()
, log4g/level.h
Returns : |
TRUE if trace is enabled, FALSE otherwise.
|
Since 0.1
#define log4g_trace(format, args...)
Log a trace message.
Example:
log4g_trace("example %s message", "TRACE");
See
: log4g_logger_trace()
, _log4g_logger_trace()
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_logger_trace(logger, format, args...)
Log a trace message.
Example:
log4g_logger_trace(log4g_get_logger("org.gnome.debug"), "example %s message", "TRACE");
See
: log4g_trace()
, _log4g_logger_trace()
|
A logger object. |
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_is_debug_enabled()
Check if the debug level is enabled.
See
: log4g_logger_is_debug_enabled()
, Log4gLevelClass,
log4g_is_trace_enabled()
Returns : |
TRUE if debug is enabled, FALSE otherwise.
|
Since 0.1
#define log4g_debug(format, args...)
Log a debug message.
Example:
log4g_debug("example %s message", "DEBUG");
See
: log4g_logger_debug()
, _log4g_logger_debug()
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_logger_debug(logger, format, args...)
Log a debug message.
Example:
log4g_logger_debug(log4g_get_logger("org.gnome.debug"), "example %s message", "DEBUG");
See
: log4g_debug()
, _log4g_logger_debug()
|
A logger object. |
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_is_info_enabled()
Check if the info level is enabled.
See
: log4g_logger_is_info_enabled()
, Log4gLevelClass,
log4g_is_trace_enabled()
Returns : |
TRUE if info is enabled, FALSE otherwise.
|
Since 0.1
#define log4g_info(format, args...)
Log an info message.
Example:
log4g_info("example %s message", "INFO");
See
: log4g_logger_info()
, _log4g_logger_info()
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_logger_info(logger, format, args...)
Log an info message.
Example:
log4g_logger_info(log4g_get_logger("org.gnome.debug"), "example %s message", "INFO");
See
: log4g_info()
, _log4g_logger_info()
|
A logger object. |
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_is_warn_enabled()
Check if the warn level is enabled.
See
: log4g_logger_is_warn_enabled()
, Log4gLevelClass,
log4g_is_trace_enabled()
Returns : |
TRUE if warn is enabled, FALSE otherwise.
|
Since 0.1
#define log4g_warn(format, args...)
Log a warn message.
Example:
log4g_warn("example %s message", "WARN");
See
: log4g_logger_warn()
, _log4g_logger_warn()
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_logger_warn(logger, format, args...)
Log a warn message.
Example:
log4g_logger_warn(log4g_get_logger("org.gnome.debug"), "example %s message", "WARN");
See
: log4g_warn()
, _log4g_logger_warn()
|
A logger object. |
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_is_error_enabled()
Check if the error level is enabled.
See
: log4g_logger_is_error_enabled()
, Log4gLevelClass,
log4g_is_trace_enabled()
Returns : |
TRUE if error is enabled, FALSE otherwise.
|
Since 0.1
#define log4g_error(format, args...)
Log an error message.
Example:
log4g_error("example %s message", "ERROR");
See
: log4g_logger_error()
, _log4g_logger_error()
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_logger_error(logger, format, args...)
Log an error message.
Example:
log4g_logger_error(log4g_get_logger("org.gnome.debug"), "example %s message", "ERROR");
See
: log4g_error()
, _log4g_logger_error()
|
A logger object. |
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_is_fatal_enabled()
Check if the fatal level is enabled.
See
: log4g_logger_is_fatal_enabled()
, Log4gLevelClass,
log4g_is_trace_enabled()
Returns : |
TRUE if fatal is enabled, FALSE otherwise.
|
Since 0.1
#define log4g_fatal(format, args...)
Log a fatal message.
Example:
log4g_fatal("example %s message", "FATAL");
See
: log4g_logger_fatal()
, _log4g_logger_fatal()
|
A printf formatted message. |
|
Format parameters. |
Since 0.1
#define log4g_logger_fatal(logger, format, args...)
Log a fatal message.
Example:
log4g_logger_fatal(log4g_get_logger("org.gnome.debug"), "example %s message", "FATAL");
See
: log4g_fatal()
, _log4g_logger_fatal()
|
A logger object. |
|
A printf formatted message. |
|
Format parameters. |
Since 0.1