42 #include "magick/studio.h" 43 #include "magick/blob.h" 44 #include "magick/client.h" 45 #include "magick/configure.h" 46 #include "magick/exception.h" 47 #include "magick/exception-private.h" 48 #include "magick/hashmap.h" 49 #include "magick/log.h" 50 #include "magick/memory_.h" 51 #include "magick/nt-base-private.h" 52 #include "magick/option.h" 53 #include "magick/semaphore.h" 54 #include "magick/timer.h" 55 #include "magick/string_.h" 56 #include "magick/string-private.h" 57 #include "magick/token.h" 58 #include "magick/thread_.h" 59 #include "magick/thread-private.h" 60 #include "magick/timer-private.h" 61 #include "magick/utility.h" 62 #include "magick/utility-private.h" 63 #include "magick/version.h" 64 #include "magick/xml-tree.h" 65 #include "magick/xml-tree-private.h" 70 #define LogFilename "log.xml" 77 UndefinedHandler = 0x0000,
79 ConsoleHandler = 0x0001,
80 StdoutHandler = 0x0002,
81 StderrHandler = 0x0004,
83 DebugHandler = 0x0010,
84 EventHandler = 0x0020,
85 MethodHandler = 0x0040
166 {
"Console", ConsoleHandler },
167 {
"Debug", DebugHandler },
168 {
"Event", EventHandler },
169 {
"File", FileHandler },
170 {
"None", NoHandler },
171 {
"Stderr", StderrHandler },
172 {
"Stdout", StdoutHandler },
173 {
"", UndefinedHandler },
174 {
"", UndefinedHandler },
175 {
"", UndefinedHandler },
176 {
"", UndefinedHandler },
177 {
"", UndefinedHandler },
178 {
"", UndefinedHandler },
179 {
"", UndefinedHandler },
180 {
"", UndefinedHandler },
181 {
"", UndefinedHandler },
182 {
"", UndefinedHandler },
183 {
"", UndefinedHandler },
184 {
"", UndefinedHandler },
185 {
"", UndefinedHandler },
186 {
"", UndefinedHandler },
187 {
"", UndefinedHandler },
188 {
"", UndefinedHandler },
189 {
"", UndefinedHandler },
190 {
"", UndefinedHandler },
191 {
"", UndefinedHandler },
192 {
"", UndefinedHandler },
193 {
"", UndefinedHandler },
194 {
"", UndefinedHandler },
195 {
"", UndefinedHandler },
196 {
"", UndefinedHandler },
197 {
"", UndefinedHandler }
203 { NoEvents, ConsoleHandler,
"Magick-%g.log",
204 "%t %r %u %v %d %c[%p]: %m/%f/%l/%d\\n %e" }
208 log_name[MaxTextExtent] =
"Magick";
213 static MagickBooleanType
214 event_logging = MagickFalse;
222 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT 223 static LogHandlerType
224 ParseLogHandlers(
const char *) magick_attribute((__pure__));
230 static MagickBooleanType
231 IsLogCacheInstantiated(
ExceptionInfo *) magick_attribute((__pure__));
233 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT 234 static MagickBooleanType
235 LoadLogCache(
LinkedListInfo *,
const char *,
const char *,
const size_t,
280 cache=NewLinkedList(0);
282 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
284 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT 292 options=GetConfigureOptions(filename,exception);
293 option=(
const StringInfo *) GetNextValueInLinkedList(options);
296 status&=LoadLogCache(cache,(
const char *) GetStringInfoDatum(option),
297 GetStringInfoPath(option),0,exception);
298 option=(
const StringInfo *) GetNextValueInLinkedList(options);
300 options=DestroyConfigureOptions(options);
306 for (i=0; i < (ssize_t) (
sizeof(LogMap)/
sizeof(*LogMap)); i++)
315 log_info=(
LogInfo *) AcquireMagickMemory(
sizeof(*log_info));
316 if (log_info == (
LogInfo *) NULL)
318 (void) ThrowMagickException(exception,GetMagickModule(),
319 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",p->filename);
322 (void) memset(log_info,0,
sizeof(*log_info));
323 log_info->path=ConstantString(
"[built-in]");
324 GetTimerInfo((
TimerInfo *) &log_info->timer);
325 log_info->event_mask=p->event_mask;
326 log_info->handler_mask=p->handler_mask;
327 log_info->filename=ConstantString(p->filename);
328 log_info->format=ConstantString(p->format);
329 log_info->signature=MagickCoreSignature;
330 status&=AppendValueToLinkedList(cache,log_info);
331 if (status == MagickFalse)
332 (void) ThrowMagickException(exception,GetMagickModule(),
333 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",log_info->name);
356 MagickExport
void CloseMagickLog(
void)
364 if (IsEventLogging() == MagickFalse)
366 exception=AcquireExceptionInfo();
367 log_info=GetLogInfo(
"*",exception);
368 exception=DestroyExceptionInfo(exception);
369 LockSemaphoreInfo(log_semaphore);
370 if (log_info->file != (FILE *) NULL)
372 (void) FormatLocaleFile(log_info->file,
"</log>\n");
373 (void) fclose(log_info->file);
374 log_info->file=(FILE *) NULL;
376 UnlockSemaphoreInfo(log_semaphore);
397 MagickExport LogEventType GetLogEventMask(
void)
405 exception=AcquireExceptionInfo();
406 log_info=GetLogInfo(
"*",exception);
407 exception=DestroyExceptionInfo(exception);
408 if (log_info == (
const LogInfo *) NULL)
410 return(log_info->event_mask);
444 if (IsLogCacheInstantiated(exception) == MagickFalse)
449 LockSemaphoreInfo(log_semaphore);
450 ResetLinkedListIterator(log_cache);
451 p=(
LogInfo *) GetNextValueInLinkedList(log_cache);
452 if ((name == (
const char *) NULL) || (LocaleCompare(name,
"*") == 0))
454 UnlockSemaphoreInfo(log_semaphore);
459 if (LocaleCompare(name,p->name) == 0)
461 p=(
LogInfo *) GetNextValueInLinkedList(log_cache);
464 (
void) InsertValueInLinkedList(log_cache,0,
465 RemoveElementByValueFromLinkedList(log_cache,p));
466 UnlockSemaphoreInfo(log_semaphore);
497 #if defined(__cplusplus) || defined(c_plusplus) 501 static int LogInfoCompare(
const void *x,
const void *y)
509 if (LocaleCompare((*p)->path,(*q)->path) == 0)
510 return(LocaleCompare((*p)->name,(*q)->name));
511 return(LocaleCompare((*p)->path,(*q)->path));
514 #if defined(__cplusplus) || defined(c_plusplus) 518 MagickExport
const LogInfo **GetLogInfoList(
const char *pattern,
533 assert(pattern != (
char *) NULL);
534 assert(number_preferences != (
size_t *) NULL);
535 if (IsEventLogging() != MagickFalse)
536 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
537 *number_preferences=0;
538 p=GetLogInfo(
"*",exception);
539 if (p == (
const LogInfo *) NULL)
540 return((
const LogInfo **) NULL);
541 preferences=(
const LogInfo **) AcquireQuantumMemory((
size_t)
542 GetNumberOfElementsInLinkedList(log_cache)+1UL,
sizeof(*preferences));
543 if (preferences == (
const LogInfo **) NULL)
544 return((
const LogInfo **) NULL);
548 LockSemaphoreInfo(log_semaphore);
549 ResetLinkedListIterator(log_cache);
550 p=(
const LogInfo *) GetNextValueInLinkedList(log_cache);
551 for (i=0; p != (
const LogInfo *) NULL; )
553 if ((p->stealth == MagickFalse) &&
554 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
556 p=(
const LogInfo *) GetNextValueInLinkedList(log_cache);
558 UnlockSemaphoreInfo(log_semaphore);
559 qsort((
void *) preferences,(
size_t) i,
sizeof(*preferences),LogInfoCompare);
560 preferences[i]=(
LogInfo *) NULL;
561 *number_preferences=(size_t) i;
593 #if defined(__cplusplus) || defined(c_plusplus) 597 static int LogCompare(
const void *x,
const void *y)
605 return(LocaleCompare(*p,*q));
608 #if defined(__cplusplus) || defined(c_plusplus) 612 MagickExport
char **GetLogList(
const char *pattern,
627 assert(pattern != (
char *) NULL);
628 assert(number_preferences != (
size_t *) NULL);
629 if (IsEventLogging() != MagickFalse)
630 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
631 *number_preferences=0;
632 p=GetLogInfo(
"*",exception);
633 if (p == (
const LogInfo *) NULL)
634 return((
char **) NULL);
635 preferences=(
char **) AcquireQuantumMemory((
size_t)
636 GetNumberOfElementsInLinkedList(log_cache)+1UL,
sizeof(*preferences));
637 if (preferences == (
char **) NULL)
638 return((
char **) NULL);
642 LockSemaphoreInfo(log_semaphore);
643 ResetLinkedListIterator(log_cache);
644 p=(
const LogInfo *) GetNextValueInLinkedList(log_cache);
645 for (i=0; p != (
const LogInfo *) NULL; )
647 if ((p->stealth == MagickFalse) &&
648 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
649 preferences[i++]=ConstantString(p->name);
650 p=(
const LogInfo *) GetNextValueInLinkedList(log_cache);
652 UnlockSemaphoreInfo(log_semaphore);
653 qsort((
void *) preferences,(
size_t) i,
sizeof(*preferences),LogCompare);
654 preferences[i]=(
char *) NULL;
655 *number_preferences=(size_t) i;
677 MagickExport
char *GetLogName(
void)
706 static inline void CheckEventLogging(
void)
711 if (IsLinkedListEmpty(log_cache) != MagickFalse)
712 event_logging=MagickFalse;
718 ResetLinkedListIterator(log_cache);
719 p=(
LogInfo *) GetNextValueInLinkedList(log_cache);
720 event_logging=(p != (
LogInfo *) NULL) && (p->event_mask != NoEvents) ?
721 MagickTrue: MagickFalse;
725 static MagickBooleanType IsLogCacheInstantiated(
ExceptionInfo *exception)
730 ActivateSemaphoreInfo(&log_semaphore);
731 LockSemaphoreInfo(log_semaphore);
734 log_cache=AcquireLogCache(LogFilename,exception);
737 UnlockSemaphoreInfo(log_semaphore);
739 return(log_cache != (
LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
761 MagickExport MagickBooleanType IsEventLogging(
void)
763 return(event_logging);
789 MagickExport MagickBooleanType ListLogInfo(FILE *file,
ExceptionInfo *exception)
791 #define MegabytesToBytes(value) ((MagickSizeType) (value)*1024*1024) 808 if (file == (
const FILE *) NULL)
810 log_info=GetLogInfoList(
"*",&number_aliases,exception);
811 if (log_info == (
const LogInfo **) NULL)
814 path=(
const char *) NULL;
815 for (i=0; i < (ssize_t) number_aliases; i++)
817 if (log_info[i]->stealth != MagickFalse)
819 if ((path == (
const char *) NULL) ||
820 (LocaleCompare(path,log_info[i]->path) != 0))
825 if (log_info[i]->path != (
char *) NULL)
826 (
void) FormatLocaleFile(file,
"\nPath: %s\n\n",log_info[i]->path);
828 for (j=0; j < (ssize_t) (8*
sizeof(LogHandlerType)); j++)
833 if (*LogHandlers[j].name ==
'\0')
837 if ((log_info[i]->handler_mask & mask) != 0)
839 (void) FormatLocaleFile(file,
"%s ",LogHandlers[j].name);
840 length+=strlen(LogHandlers[j].name);
843 for (j=(ssize_t) length; j <= 12; j++)
844 (
void) FormatLocaleFile(file,
" ");
845 (void) FormatLocaleFile(file,
" Generations Limit Format\n");
846 (void) FormatLocaleFile(file,
"-----------------------------------------" 847 "--------------------------------------\n");
849 path=log_info[i]->path;
850 if (log_info[i]->filename != (
char *) NULL)
852 (void) FormatLocaleFile(file,
"%s",log_info[i]->filename);
853 for (j=(ssize_t) strlen(log_info[i]->filename); j <= 16; j++)
854 (
void) FormatLocaleFile(file,
" ");
856 (void) FormatLocaleFile(file,
"%9g ",(
double) log_info[i]->generations);
857 (void) FormatLocaleFile(file,
"%8g ",(
double) log_info[i]->limit);
858 if (log_info[i]->format != (
char *) NULL)
859 (
void) FormatLocaleFile(file,
"%s",log_info[i]->format);
860 (void) FormatLocaleFile(file,
"\n");
863 log_info=(
const LogInfo **) RelinquishMagickMemory((
void *) log_info);
885 MagickExport MagickBooleanType LogComponentGenesis(
void)
891 log_semaphore=AllocateSemaphoreInfo();
892 exception=AcquireExceptionInfo();
893 (void) GetLogInfo(
"*",exception);
894 exception=DestroyExceptionInfo(exception);
917 static void *DestroyLogElement(
void *log_info)
923 if (p->file != (FILE *) NULL)
925 (void) FormatLocaleFile(p->file,
"</log>\n");
926 (void) fclose(p->file);
927 p->file=(FILE *) NULL;
929 if (p->format != (
char *) NULL)
930 p->format=DestroyString(p->format);
931 if (p->path != (
char *) NULL)
932 p->path=DestroyString(p->path);
933 if (p->filename != (
char *) NULL)
934 p->filename=DestroyString(p->filename);
936 DestroySemaphoreInfo(&p->event_semaphore);
937 p=(
LogInfo *) RelinquishMagickMemory(p);
938 return((
void *) NULL);
941 MagickExport
void LogComponentTerminus(
void)
944 ActivateSemaphoreInfo(&log_semaphore);
945 LockSemaphoreInfo(log_semaphore);
947 log_cache=DestroyLinkedList(log_cache,DestroyLogElement);
948 event_logging=MagickFalse;
949 UnlockSemaphoreInfo(log_semaphore);
950 DestroySemaphoreInfo(&log_semaphore);
986 static char *TranslateEvent(
const LogEventType magick_unused(type),
987 const char *module,
const char *
function,
const size_t line,
const char *domain,
1015 magick_unreferenced(type);
1017 exception=AcquireExceptionInfo();
1018 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1019 exception=DestroyExceptionInfo(exception);
1020 seconds=GetMagickTime();
1021 elapsed_time=GetElapsedTime(&log_info->timer);
1022 user_time=GetUserTime(&log_info->timer);
1023 text=AcquireString(event);
1024 if (log_info->format == (
char *) NULL)
1026 extent=strlen(event)+MaxTextExtent;
1027 if (LocaleCompare(log_info->format,
"xml") == 0)
1030 timestamp[MaxTextExtent];
1035 (void) FormatMagickTime(seconds,extent,timestamp);
1036 (void) FormatLocaleString(text,extent,
1038 " <timestamp>%s</timestamp>\n" 1039 " <elapsed-time>%lu:%02lu.%06lu</elapsed-time>\n" 1040 " <user-time>%0.3f</user-time>\n" 1041 " <process-id>%.20g</process-id>\n" 1042 " <thread-id>%.20g</thread-id>\n" 1043 " <module>%s</module>\n" 1044 " <function>%s</function>\n" 1045 " <line>%.20g</line>\n" 1046 " <domain>%s</domain>\n" 1047 " <event>%s</event>\n" 1048 "</entry>",timestamp,(
unsigned long) (elapsed_time/60.0),
1049 (
unsigned long) floor(fmod(elapsed_time,60.0)),(
unsigned long)
1050 (1000000.0*(elapsed_time-floor(elapsed_time))+0.5),user_time,
1051 (double) getpid(),(double) GetMagickThreadSignature(),module,
function,
1052 (double) line,domain,event);
1059 for (p=log_info->format; *p !=
'\0'; p++)
1062 if ((
size_t) (q-text+MaxTextExtent) >= extent)
1065 text=(
char *) ResizeQuantumMemory(text,extent,
sizeof(*text));
1066 if (text == (
char *) NULL)
1067 return((
char *) NULL);
1068 q=text+strlen(text);
1091 if ((*p ==
'\\') && (*(p+1) ==
'r'))
1097 if ((*p ==
'\\') && (*(p+1) ==
'n'))
1115 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),extent-(q-text));
1120 q+=(ptrdiff_t) CopyMagickString(q,domain,extent-(q-text));
1125 q+=(ptrdiff_t) CopyMagickString(q,event,extent-(q-text));
1130 q+=(ptrdiff_t) CopyMagickString(q,
function,extent-(q-text));
1135 if (log_info->generations == 0)
1137 (void) CopyMagickString(q,
"0",extent-(q-text));
1141 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(double)
1142 (log_info->generation % log_info->generations));
1147 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(double)
1148 GetMagickThreadSignature());
1153 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(double)
1162 for (p=module+strlen(module)-1; p > module; p--)
1163 if (*p == *DirectorySeparator)
1168 q+=(ptrdiff_t) CopyMagickString(q,p,extent-(q-text));
1173 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),extent-(q-text));
1178 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(double)
1184 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%lu:%02lu.%03lu",
1185 (
unsigned long) (elapsed_time/60.0),(
unsigned long) floor(fmod(
1186 elapsed_time,60.0)),(
unsigned long) (1000.0*(elapsed_time-floor(
1187 elapsed_time))+0.5));
1192 q+=(ptrdiff_t) FormatMagickTime(seconds,extent-(q-text),q);
1197 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%0.3fu",user_time);
1202 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,extent-(q-text));
1222 static char *TranslateFilename(
const LogInfo *log_info)
1239 assert(log_info != (
LogInfo *) NULL);
1240 assert(log_info->filename != (
char *) NULL);
1241 filename=AcquireString((
char *) NULL);
1242 extent=MaxTextExtent;
1244 for (p=log_info->filename; *p !=
'\0'; p++)
1247 if ((
size_t) (q-filename+MaxTextExtent) >= extent)
1250 filename=(
char *) ResizeQuantumMemory(filename,extent,
1252 if (filename == (
char *) NULL)
1253 return((
char *) NULL);
1254 q=filename+strlen(filename);
1283 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),extent-(q-filename));
1288 if (log_info->generations == 0)
1290 (void) CopyMagickString(q,
"0",extent);
1294 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-filename),
"%.20g",
1295 (double) (log_info->generation % log_info->generations));
1300 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),extent-(q-filename));
1305 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-filename),
"%.20g",
1311 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,extent-
1332 MagickExport MagickBooleanType LogMagickEventList(
const LogEventType type,
1333 const char *module,
const char *
function,
const size_t line,
const char *format,
1337 event[MaxTextExtent],
1352 exception=AcquireExceptionInfo();
1353 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1354 exception=DestroyExceptionInfo(exception);
1356 ActivateSemaphoreInfo(&log_info->event_semaphore);
1357 LockSemaphoreInfo(log_info->event_semaphore);
1358 if ((log_info->event_mask & type) == 0)
1360 UnlockSemaphoreInfo(log_info->event_semaphore);
1363 domain=CommandOptionToMnemonic(MagickLogEventOptions,type);
1364 #if defined(MAGICKCORE_HAVE_VSNPRINTF) 1365 n=vsnprintf(event,MaxTextExtent,format,operands);
1367 n=vsprintf(event,format,operands);
1370 event[MaxTextExtent-1]=
'\0';
1371 text=TranslateEvent(type,module,
function,line,domain,event);
1372 if (text == (
char *) NULL)
1374 (void) ContinueTimer((
TimerInfo *) &log_info->timer);
1375 UnlockSemaphoreInfo(log_info->event_semaphore);
1376 return(MagickFalse);
1378 if ((log_info->handler_mask & ConsoleHandler) != 0)
1380 (void) FormatLocaleFile(stderr,
"%s\n",text);
1381 (void) fflush(stderr);
1383 if ((log_info->handler_mask & DebugHandler) != 0)
1385 #if defined(MAGICKCORE_WINDOWS_SUPPORT) 1386 OutputDebugString(text);
1387 OutputDebugString(
"\n");
1390 if ((log_info->handler_mask & EventHandler) != 0)
1392 #if defined(MAGICKCORE_WINDOWS_SUPPORT) 1393 (void) NTReportEvent(text,MagickFalse);
1396 if ((log_info->handler_mask & FileHandler) != 0)
1401 file_info.st_size=0;
1402 if (log_info->file != (FILE *) NULL)
1403 (
void) fstat(fileno(log_info->file),&file_info);
1404 if (file_info.st_size > (MagickOffsetType) (1024*1024*log_info->limit))
1406 (void) FormatLocaleFile(log_info->file,
"</log>\n");
1407 (void) fclose(log_info->file);
1408 log_info->file=(FILE *) NULL;
1410 if (log_info->file == (FILE *) NULL)
1415 filename=TranslateFilename(log_info);
1416 if (filename == (
char *) NULL)
1418 (void) ContinueTimer((
TimerInfo *) &log_info->timer);
1419 UnlockSemaphoreInfo(log_info->event_semaphore);
1420 return(MagickFalse);
1422 log_info->append=IsPathAccessible(filename);
1423 log_info->file=fopen_utf8(filename,
"ab");
1424 filename=(
char *) RelinquishMagickMemory(filename);
1425 if (log_info->file == (FILE *) NULL)
1427 UnlockSemaphoreInfo(log_info->event_semaphore);
1428 return(MagickFalse);
1430 log_info->generation++;
1431 if (log_info->append == MagickFalse)
1432 (void) FormatLocaleFile(log_info->file,
"<?xml version=\"1.0\" " 1433 "encoding=\"UTF-8\" standalone=\"yes\"?>\n");
1434 (void) FormatLocaleFile(log_info->file,
"<log>\n");
1436 (void) FormatLocaleFile(log_info->file,
" <event>%s</event>\n",text);
1437 (void) fflush(log_info->file);
1439 if ((log_info->handler_mask & MethodHandler) != 0)
1441 if (log_info->method != (MagickLogMethod) NULL)
1442 log_info->method(type,text);
1444 if ((log_info->handler_mask & StdoutHandler) != 0)
1446 (void) FormatLocaleFile(stdout,
"%s\n",text);
1447 (void) fflush(stdout);
1449 if ((log_info->handler_mask & StderrHandler) != 0)
1451 (void) FormatLocaleFile(stderr,
"%s\n",text);
1452 (void) fflush(stderr);
1454 text=(
char *) RelinquishMagickMemory(text);
1455 (void) ContinueTimer((
TimerInfo *) &log_info->timer);
1456 UnlockSemaphoreInfo(log_info->event_semaphore);
1460 MagickExport MagickBooleanType LogMagickEvent(
const LogEventType type,
1461 const char *module,
const char *
function,
const size_t line,
1462 const char *format,...)
1470 if (IsEventLogging() == MagickFalse)
1471 return(MagickFalse);
1472 va_start(operands,format);
1473 status=LogMagickEventList(type,module,
function,line,format,operands);
1478 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT 1509 static MagickBooleanType LoadLogCache(
LinkedListInfo *cache,
const char *xml,
1510 const char *filename,
const size_t depth,
ExceptionInfo *exception)
1513 keyword[MaxTextExtent],
1531 if (xml == (
const char *) NULL)
1532 return(MagickFalse);
1534 token=AcquireString(xml);
1535 extent=strlen(token)+MaxTextExtent;
1536 for (q=(
const char *) xml; *q !=
'\0'; )
1541 (void) GetNextToken(q,&q,extent,token);
1544 (void) CopyMagickString(keyword,token,MaxTextExtent);
1545 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
1550 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
1551 (
void) GetNextToken(q,&q,extent,token);
1554 if (LocaleNCompare(keyword,
"<!--",4) == 0)
1559 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
1560 (void) GetNextToken(q,&q,extent,token);
1563 if (LocaleCompare(keyword,
"<include") == 0)
1568 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
1570 (void) CopyMagickString(keyword,token,MaxTextExtent);
1571 (void) GetNextToken(q,&q,extent,token);
1574 (void) GetNextToken(q,&q,extent,token);
1575 if (LocaleCompare(keyword,
"file") == 0)
1577 if (depth > MagickMaxRecursionDepth)
1578 (void) ThrowMagickException(exception,GetMagickModule(),
1579 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
1583 path[MaxTextExtent],
1586 GetPathComponent(filename,HeadPath,path);
1588 (void) ConcatenateMagickString(path,DirectorySeparator,
1590 if (*token == *DirectorySeparator)
1591 (void) CopyMagickString(path,token,MaxTextExtent);
1593 (
void) ConcatenateMagickString(path,token,MaxTextExtent);
1594 xml=FileToXML(path,~0UL);
1595 if (xml != (
char *) NULL)
1597 status&=LoadLogCache(cache,xml,path,depth+1,
1599 xml=DestroyString(xml);
1606 if (LocaleCompare(keyword,
"<logmap>") == 0)
1611 log_info=(
LogInfo *) AcquireMagickMemory(
sizeof(*log_info));
1612 if (log_info == (
LogInfo *) NULL)
1613 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
1614 (void) memset(log_info,0,
sizeof(*log_info));
1615 log_info->path=ConstantString(filename);
1616 GetTimerInfo((
TimerInfo *) &log_info->timer);
1617 log_info->signature=MagickCoreSignature;
1620 if (log_info == (
LogInfo *) NULL)
1622 if (LocaleCompare(keyword,
"</logmap>") == 0)
1624 status=AppendValueToLinkedList(cache,log_info);
1625 if (status == MagickFalse)
1626 (void) ThrowMagickException(exception,GetMagickModule(),
1627 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",filename);
1631 (void) GetNextToken(q,(
const char **) NULL,extent,token);
1634 (void) GetNextToken(q,&q,extent,token);
1635 (void) GetNextToken(q,&q,extent,token);
1641 if (LocaleCompare((
char *) keyword,
"events") == 0)
1643 log_info->event_mask=(LogEventType) (log_info->event_mask |
1644 ParseCommandOption(MagickLogEventOptions,MagickTrue,token));
1652 if (LocaleCompare((
char *) keyword,
"filename") == 0)
1654 if (log_info->filename != (
char *) NULL)
1655 log_info->filename=(
char *)
1656 RelinquishMagickMemory(log_info->filename);
1657 log_info->filename=ConstantString(token);
1660 if (LocaleCompare((
char *) keyword,
"format") == 0)
1662 if (log_info->format != (
char *) NULL)
1663 log_info->format=(
char *)
1664 RelinquishMagickMemory(log_info->format);
1665 log_info->format=ConstantString(token);
1673 if (LocaleCompare((
char *) keyword,
"generations") == 0)
1675 if (LocaleCompare(token,
"unlimited") == 0)
1677 log_info->generations=(~0UL);
1680 log_info->generations=StringToUnsignedLong(token);
1688 if (LocaleCompare((
char *) keyword,
"limit") == 0)
1690 if (LocaleCompare(token,
"unlimited") == 0)
1692 log_info->limit=(~0UL);
1695 log_info->limit=StringToUnsignedLong(token);
1703 if (LocaleCompare((
char *) keyword,
"output") == 0)
1705 log_info->handler_mask=(LogHandlerType)
1706 (log_info->handler_mask | ParseLogHandlers(token));
1715 token=DestroyString(token);
1717 return(MagickFalse);
1718 return(status != 0 ? MagickTrue : MagickFalse);
1722 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT 1746 static LogHandlerType ParseLogHandlers(
const char *handlers)
1760 handler_mask=NoHandler;
1761 for (p=handlers; p != (
char *) NULL; p=strchr(p,
','))
1763 while ((*p !=
'\0') && ((isspace((
int) ((
unsigned char) *p)) != 0) ||
1766 for (i=0; *LogHandlers[i].name !=
'\0'; i++)
1768 length=strlen(LogHandlers[i].name);
1769 if (LocaleNCompare(p,LogHandlers[i].name,length) == 0)
1771 handler_mask=(LogHandlerType) (handler_mask | LogHandlers[i].handler);
1775 if (*LogHandlers[i].name ==
'\0')
1776 return(UndefinedHandler);
1778 return(handler_mask);
1806 MagickExport LogEventType SetLogEventMask(
const char *events)
1817 exception=AcquireExceptionInfo();
1818 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1819 exception=DestroyExceptionInfo(exception);
1820 option=ParseCommandOption(MagickLogEventOptions,MagickTrue,events);
1821 LockSemaphoreInfo(log_semaphore);
1822 log_info=(
LogInfo *) GetValueFromLinkedList(log_cache,0);
1823 log_info->event_mask=(LogEventType) option;
1825 log_info->event_mask=UndefinedEvents;
1826 CheckEventLogging();
1827 UnlockSemaphoreInfo(log_semaphore);
1828 return(log_info->event_mask);
1853 MagickExport
void SetLogFormat(
const char *format)
1861 exception=AcquireExceptionInfo();
1862 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1863 exception=DestroyExceptionInfo(exception);
1864 LockSemaphoreInfo(log_semaphore);
1865 if (log_info->format != (
char *) NULL)
1866 log_info->format=DestroyString(log_info->format);
1867 log_info->format=ConstantString(format);
1868 UnlockSemaphoreInfo(log_semaphore);
1894 MagickExport
void SetLogMethod(MagickLogMethod method)
1902 exception=AcquireExceptionInfo();
1903 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1904 exception=DestroyExceptionInfo(exception);
1905 LockSemaphoreInfo(log_semaphore);
1906 log_info=(
LogInfo *) GetValueFromLinkedList(log_cache,0);
1907 log_info->handler_mask=(LogHandlerType) (log_info->handler_mask |
1909 log_info->method=method;
1910 UnlockSemaphoreInfo(log_semaphore);
1937 MagickExport
char *SetLogName(
const char *name)
1939 if ((name != (
char *) NULL) && (*name !=
'\0'))
1940 (void) CopyMagickString(log_name,name,MaxTextExtent);