## InfinotedLog

InfinotedLog — A class to handle logging of messages.

## Stability Level

Unstable, unless otherwise indicated

## Functions

InfinotedLog * | infinoted_log_new ()
gboolean | infinoted_log_open ()
void | infinoted_log_close ()
void | infinoted_log_log ()
void | infinoted_log_info ()
void | infinoted_log_warning ()
void | infinoted_log_error ()

## Properties

gchar * | file-path | Read

## Signals

void | log-message | Run First

## Types and Values

struct | InfinotedLog
struct | InfinotedLogClass

## Object Hierarchy

        GObject
        ╰── InfinotedLog

## Includes

    #include <infinoted/infinoted-log.h>

## 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.

## Functions

### infinoted_log_new ()

    InfinotedLog *
    infinoted_log_new (void);

Creates a new InfinotedLog.

[constructor]

#### Returns

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

[transfer full]

### 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.

#### Parameters

log | A InfinotedLog. |
path | The path to the log file to write, or `NULL`. | [type filename][allow-none]
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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

log | A InfinotedLog. |
fmt | A printf-style format string. |
... | Format arguments. |

## Types and Values

### struct InfinotedLog

    struct 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.

#### Members

`log_message` () | Default signal handler for the “log-message” signal. |

## Property Details

### The `“file-path”` property

      “file-path”                gchar *

Path to the log file.

Owner: InfinotedLog

Flags: Read

Default value: NULL

## Signal Details

### The `“log-message”` signal

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

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

#### Parameters

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. |

Flags: Run First