gwenhywfar 5.14.1
logger.c File Reference
#include <gwenhywfar/gwenhywfarapi.h>
#include <gwenhywfar/misc.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/gui.h>
#include "logger_p.h"
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <time.h>
Include dependency graph for logger.c:

Go to the source code of this file.

Functions

static int _createMessage (GWEN_LOGGER *lg, GWEN_LOGGER_LEVEL priority, const char *s, GWEN_BUFFER *mbuf)
static void _loggerDomain_Add (GWEN_LOGGER_DOMAIN *ld)
static void _loggerDomain_Del (GWEN_LOGGER_DOMAIN *ld)
static GWEN_LOGGER_DOMAIN * _loggerDomain_Find (const char *name)
static void _loggerDomain_free (GWEN_LOGGER_DOMAIN *ld)
static GWEN_LOGGER * _loggerDomain_GetLogger (const char *name)
static GWEN_LOGGER_DOMAIN * _loggerDomain_new (const char *name)
static int _logMessage (GWEN_LOGGER *lg, GWEN_LOGGER_LEVEL priority, const char *s)
static int _logMessageToConsole (GWEN_LOGGER *lg, GWEN_LOGGER_LEVEL priority, const char *s)
static int _logMessageToFile (GWEN_LOGGER *lg, GWEN_LOGGER_LEVEL priority, const char *s)
static int _logMessageToFunction (GWEN_LOGGER *lg, GWEN_LOGGER_LEVEL priority, const char *s)
GWENHYWFAR_API void GWEN_Logger_AddLogger (GWEN_LOGGER *oldLogger, GWEN_LOGGER *newLogger) GWEN_DEPRECATED
void GWEN_Logger_Close (const char *logDomain)
int GWEN_Logger_CreateLogMessage (const char *logDomain, GWEN_LOGGER_LEVEL priority, const char *s, GWEN_BUFFER *mbuf)
void GWEN_Logger_Enable (const char *logDomain, int f)
int GWEN_Logger_Exists (const char *logDomain)
static void GWEN_Logger_free (GWEN_LOGGER *lg)
int GWEN_Logger_GetLevel (const char *logDomain)
int GWEN_Logger_IsEnabled (const char *logDomain)
int GWEN_Logger_IsOpen (const char *logDomain)
const char * GWEN_Logger_Level2Name (GWEN_LOGGER_LEVEL level)
void GWEN_Logger_Log (const char *logDomain, GWEN_LOGGER_LEVEL priority, const char *s)
const char * GWEN_Logger_Logtype2Name (GWEN_LOGGER_LOGTYPE lt)
int GWEN_Logger_ModuleFini (void)
int GWEN_Logger_ModuleInit (void)
GWEN_LOGGER_LEVEL GWEN_Logger_Name2Level (const char *name)
GWEN_LOGGER_LOGTYPE GWEN_Logger_Name2Logtype (const char *name)
static GWEN_LOGGER * GWEN_Logger_new (GWEN_LOGGER_DOMAIN *domain)
int GWEN_Logger_Open (const char *logDomain, const char *ident, const char *file, GWEN_LOGGER_LOGTYPE logtype, GWEN_LOGGER_FACILITY facility)
GWENHYWFAR_API void GWEN_Logger_SetDefaultLogger (GWEN_LOGGER *lg) GWEN_DEPRECATED
void GWEN_Logger_SetDefaultLogger (GWEN_UNUSED GWEN_LOGGER *lg)
void GWEN_Logger_SetFilename (const char *logDomain, const char *name)
void GWEN_Logger_SetIdent (const char *logDomain, const char *id)
void GWEN_Logger_SetLevel (const char *logDomain, GWEN_LOGGER_LEVEL l)
GWEN_LOGGERFUNCTIONLOG GWEN_Logger_SetLogFunction (const char *logDomain, GWEN_LOGGERFUNCTIONLOG fn)

Variables

static GWEN_LOGGER_DOMAIN * gwen_loggerdomains =NULL

Function Documentation

◆ _createMessage()

int _createMessage ( GWEN_LOGGER * lg,
GWEN_LOGGER_LEVEL priority,
const char * s,
GWEN_BUFFER * mbuf )
static

Definition at line 828 of file logger.c.

References GWEN_Buffer_AppendArgs(), GWEN_Buffer_AppendByte(), and GWEN_Buffer_AppendString().

Referenced by _logMessageToConsole(), _logMessageToFile(), _logMessageToFunction(), and GWEN_Logger_CreateLogMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _loggerDomain_Add()

void _loggerDomain_Add ( GWEN_LOGGER_DOMAIN * ld)
static

Definition at line 186 of file logger.c.

References GWEN_LIST_INSERT, and gwen_loggerdomains.

Referenced by _loggerDomain_GetLogger().

Here is the caller graph for this function:

◆ _loggerDomain_Del()

void _loggerDomain_Del ( GWEN_LOGGER_DOMAIN * ld)
static

Definition at line 194 of file logger.c.

References GWEN_LIST_DEL, and gwen_loggerdomains.

Referenced by GWEN_Logger_Close(), and GWEN_Logger_ModuleFini().

Here is the caller graph for this function:

◆ _loggerDomain_Find()

GWEN_LOGGER_DOMAIN * _loggerDomain_Find ( const char * name)
static

Definition at line 169 of file logger.c.

References gwen_loggerdomains.

Referenced by _loggerDomain_GetLogger(), GWEN_Logger_Exists(), and GWEN_Logger_IsOpen().

Here is the caller graph for this function:

◆ _loggerDomain_free()

void _loggerDomain_free ( GWEN_LOGGER_DOMAIN * ld)
static

Definition at line 159 of file logger.c.

References GWEN_FREE_OBJECT, and GWEN_Logger_free().

Referenced by GWEN_Logger_Close(), and GWEN_Logger_ModuleFini().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _loggerDomain_GetLogger()

GWEN_LOGGER * _loggerDomain_GetLogger ( const char * name)
static

◆ _loggerDomain_new()

GWEN_LOGGER_DOMAIN * _loggerDomain_new ( const char * name)
static

Definition at line 147 of file logger.c.

References GWEN_NEW_OBJECT.

Referenced by _loggerDomain_GetLogger().

Here is the caller graph for this function:

◆ _logMessage()

int _logMessage ( GWEN_LOGGER * lg,
GWEN_LOGGER_LEVEL priority,
const char * s )
static

Definition at line 667 of file logger.c.

References _logMessageToConsole(), _logMessageToFile(), _logMessageToFunction(), GWEN_LoggerType_Console, GWEN_LoggerType_File, GWEN_LoggerType_Function, GWEN_LoggerType_Syslog, and GWEN_LoggerType_Unknown.

Referenced by GWEN_Logger_Log().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _logMessageToConsole()

int _logMessageToConsole ( GWEN_LOGGER * lg,
GWEN_LOGGER_LEVEL priority,
const char * s )
static

Definition at line 736 of file logger.c.

References _createMessage(), GWEN_Buffer_free(), GWEN_Buffer_GetStart(), and GWEN_Buffer_new().

Referenced by _logMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _logMessageToFile()

int _logMessageToFile ( GWEN_LOGGER * lg,
GWEN_LOGGER_LEVEL priority,
const char * s )
static

Definition at line 695 of file logger.c.

References _createMessage(), GWEN_Buffer_free(), GWEN_Buffer_GetStart(), GWEN_Buffer_GetUsedBytes(), GWEN_Buffer_new(), GWEN_ERROR_IO, and GWEN_LoggerType_Console.

Referenced by _logMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _logMessageToFunction()

int _logMessageToFunction ( GWEN_LOGGER * lg,
GWEN_LOGGER_LEVEL priority,
const char * s )
static

Definition at line 799 of file logger.c.

References _createMessage(), GWEN_Buffer_free(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), and GWEN_ERROR_NOT_IMPLEMENTED.

Referenced by _logMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Logger_AddLogger()

void GWEN_Logger_AddLogger ( GWEN_LOGGER * oldLogger,
GWEN_LOGGER * newLogger )

Adds a logger to the given one. So if the old logger is to log something then the newly added logger will log the same message as well. The new logger must already be open (via GWEN_Logger_Open).

Definition at line 261 of file logger.c.

References GWEN_LIST_ADD.

◆ GWEN_Logger_Close()

void GWEN_Logger_Close ( const char * logDomain)

Shuts down logging. Automatically disables logging.

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de

Definition at line 357 of file logger.c.

References _loggerDomain_Del(), _loggerDomain_free(), _loggerDomain_GetLogger(), GWEN_Logger_Log(), GWEN_LoggerLevel_Debug, and GWEN_LoggerType_Console.

Here is the call graph for this function:

◆ GWEN_Logger_CreateLogMessage()

int GWEN_Logger_CreateLogMessage ( const char * logDomain,
GWEN_LOGGER_LEVEL priority,
const char * s,
GWEN_BUFFER * mbuf )

This function can be used to generate log messages from within log hooks.

Definition at line 389 of file logger.c.

References _createMessage(), and _loggerDomain_GetLogger().

Referenced by _logHook().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Logger_Enable()

void GWEN_Logger_Enable ( const char * logDomain,
int f )

Enables or disables logging.

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de
Parameters
fif 0 then logging is disabled, otherwise it is enabled

Definition at line 450 of file logger.c.

References _loggerDomain_GetLogger().

Here is the call graph for this function:

◆ GWEN_Logger_Exists()

int GWEN_Logger_Exists ( const char * logDomain)

Checks whether a given log domain already exists.

Returns
1 if it exists, 0 otherwise

Definition at line 656 of file logger.c.

References _loggerDomain_Find().

Here is the call graph for this function:

◆ GWEN_Logger_free()

void GWEN_Logger_free ( GWEN_LOGGER * lg)
static

Definition at line 237 of file logger.c.

References GWEN_FREE_OBJECT.

Referenced by _loggerDomain_free().

Here is the caller graph for this function:

◆ GWEN_Logger_GetLevel()

int GWEN_Logger_GetLevel ( const char * logDomain)

Returns the current log level.

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de

Definition at line 483 of file logger.c.

References _loggerDomain_GetLogger().

Referenced by _recvPacket(), GWEN_SyncIo_Http_ReadHeader(), GWEN_SyncIo_Http_ReadStatus(), GWEN_SyncIo_Http_WriteCommand(), and GWEN_SyncIo_Http_WriteHeader().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Logger_IsEnabled()

int GWEN_Logger_IsEnabled ( const char * logDomain)

Checks whether logging is enabled.

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de
Returns
0 if disabled, 1 otherwise

Definition at line 461 of file logger.c.

References _loggerDomain_GetLogger().

Here is the call graph for this function:

◆ GWEN_Logger_IsOpen()

int GWEN_Logger_IsOpen ( const char * logDomain)

Checks whether the logger for the given logDomain is open or not.

Definition at line 377 of file logger.c.

References _loggerDomain_Find().

Here is the call graph for this function:

◆ GWEN_Logger_Level2Name()

const char * GWEN_Logger_Level2Name ( GWEN_LOGGER_LEVEL level)

◆ GWEN_Logger_Log()

void GWEN_Logger_Log ( const char * logDomain,
GWEN_LOGGER_LEVEL priority,
const char * s )

Log a message.

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de
Parameters
prioritypriority of the message
sstring to log. This string is cut at all occurences of a newline character thus splitting it into multiple log lines if necessary

Definition at line 401 of file logger.c.

References _loggerDomain_GetLogger(), _logMessage(), GWEN_Buffer_AppendByte(), GWEN_Buffer_free(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), and GWEN_Gui_LogHook().

Referenced by GWEN_Logger_Close(), GWEN_Logger_Open(), and GWEN_Text_LogString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Logger_Logtype2Name()

const char * GWEN_Logger_Logtype2Name ( GWEN_LOGGER_LOGTYPE lt)

Transforms a log type into an ASCII string.

Definition at line 629 of file logger.c.

References GWEN_LoggerType_Console, GWEN_LoggerType_File, GWEN_LoggerType_Function, GWEN_LoggerType_Syslog, and GWEN_LoggerType_Unknown.

◆ GWEN_Logger_ModuleFini()

int GWEN_Logger_ModuleFini ( void )

Definition at line 134 of file logger.c.

References _loggerDomain_Del(), _loggerDomain_free(), and gwen_loggerdomains.

Referenced by GWEN_Fini().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Logger_ModuleInit()

int GWEN_Logger_ModuleInit ( void )

Definition at line 116 of file logger.c.

References GWEN_LOGDOMAIN, GWEN_Logger_Name2Level(), GWEN_Logger_Open(), GWEN_Logger_SetLevel(), GWEN_LoggerFacility_User, GWEN_LoggerLevel_Unknown, GWEN_LoggerLevel_Warning, and GWEN_LoggerType_Console.

Referenced by GWEN_Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Logger_Name2Level()

GWEN_LOGGER_LEVEL GWEN_Logger_Name2Level ( const char * name)

◆ GWEN_Logger_Name2Logtype()

GWEN_LOGGER_LOGTYPE GWEN_Logger_Name2Logtype ( const char * name)

Transforms an ASCII string into the corresponding log type.

Definition at line 612 of file logger.c.

References GWEN_LoggerType_Console, GWEN_LoggerType_File, GWEN_LoggerType_Function, GWEN_LoggerType_Syslog, and GWEN_LoggerType_Unknown.

Referenced by checkArgs().

Here is the caller graph for this function:

◆ GWEN_Logger_new()

GWEN_LOGGER * GWEN_Logger_new ( GWEN_LOGGER_DOMAIN * domain)
static

Definition at line 222 of file logger.c.

References GWEN_LoggerLevel_Error, GWEN_LoggerType_Console, and GWEN_NEW_OBJECT.

Referenced by _loggerDomain_GetLogger().

Here is the caller graph for this function:

◆ GWEN_Logger_Open()

int GWEN_Logger_Open ( const char * logDomain,
const char * ident,
const char * file,
GWEN_LOGGER_LOGTYPE logtype,
GWEN_LOGGER_FACILITY facility )

Sets up logging. It automatically enables logging.

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de
Parameters
identthis string is prepended to each message logged to identify the logging program
filename of the file to log to. If this is empty and syslog is available, then all messages are logged via syslog. If syslog is not available, all messages are logged to the console.
logtypehow to log (via syslog, to a file, to the console etc)
facilitywhat kind of program the log message comes from

Definition at line 281 of file logger.c.

References _loggerDomain_GetLogger(), GWEN_Logger_Log(), GWEN_Logger_SetFilename(), GWEN_Logger_SetIdent(), GWEN_LoggerFacility_Auth, GWEN_LoggerFacility_Daemon, GWEN_LoggerFacility_Mail, GWEN_LoggerFacility_News, GWEN_LoggerFacility_Unknown, GWEN_LoggerFacility_User, GWEN_LoggerLevel_Debug, GWEN_LoggerType_Console, GWEN_LoggerType_File, and GWEN_LoggerType_Syslog.

Referenced by GWEN_Logger_ModuleInit(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Logger_SetDefaultLogger() [1/2]

GWENHYWFAR_API void GWEN_Logger_SetDefaultLogger ( GWEN_LOGGER * lg)

DEPRECATED. Only sets the new default logger if it not already is set or if the new default logger is NULL. You must call GWEN_Logger_Open on that logger prior to calling this function.

References GWEN_DEPRECATED, and GWENHYWFAR_API.

◆ GWEN_Logger_SetDefaultLogger() [2/2]

void GWEN_Logger_SetDefaultLogger ( GWEN_UNUSED GWEN_LOGGER * lg)

Definition at line 273 of file logger.c.

References GWEN_UNUSED.

◆ GWEN_Logger_SetFilename()

void GWEN_Logger_SetFilename ( const char * logDomain,
const char * name )

Set the name of the file to be used when logging to a file.

Definition at line 511 of file logger.c.

References _loggerDomain_GetLogger().

Referenced by GWEN_Logger_Open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Logger_SetIdent()

void GWEN_Logger_SetIdent ( const char * logDomain,
const char * id )

Set ident string. This string is prepended to every log message and should contain the name of the running program.

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de

Definition at line 495 of file logger.c.

References _loggerDomain_GetLogger().

Referenced by GWEN_Logger_Open().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Logger_SetLevel()

void GWEN_Logger_SetLevel ( const char * logDomain,
GWEN_LOGGER_LEVEL l )

Sets the logger level. All messages with a priority up to the given one will be logged, all others will not.

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de
Parameters
lmaximum level to be logged

Definition at line 472 of file logger.c.

References _loggerDomain_GetLogger().

Referenced by GWEN_Logger_ModuleInit(), main(), test1(), test1(), test10(), test2(), test3(), test8(), and test9().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GWEN_Logger_SetLogFunction()

GWEN_LOGGERFUNCTIONLOG GWEN_Logger_SetLogFunction ( const char * logDomain,
GWEN_LOGGERFUNCTIONLOG fn )

Set logging function. This function is used to log messages in mode LoggerTypeFunction.

Author
Martin Preussmarti.nosp@m.n@li.nosp@m.bchip.nosp@m.card.nosp@m..de

Definition at line 527 of file logger.c.

References _loggerDomain_GetLogger().

Here is the call graph for this function:

Variable Documentation

◆ gwen_loggerdomains

GWEN_LOGGER_DOMAIN* gwen_loggerdomains =NULL
static