#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 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" |
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.
[in] | f | File handle to write into. |
[in] | ctx | Logging context or NULL if no context / global context. |
[in] | level | Message's log level setting. |
[in] | fmt | Message 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.
[in] | f | File handle to write into. |
[in] | ctx | Logging context or NULL if no context / global context. |
[in] | level | Message's log level setting. |
[in] | fmt | Message printf() style format string. |
[in] | args | Argument 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, | |||
... | ||||
) |
void aud_log_add_thread_context | ( | GThread * | thread, | |
const gchar * | name | |||
) |
void aud_log_close | ( | void | ) |
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.
[in] | thread | Pointer to a GThread structure of the thread. |
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.
[in] | ctx | Logging context pointer or NULL if no context / global context. |
[in] | level | Message's log level setting. |
[in] | file | Filename (usually obtained through __FILE__ macro) |
[in] | func | Function name (usually obtained through __FUNCTION__ macro) |
[in] | line | Linenumber (usually obtained through __LINE__ macro) |
[in] | fmt | Message printf() style format string. |
[in] | ... | Optional printf() arguments. |
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().
[in] | f | File handle to write into. |
[in] | ctx | Logging context or NULL if no context / global context. |
[in] | level | Message's log level setting. |
[in] | msg | Log 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.
[in] | fmt | Format for time/date string, as described in 'man strftime'. |
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.
[in] | ctx | Logging context or NULL if no context / global context. |
[in] | level | Message's log level setting. |
[in] | fmt | Message printf() style format string. |
[in] | args | Argument structure. |
Definition at line 342 of file log.c.
Referenced by aud_log().
FILE* log_file = NULL [static] |
Global log file handle.
Definition at line 38 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(), aud_log_print_hash(), and aud_logv().
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] |
{ "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().