68#define LogFilename "log.xml"
201 "%t %r %u %v %d %c[%p]: %m/%f/%l/%d\\n %e" }
288 for (i=0; i < (ssize_t) (
sizeof(
LogMap)/
sizeof(*
LogMap)); i++)
298 if (log_info == (
LogInfo *) NULL)
301 "memory allocation failed `%s'",p->
filename);
304 (void) memset(log_info,0,
sizeof(*log_info));
315 "memory allocation failed `%s'",log_info->
name);
352 if (log_info->
file != (FILE *) NULL)
354 (void) fprintf(log_info->
file,
"</log>\n");
355 (void) fclose(log_info->
file);
356 log_info->
file=(FILE *) NULL;
394 return((
const LogInfo *) NULL);
401 if ((name == (
const char *) NULL) || (
LocaleCompare(name,
"*") == 0))
406 while (p != (
const LogInfo *) NULL)
414 "no such element `%s'",name);
449#if defined(__cplusplus) || defined(c_plusplus)
466#if defined(__cplusplus) || defined(c_plusplus)
485 assert(pattern != (
char *) NULL);
487 assert(number_preferences != (
size_t *) NULL);
488 *number_preferences=0;
490 if (p == (
const LogInfo *) NULL)
491 return((
const LogInfo **) NULL);
494 if (preferences == (
const LogInfo **) NULL)
495 return((
const LogInfo **) NULL);
502 for (i=0; p != (
const LogInfo *) NULL; )
510 qsort((
void *) preferences,(
size_t) i,
sizeof(*preferences),
LogInfoCompare);
511 preferences[i]=(
LogInfo *) NULL;
512 *number_preferences=(size_t) i;
544#if defined(__cplusplus) || defined(c_plusplus)
559#if defined(__cplusplus) || defined(c_plusplus)
578 assert(pattern != (
char *) NULL);
580 assert(number_preferences != (
size_t *) NULL);
581 *number_preferences=0;
583 if (p == (
const LogInfo *) NULL)
584 return((
char **) NULL);
587 if (preferences == (
char **) NULL)
588 return((
char **) NULL);
595 for (i=0; p != (
const LogInfo *) NULL; )
603 qsort((
void *) preferences,(
size_t) i,
sizeof(*preferences),
LogCompare);
604 preferences[i]=(
char *) NULL;
605 *number_preferences=(size_t) i;
730#define MegabytesToBytes(value) ((WizardSizeType) (value)*1024*1024)
747 if (file == (
const FILE *) NULL)
750 if (log_info == (
const LogInfo **) NULL)
753 path=(
const char *) NULL;
754 for (i=0; i < (ssize_t) number_aliases; i++)
758 if ((path == (
const char *) NULL) ||
764 if (log_info[i]->path != (
char *) NULL)
765 (
void) fprintf(file,
"\nPath: %s\n\n",log_info[i]->path);
776 if ((log_info[i]->handler_mask & mask) != 0)
782 for (j=(ssize_t) length; j <= 12; j++)
784 (void) fprintf(file,
" Generations Limit Format\n");
785 (void) fprintf(file,
"-----------------------------------------"
786 "--------------------------------------\n");
788 path=log_info[i]->
path;
789 if (log_info[i]->filename != (
char *) NULL)
791 (void) fprintf(file,
"%s",log_info[i]->filename);
792 for (j=(ssize_t) strlen(log_info[i]->filename); j <= 16; j++)
793 (
void) fprintf(file,
" ");
795 (void) fprintf(file,
"%9g ",(
double) log_info[i]->
generations);
796 (void) fprintf(file,
"%8g ",(
double) log_info[i]->
limit);
797 if (log_info[i]->format != (
char *) NULL)
798 (
void) fprintf(file,
"%s",log_info[i]->format);
799 (void) fprintf(file,
"\n");
862 if (p->
file != (FILE *) NULL)
864 (void) fprintf(p->
file,
"</log>\n");
865 (void) fclose(p->
file);
866 p->
file=(FILE *) NULL;
868 if (p->
format != (
char *) NULL)
872 if (p->
path != (
char *) NULL)
879 return((
void *) NULL);
927 const char *module,
const char *function,
const size_t line,
928 const char *domain,
const char *event)
958 seconds=time((time_t *) NULL);
962 if (log_info->
format == (
char *) NULL)
976 " <timestamp>%s</timestamp>\n"
977 " <elapsed-time>%lu:%02lu.%06lu</elapsed-time>\n"
978 " <user-time>%0.3f</user-time>\n"
979 " <process-id>%.20g</process-id>\n"
980 " <thread-id>%.20g</thread-id>\n"
981 " <module>%s</module>\n"
982 " <function>%s</function>\n"
983 " <line>%.20g</line>\n"
984 " <domain>%s</domain>\n"
985 " <event>%s</event>\n"
986 "</entry>",timestamp,(
unsigned long) (elapsed_time/60.0),(
unsigned long)
987 floor(fmod(elapsed_time,60.0)),(
unsigned long) (1000000.0*(elapsed_time-
988 floor(elapsed_time))+0.5),user_time,(
double) getpid(),(double)
996 for (p=log_info->
format; *p !=
'\0'; p++)
1004 if (text == (
char *) NULL)
1005 return((
char *) NULL);
1006 q=text+strlen(text);
1029 if ((*p ==
'\\') && (*(p+1) ==
'r'))
1035 if ((*p ==
'\\') && (*(p+1) ==
'n'))
1104 for (p=module+strlen(module)-1; p > module; p--)
1126 (elapsed_time/60.0),(
unsigned long) floor(fmod(elapsed_time,60.0)),
1127 (
unsigned long) (1000.0*(elapsed_time-floor(elapsed_time))+0.5));
1179 assert(log_info != (
LogInfo *) NULL);
1180 assert(log_info->
filename != (
char *) NULL);
1184 for (p=log_info->
filename; *p !=
'\0'; p++)
1192 if (filename == (
char *) NULL)
1193 return((
char *) NULL);
1194 q=filename+strlen(filename);
1266 const char *function,
const size_t line,
const char *format,
1299#if defined(WIZARDSTOOLKIT_HAVE_VSNPRINTF)
1302 n=vsprintf(event,format,operands);
1307 if (text == (
char *) NULL)
1315 (void) fprintf(stderr,
"%s\n",text);
1316 (void) fflush(stderr);
1320#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
1321 OutputDebugString(text);
1322 OutputDebugString(
"\n");
1327#if defined(WIZARDSTOOLKIT_WINDOWS_SUPPORT)
1336 file_info.st_size=0;
1337 if (log_info->
file != (FILE *) NULL)
1338 (
void) fstat(fileno(log_info->
file),&file_info);
1341 (void) fprintf(log_info->
file,
"</log>\n");
1342 (void) fclose(log_info->
file);
1343 log_info->
file=(FILE *) NULL;
1345 if (log_info->
file == (FILE *) NULL)
1351 if (filename == (
char *) NULL)
1360 if (log_info->
file == (FILE *) NULL)
1367 (void) fprintf(log_info->
file,
"<?xml version=\"1.0\" "
1368 "encoding=\"UTF-8\" standalone=\"yes\"?>\n");
1369 (void) fprintf(log_info->
file,
"<log>\n");
1371 (void) fprintf(log_info->
file,
" <event>%s</event>\n",text);
1372 (void) fflush(log_info->
file);
1376 (void) fprintf(stdout,
"%s\n",text);
1377 (void) fflush(stdout);
1381 (void) fprintf(stderr,
"%s\n",text);
1382 (void) fflush(stderr);
1391 const char *function,
const size_t line,
const char *format,...)
1399 va_start(operands,format);
1436 const char *filename,
const size_t depth,
ExceptionInfo *exception)
1457 if (xml == (
const char *) NULL)
1462 for (q=(
char *) xml; *q !=
'\0'; )
1494 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
1522 if (xml != (
char *) NULL)
1539 if (log_info == (
LogInfo *) NULL)
1541 "memory allocation failed: `%s'");
1542 (void) memset(log_info,0,
sizeof(*log_info));
1548 if (log_info == (
LogInfo *) NULL)
1582 if (log_info->
filename != (
char *) NULL)
1590 if (log_info->
format != (
char *) NULL)
1620 log_info->
limit=(~0UL);
1687 for (p=handlers; p != (
char *) NULL; p=strchr(p,
','))
1689 while ((*p !=
'\0') && ((isspace((
int) ((
unsigned char) *p)) != 0) ||
1704 return(handler_mask);
1789 if (log_info->
format != (
char *) NULL)
1821 if ((name != (
char *) NULL) && (*name !=
'\0'))
WizardExport const char * GetClientName(void)
#define ThrowFatalException(severity, tag)
WizardExport ExceptionInfo * AcquireExceptionInfo(void)
WizardExport ExceptionInfo * DestroyExceptionInfo(ExceptionInfo *exception)
WizardExport WizardBooleanType ThrowWizardException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *format,...)
WizardExport void * GetValueFromLinkedList(LinkedListInfo *list_info, const size_t index)
WizardExport WizardBooleanType IsLinkedListEmpty(const LinkedListInfo *list_info)
WizardExport void ResetLinkedListIterator(LinkedListInfo *list_info)
WizardExport size_t GetNumberOfElementsInLinkedList(const LinkedListInfo *list_info)
WizardExport WizardBooleanType AppendValueToLinkedList(LinkedListInfo *list_info, const void *value)
WizardExport WizardBooleanType InsertValueInLinkedList(LinkedListInfo *list_info, const size_t index, const void *value)
WizardExport void * RemoveElementByValueFromLinkedList(LinkedListInfo *list_info, const void *value)
WizardExport LinkedListInfo * NewLinkedList(const size_t capacity)
WizardExport void * GetNextValueInLinkedList(LinkedListInfo *list_info)
WizardExport LinkedListInfo * DestroyLinkedList(LinkedListInfo *list_info, void *(*relinquish_value)(void *))
WizardExport ssize_t FormatLocaleFile(FILE *file, const char *format,...)
WizardExport ssize_t FormatLocaleString(char *string, const size_t length, const char *format,...)
WizardExport const LogInfo ** GetLogInfoList(const char *pattern, size_t *number_preferences, ExceptionInfo *exception)
WizardBooleanType LogWizardEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
WizardExport WizardBooleanType LogComponentGenesis(void)
WizardExport char ** GetLogList(const char *pattern, size_t *number_preferences, ExceptionInfo *exception)
static char * TranslateEvent(const LogEventType wizard_unused(type), const char *module, const char *function, const size_t line, const char *domain, const char *event)
WizardExport LogEventType SetLogEventMask(const char *events)
WizardExport const char * GetLogName(void)
static LinkedListInfo * AcquireLogCache(const char *filename, ExceptionInfo *exception)
WizardBooleanType LogWizardEventList(const LogEventType type, const char *module, const char *function, const size_t line, const char *format, va_list operands)
static const LogMapInfo LogMap[]
WizardExport void LogComponentTerminus(void)
static LogHandlerType ParseLogHandlers(const char *)
static const HandlerInfo LogHandlers[32]
WizardExport WizardBooleanType ListLogInfo(FILE *file, ExceptionInfo *exception)
WizardExport const char * SetLogName(const char *name)
static int LogInfoCompare(const void *x, const void *y)
static SemaphoreInfo * log_semaphore
WizardExport void SetLogFormat(const char *format)
WizardExport WizardBooleanType IsEventLogging(void)
WizardExport void CloseWizardLog(void)
struct _LogMapInfo LogMapInfo
static int LogCompare(const void *x, const void *y)
static char * TranslateFilename(const LogInfo *log_info)
struct _HandlerInfo HandlerInfo
static void * DestroyLogElement(void *log_info)
static char log_name[WizardPathExtent]
struct _EventInfo EventInfo
static WizardBooleanType LoadLogCache(LinkedListInfo *, const char *, const char *, const size_t, ExceptionInfo *)
static WizardBooleanType IsLogCacheInstantiated(ExceptionInfo *)
WizardExport const LogInfo * GetLogInfo(const char *name, ExceptionInfo *exception)
static LinkedListInfo * log_cache
#define GetWizardModule()
WizardExport void * AcquireWizardMemory(const size_t size)
WizardExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
WizardExport void * RelinquishWizardMemory(void *memory)
WizardExport void * ResizeQuantumMemory(void *memory, const size_t count, const size_t quantum)
WizardExport ssize_t ParseWizardOption(const WizardOption option, const WizardBooleanType list, const char *options)
WizardExport const char * WizardOptionToMnemonic(const WizardOption option, const ssize_t type)
WizardExport void RelinquishSemaphoreInfo(SemaphoreInfo **semaphore_info)
WizardExport SemaphoreInfo * AcquireSemaphoreInfo(void)
WizardExport void LockSemaphoreInfo(SemaphoreInfo *semaphore_info)
WizardExport void UnlockSemaphoreInfo(SemaphoreInfo *semaphore_info)
WizardExport void ActivateSemaphoreInfo(SemaphoreInfo **semaphore_info)
static unsigned long StringToUnsignedLong(const char *value)
WizardExport int LocaleNCompare(const char *p, const char *q, const size_t length)
WizardExport char * DestroyString(char *string)
WizardExport int LocaleCompare(const char *p, const char *q)
WizardExport char * ConstantString(const char *source)
WizardExport size_t ConcatenateWizardString(char *destination, const char *source, const size_t length)
WizardExport char * AcquireString(const char *source)
WizardExport ssize_t FormatWizardTime(const time_t time, const size_t length, char *timestamp)
WizardExport unsigned char * GetStringInfoDatum(const StringInfo *string_info)
WizardExport size_t CopyWizardString(char *destination, const char *source, const size_t length)
WizardExport const char * GetStringInfoPath(const StringInfo *string_info)
SemaphoreInfo * event_semaphore
WizardBooleanType stealth
LogHandlerType handler_mask
const LogEventType event_mask
const LogHandlerType handler_mask
#define DirectorySeparator
static size_t GetWizardThreadSignature(void)
WizardExport double GetUserTime(TimerInfo *timer_info)
WizardExport WizardBooleanType ContinueTimer(TimerInfo *timer_info)
WizardExport TimerInfo * DestroyTimerInfo(TimerInfo *timer_info)
WizardExport double GetElapsedTime(TimerInfo *timer_info)
WizardExport TimerInfo * AcquireTimerInfo(void)
WizardExport WizardBooleanType GlobExpression(const char *expression, const char *pattern, const WizardBooleanType case_insensitive)
WizardExport void GetNextToken(const char *start, const char **end, const size_t extent, char *token)
static FILE * fopen_utf8(const char *path, const char *mode)
WizardExport void GetPathComponent(const char *path, PathType type, char *component)
WizardExport WizardBooleanType IsPathAcessible(const char *path)
#define WizardLibVersionText
unsigned int WizardStatusType
WizardPrivate char * FileToXML(const char *, const size_t)