InfinotedLog

InfinotedLog — A class to handle logging of messages.

Stability Level

Unstable, unless otherwise indicated

Synopsis

#include <infinoted/infinoted-log.h>

                    InfinotedLog;
struct              InfinotedLogClass;
InfinotedLog *      infinoted_log_new                   (void);
gboolean            infinoted_log_open                  (InfinotedLog *log,
                                                         const gchar *path,
                                                         GError **error);
void                infinoted_log_close                 (InfinotedLog *log);
void                infinoted_log_log                   (InfinotedLog *log,
                                                         guint prio,
                                                         const char *fmt,
                                                         ...);
void                infinoted_log_info                  (InfinotedLog *log,
                                                         const char *fmt,
                                                         ...);
void                infinoted_log_warning               (InfinotedLog *log,
                                                         const char *fmt,
                                                         ...);
void                infinoted_log_error                 (InfinotedLog *log,
                                                         const char *fmt,
                                                         ...);

Object Hierarchy

  GObject
   +----InfinotedLog

Properties

  "file-path"                gchar*                : Read

Signals

  "log-message"                                    : Run First

Description

InfinotedLog manages a message log. Messages can be written to the log either as informational, warning and error messages. If the log was successfully opened, also a glib logging handler is installed which redirects glib logging to this class. Log output is always shown on stderr and, optionally, can be duplicated to a file as well.

Details

InfinotedLog

typedef struct _InfinotedLog InfinotedLog;

InfinotedLog is an opaque data type. You should only access it via the public API functions.


struct InfinotedLogClass

struct InfinotedLogClass {
  void (*log_message)(InfinotedLog* log,
                      guint prio,
                      guint depth,
                      const gchar* text);
};

This structure contains default signal handlers for InfinotedLog.

log_message ()

Default signal handler for the "log-message" signal.

infinoted_log_new ()

InfinotedLog *      infinoted_log_new                   (void);

Creates a new InfinotedLog.

Returns :

A new InfinotedLog. Free with g_object_unref() when no longer needed.

infinoted_log_open ()

gboolean            infinoted_log_open                  (InfinotedLog *log,
                                                         const gchar *path,
                                                         GError **error);

Attempts to open the log file at the given path. If the log file could not be opened the function returns FALSE and error is set. If the log file exists already then new log messages will be appended.

If path is NULL no log file is opened and logging only occurs to stderr.

log :

A InfinotedLog.

path :

The path to the log file to write, or NULL.

error :

Location to store error information, if any, or NULL.

Returns :

TRUE on success, or FALSE otherwise.

infinoted_log_close ()

void                infinoted_log_close                 (InfinotedLog *log);

Closes a InfinotedLog object opened with infinoted_log_open(). After the log was closed it can be opened again with a different file. The log is closed automatically on destruction.

log :

A InfinotedLog.

infinoted_log_log ()

void                infinoted_log_log                   (InfinotedLog *log,
                                                         guint prio,
                                                         const char *fmt,
                                                         ...);

Logs a message with the given priority. The priority is one of LOG_ERR, LOG_WARNING or LOG_INFO. If the server is daemonized, log to syslog, otherwise log to stderr. If a logfile is given in the options when log was created, the logfile is written to as well.

log :

A InfinotedLog.

prio :

Priority of the logged message.

fmt :

A printf-style format string.

... :

Format arguments.

infinoted_log_info ()

void                infinoted_log_info                  (InfinotedLog *log,
                                                         const char *fmt,
                                                         ...);

Logs an info message. If the server is daemonized, log to syslog, otherwise log to stderr. If a logfile is given in the options when log was created, the logfile is written to as well.

log :

A InfinotedLog.

fmt :

A printf-style format string.

... :

Format arguments.

infinoted_log_warning ()

void                infinoted_log_warning               (InfinotedLog *log,
                                                         const char *fmt,
                                                         ...);

Logs a warning message. If the server is daemonized, log to syslog, otherwise log to stderr. If a logfile is given in the options when log was created, the logfile is written to as well.

log :

A InfinotedLog.

fmt :

A printf-style format string.

... :

Format arguments.

infinoted_log_error ()

void                infinoted_log_error                 (InfinotedLog *log,
                                                         const char *fmt,
                                                         ...);

Logs an error message. If the server is daemonized, log to syslog, otherwise log to stderr. If a logfile is given in the options when log was created, the logfile is written to as well.

log :

A InfinotedLog.

fmt :

A printf-style format string.

... :

Format arguments.

Property Details

The "file-path" property

  "file-path"                gchar*                : Read

Path to the log file.

Default value: NULL

Signal Details

The "log-message" signal

void                user_function                      (InfinotedLog *log,
                                                        guint         prio,
                                                        guint         depth,
                                                        gchar        *text,
                                                        gpointer      user_data)      : Run First

This signal is emitted when a new line of log message is written to the log.

log :

The InfinotedLog that is logging a message.

prio :

The priority of the logged message.

depth :

The recursion depth of the logged message.

text :

The logged message text.

user_data :

user data set when the signal handler was connected.