gwenhywfar  4.3.1
Functions | Variables
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>

Go to the source code of this file.

Functions

int GWEN_Logger__CreateMessage (GWEN_LOGGER *lg, GWEN_LOGGER_LEVEL priority, const char *s, GWEN_BUFFER *mbuf)
int GWEN_Logger__Log (GWEN_LOGGER *lg, GWEN_LOGGER_LEVEL priority, const char *s)
void GWEN_Logger_AddLogger (GWEN_LOGGER *oldLogger, GWEN_LOGGER *newLogger)
void GWEN_Logger_Attach (GWEN_LOGGER *lg)
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)
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)
int 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)
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)
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)
void GWEN_LoggerDomain_Add (GWEN_LOGGER_DOMAIN *ld)
void GWEN_LoggerDomain_Del (GWEN_LOGGER_DOMAIN *ld)
GWEN_LOGGER_DOMAIN * GWEN_LoggerDomain_Find (const char *name)
void GWEN_LoggerDomain_free (GWEN_LOGGER_DOMAIN *ld)
GWEN_LOGGER * GWEN_LoggerDomain_GetLogger (const char *name)
GWEN_LOGGER_DOMAIN * GWEN_LoggerDomain_new (const char *name)

Variables

static GWEN_LOGGER_DOMAIN * gwen_loggerdomains = 0

Function Documentation

int GWEN_Logger__CreateMessage ( GWEN_LOGGER *  lg,
GWEN_LOGGER_LEVEL  priority,
const char *  s,
GWEN_BUFFER mbuf 
)
int GWEN_Logger__Log ( GWEN_LOGGER *  lg,
GWEN_LOGGER_LEVEL  priority,
const char *  s 
)
void GWEN_Logger_AddLogger ( GWEN_LOGGER *  oldLogger,
GWEN_LOGGER *  newLogger 
)

Definition at line 195 of file logger.c.

References GWEN_LIST_ADD.

void GWEN_Logger_Attach ( GWEN_LOGGER *  lg)

Definition at line 188 of file logger.c.

void GWEN_Logger_Close ( const char *  logDomain)

Shuts down logging. Automatically disables logging.

Author:
Martin Preuss<martin@libchipcard.de>

Definition at line 281 of file logger.c.

References GWEN_Logger_Log(), GWEN_LoggerDomain_Del(), GWEN_LoggerDomain_free(), GWEN_LoggerDomain_GetLogger(), GWEN_LoggerLevel_Debug, and GWEN_LoggerType_Console.

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 390 of file logger.c.

References GWEN_Logger__CreateMessage(), and GWEN_LoggerDomain_GetLogger().

void GWEN_Logger_Enable ( const char *  logDomain,
int  f 
)

Enables or disables logging.

Author:
Martin Preuss<martin@libchipcard.de>
Parameters:
fif 0 then logging is disabled, otherwise it is enabled

Definition at line 582 of file logger.c.

References GWEN_LoggerDomain_GetLogger().

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 761 of file logger.c.

References GWEN_LoggerDomain_Find().

void GWEN_Logger_free ( GWEN_LOGGER *  lg)

Definition at line 175 of file logger.c.

References GWEN_FREE_OBJECT.

Referenced by GWEN_LoggerDomain_free().

int GWEN_Logger_GetLevel ( const char *  logDomain)

Returns the current log level.

Author:
Martin Preuss<martin@libchipcard.de>

Definition at line 612 of file logger.c.

References GWEN_LoggerDomain_GetLogger().

int GWEN_Logger_IsEnabled ( const char *  logDomain)

Checks whether logging is enabled.

Author:
Martin Preuss<martin@libchipcard.de>
Returns:
0 if disabled, 1 otherwise

Definition at line 592 of file logger.c.

References GWEN_LoggerDomain_GetLogger().

int GWEN_Logger_IsOpen ( const char *  logDomain)

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

Definition at line 300 of file logger.c.

References GWEN_LoggerDomain_Find().

const char* GWEN_Logger_Level2Name ( GWEN_LOGGER_LEVEL  level)
int GWEN_Logger_Log ( const char *  logDomain,
GWEN_LOGGER_LEVEL  priority,
const char *  s 
)

Log a message.

Author:
Martin Preuss<martin@libchipcard.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 531 of file logger.c.

References GWEN_Buffer_AppendByte(), GWEN_Buffer_free(), GWEN_Buffer_GetStart(), GWEN_Buffer_new(), GWEN_Gui_LogHook(), GWEN_Logger__Log(), and GWEN_LoggerDomain_GetLogger().

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

Transforms a log type into an ASCII string.

Definition at line 740 of file logger.c.

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

int GWEN_Logger_ModuleFini ( void  )

Definition at line 80 of file logger.c.

References GWEN_LoggerDomain_Del(), GWEN_LoggerDomain_free(), and gwen_loggerdomains.

Referenced by GWEN_Fini().

int GWEN_Logger_ModuleInit ( void  )
GWEN_LOGGER_LEVEL GWEN_Logger_Name2Level ( const char *  name)

Transforms an ASCII string into the corresponding log type.

Definition at line 724 of file logger.c.

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

GWEN_LOGGER* GWEN_Logger_new ( GWEN_LOGGER_DOMAIN *  domain)

Definition at line 161 of file logger.c.

References GWEN_LoggerLevel_Error, GWEN_LoggerType_Console, and GWEN_NEW_OBJECT.

Referenced by GWEN_LoggerDomain_GetLogger().

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 Preuss<martin@libchipcard.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 210 of file logger.c.

References GWEN_Logger_Log(), GWEN_Logger_SetFilename(), GWEN_Logger_SetIdent(), GWEN_LoggerDomain_GetLogger(), 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().

void GWEN_Logger_SetDefaultLogger ( GWEN_UNUSED GWEN_LOGGER *  lg)

Definition at line 204 of file logger.c.

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 638 of file logger.c.

References GWEN_LoggerDomain_GetLogger().

Referenced by GWEN_Logger_Open().

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 Preuss<martin@libchipcard.de>

Definition at line 623 of file logger.c.

References GWEN_LoggerDomain_GetLogger().

Referenced by GWEN_Logger_Open().

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 Preuss<martin@libchipcard.de>
Parameters:
lmaximum level to be logged

Definition at line 602 of file logger.c.

References GWEN_LoggerDomain_GetLogger().

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

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

Author:
Martin Preuss<martin@libchipcard.de>

Definition at line 653 of file logger.c.

References GWEN_LoggerDomain_GetLogger().

void GWEN_LoggerDomain_Add ( GWEN_LOGGER_DOMAIN *  ld)

Definition at line 128 of file logger.c.

References GWEN_LIST_INSERT, and gwen_loggerdomains.

Referenced by GWEN_LoggerDomain_GetLogger().

void GWEN_LoggerDomain_Del ( GWEN_LOGGER_DOMAIN *  ld)

Definition at line 135 of file logger.c.

References GWEN_LIST_DEL, and gwen_loggerdomains.

Referenced by GWEN_Logger_Close(), and GWEN_Logger_ModuleFini().

GWEN_LOGGER_DOMAIN* GWEN_LoggerDomain_Find ( const char *  name)

Definition at line 112 of file logger.c.

References gwen_loggerdomains.

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

void GWEN_LoggerDomain_free ( GWEN_LOGGER_DOMAIN *  ld)

Definition at line 103 of file logger.c.

References GWEN_FREE_OBJECT, and GWEN_Logger_free().

Referenced by GWEN_Logger_Close(), and GWEN_Logger_ModuleFini().

GWEN_LOGGER* GWEN_LoggerDomain_GetLogger ( const char *  name)
GWEN_LOGGER_DOMAIN* GWEN_LoggerDomain_new ( const char *  name)

Definition at line 92 of file logger.c.

References GWEN_NEW_OBJECT.

Referenced by GWEN_LoggerDomain_GetLogger().


Variable Documentation

GWEN_LOGGER_DOMAIN* gwen_loggerdomains = 0 [static]