Audacious $Id:Doxyfile42802007-03-2104:39:00Znenolod$
Defines | Functions | Variables
log.c File Reference
#include "log.h"
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Defines

#define AUD_LOG_CTIME_FMT   "%c"
 Logfile creation timestamp format.
#define AUD_LOG_LTIME_FMT   "%H:%M:%S"
 Logfile entry timestamp format.

Functions

static gchar * aud_log_timestr (const gchar *fmt)
 Create a time/date string based on given format string.
static void aud_log_msg (FILE *f, const gchar *ctx, gint level, const gchar *msg)
 The actual internal function that does the logfile output.
static void aud_do_logv (FILE *f, const gchar *ctx, gint level, const gchar *fmt, va_list args)
 Varargs version of internal non-locked logging function.
static void aud_do_log (FILE *f, const gchar *ctx, gint level, const gchar *fmt,...)
 Internal message logging function that does take the global lock.
gint aud_log_init (const gchar *filename, const gchar *mode, gint level)
 Initialize logging subsystem.
static void aud_log_print_hash (gpointer key, gpointer value, gpointer found)
 Internal helper function for aud_log_close().
void aud_log_close (void)
 Shut down the logging subsystem.
void aud_log_add_thread_context (GThread *thread, const gchar *name)
 Add symbolic name for given thread identifier.
void aud_log_delete_thread_context (GThread *thread)
 Removes identifier for thread, if present.
void aud_logv (const gchar *ctx, gint level, const gchar *fmt, va_list args)
 Write a log entry with variable arguments structure.
void aud_log (const gchar *ctx, gint level, const gchar *fmt,...)
 Write a log entry.
void aud_log_line (const gchar *ctx, gint level, const gchar *file, const gchar *func, gint line, const gchar *fmt,...)
 Write a log entry with file/func/line information.

Variables

static gint log_level = AUD_LOG_INFO
 Global log level setting, this determines what is logged in the logfile.
static FILE * log_file = NULL
 Global log file handle.
static GMutex * log_mutex = NULL
 Mutex for protecting from threaded access.
static GHashTable * log_thread_hash = NULL
 Hashtable that contains registered thread information.
const gchar * log_level_names [AUD_LOG_ALL]
 Descriptive names for different log levels.

Define Documentation

#define AUD_LOG_CTIME_FMT   "%c"

Logfile creation timestamp format.

Definition at line 26 of file log.c.

Referenced by aud_log_close(), and aud_log_init().

#define AUD_LOG_LTIME_FMT   "%H:%M:%S"

Logfile entry timestamp format.

Definition at line 29 of file log.c.

Referenced by aud_log_msg().


Function Documentation

static void aud_do_log ( FILE *  f,
const gchar *  ctx,
gint  level,
const gchar *  fmt,
  ... 
) [static]

Internal message logging function that does take the global lock.

Parameters:
[in]fFile handle to write into.
[in]ctxLogging context or NULL if no context / global context.
[in]levelMessage's log level setting.
[in]fmtMessage printf() style format string.
[in]...Printf() style arguments, if any.

Definition at line 152 of file log.c.

Referenced by aud_log_add_thread_context(), aud_log_close(), aud_log_delete_thread_context(), aud_log_init(), aud_log_print_hash(), and aud_logv().

static void aud_do_logv ( FILE *  f,
const gchar *  ctx,
gint  level,
const gchar *  fmt,
va_list  args 
) [static]

Varargs version of internal non-locked logging function.

Parameters:
[in]fFile handle to write into.
[in]ctxLogging context or NULL if no context / global context.
[in]levelMessage's log level setting.
[in]fmtMessage printf() style format string.
[in]argsArgument structure.

Definition at line 135 of file log.c.

Referenced by aud_do_log(), and aud_logv().

void aud_log ( const gchar *  ctx,
gint  level,
const gchar *  fmt,
  ... 
)

Write a log entry.

Parameters:
[in]ctxLogging context or NULL if no context / global context.
[in]levelMessage's log level setting.
[in]fmtMessage printf() style format string.
[in]...Optional printf() arguments.

Definition at line 364 of file log.c.

void aud_log_add_thread_context ( GThread *  thread,
const gchar *  name 
)

Add symbolic name for given thread identifier.

The identifier will be used in subsequent log messages originating from the thread.

Parameters:
[in]threadPointer to a GThread structure of the thread.
[in]nameString describing the thread.

Definition at line 286 of file log.c.

void aud_log_close ( void  )

Shut down the logging subsystem.

Logfile handle is closed, mutexes and such freed, etc.

Definition at line 241 of file log.c.

void aud_log_delete_thread_context ( GThread *  thread)

Removes identifier for thread, if present.

If thread had not been added in first place (via aud_log_add_thread_context()), a warning is logged instead.

Parameters:
[in]threadPointer to a GThread structure of the thread.

Definition at line 312 of file log.c.

gint aud_log_init ( const gchar *  filename,
const gchar *  mode,
gint  level 
)

Initialize logging subsystem.

Parameters:
[in]filenameFilename for logfile, or NULL to use stderr.
[in]modeOpen mode for fopen().
[in]levelDefault logging level.

Definition at line 169 of file log.c.

void aud_log_line ( const gchar *  ctx,
gint  level,
const gchar *  file,
const gchar *  func,
gint  line,
const gchar *  fmt,
  ... 
)

Write a log entry with file/func/line information.

Parameters:
[in]ctxLogging context pointer or NULL if no context / global context.
[in]levelMessage's log level setting.
[in]fileFilename (usually obtained through __FILE__ macro)
[in]funcFunction name (usually obtained through __FUNCTION__ macro)
[in]lineLinenumber (usually obtained through __LINE__ macro)
[in]fmtMessage printf() style format string.
[in]...Optional printf() arguments.

Definition at line 385 of file log.c.

static void aud_log_msg ( FILE *  f,
const gchar *  ctx,
gint  level,
const gchar *  msg 
) [static]

The actual internal function that does the logfile output.

Entry is prefixed with timestamp information, log level's name (as defined in log_level_names), logging context and the message itself. Linefeeds are optional in format string, they are added automatically for compatibility with g_log().

Parameters:
[in]fFile handle to write into.
[in]ctxLogging context or NULL if no context / global context.
[in]levelMessage's log level setting.
[in]msgLog message string.

Definition at line 91 of file log.c.

Referenced by aud_do_logv(), and aud_log_line().

static void aud_log_print_hash ( gpointer  key,
gpointer  value,
gpointer  found 
) [static]

Internal helper function for aud_log_close().

Definition at line 224 of file log.c.

Referenced by aud_log_close().

static gchar* aud_log_timestr ( const gchar *  fmt) [static]

Create a time/date string based on given format string.

Current adjusted local time is used as timestamp.

Parameters:
[in]fmtFormat for time/date string, as described in 'man strftime'.
Returns:
Newly allocated string, must be freed with g_free().

Definition at line 66 of file log.c.

Referenced by aud_log_close(), aud_log_init(), and aud_log_msg().

void aud_logv ( const gchar *  ctx,
gint  level,
const gchar *  fmt,
va_list  args 
)

Write a log entry with variable arguments structure.

Parameters:
[in]ctxLogging context or NULL if no context / global context.
[in]levelMessage's log level setting.
[in]fmtMessage printf() style format string.
[in]argsArgument structure.

Definition at line 342 of file log.c.

Referenced by aud_log().


Variable Documentation

FILE* log_file = NULL [static]
gint log_level = AUD_LOG_INFO [static]

Global log level setting, this determines what is logged in the logfile.

Anything "above" this level will not be logged.

Definition at line 35 of file log.c.

Referenced by aud_log_init(), and aud_logv().

const gchar* log_level_names[AUD_LOG_ALL]
Initial value:
 {
    "none",
    "FATAL",
    "ERROR",
    "warning",
    "info",
    "DEBUG",
    "DEBUG+",
}

Descriptive names for different log levels.

Definition at line 47 of file log.c.

Referenced by aud_log_msg().

GMutex* log_mutex = NULL [static]

Mutex for protecting from threaded access.

Definition at line 41 of file log.c.

Referenced by aud_log_add_thread_context(), aud_log_close(), aud_log_delete_thread_context(), aud_log_init(), aud_log_line(), and aud_logv().

GHashTable* log_thread_hash = NULL [static]

Hashtable that contains registered thread information.

Definition at line 44 of file log.c.

Referenced by aud_log_add_thread_context(), aud_log_close(), aud_log_delete_thread_context(), aud_log_init(), and aud_log_msg().