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 if (log_info == (
LogInfo *) NULL)
371 LockSemaphoreInfo(log_semaphore);
372 if (log_info->file != (FILE *) NULL)
374 (void) FormatLocaleFile(log_info->file,
"</log>\n");
375 (void) fclose(log_info->file);
376 log_info->file=(FILE *) NULL;
378 UnlockSemaphoreInfo(log_semaphore);
399 MagickExport LogEventType GetLogEventMask(
void)
407 exception=AcquireExceptionInfo();
408 log_info=GetLogInfo(
"*",exception);
409 exception=DestroyExceptionInfo(exception);
410 if (log_info == (
const LogInfo *) NULL)
412 return(log_info->event_mask);
446 if (IsLogCacheInstantiated(exception) == MagickFalse)
451 LockSemaphoreInfo(log_semaphore);
452 ResetLinkedListIterator(log_cache);
453 p=(
LogInfo *) GetNextValueInLinkedList(log_cache);
454 if ((name == (
const char *) NULL) || (LocaleCompare(name,
"*") == 0))
456 UnlockSemaphoreInfo(log_semaphore);
461 if (LocaleCompare(name,p->name) == 0)
463 p=(
LogInfo *) GetNextValueInLinkedList(log_cache);
466 (
void) InsertValueInLinkedList(log_cache,0,
467 RemoveElementByValueFromLinkedList(log_cache,p));
468 UnlockSemaphoreInfo(log_semaphore);
499 #if defined(__cplusplus) || defined(c_plusplus)
503 static int LogInfoCompare(
const void *x,
const void *y)
511 if (LocaleCompare((*p)->path,(*q)->path) == 0)
512 return(LocaleCompare((*p)->name,(*q)->name));
513 return(LocaleCompare((*p)->path,(*q)->path));
516 #if defined(__cplusplus) || defined(c_plusplus)
520 MagickExport
const LogInfo **GetLogInfoList(
const char *pattern,
535 assert(pattern != (
char *) NULL);
536 assert(number_preferences != (
size_t *) NULL);
537 if (IsEventLogging() != MagickFalse)
538 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
539 *number_preferences=0;
540 p=GetLogInfo(
"*",exception);
541 if (p == (
const LogInfo *) NULL)
542 return((
const LogInfo **) NULL);
543 preferences=(
const LogInfo **) AcquireQuantumMemory((
size_t)
544 GetNumberOfElementsInLinkedList(log_cache)+1UL,
sizeof(*preferences));
545 if (preferences == (
const LogInfo **) NULL)
546 return((
const LogInfo **) NULL);
550 LockSemaphoreInfo(log_semaphore);
551 ResetLinkedListIterator(log_cache);
552 p=(
const LogInfo *) GetNextValueInLinkedList(log_cache);
553 for (i=0; p != (
const LogInfo *) NULL; )
555 if ((p->stealth == MagickFalse) &&
556 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
558 p=(
const LogInfo *) GetNextValueInLinkedList(log_cache);
560 UnlockSemaphoreInfo(log_semaphore);
561 qsort((
void *) preferences,(
size_t) i,
sizeof(*preferences),LogInfoCompare);
562 preferences[i]=(
LogInfo *) NULL;
563 *number_preferences=(size_t) i;
595 #if defined(__cplusplus) || defined(c_plusplus)
599 static int LogCompare(
const void *x,
const void *y)
607 return(LocaleCompare(*p,*q));
610 #if defined(__cplusplus) || defined(c_plusplus)
614 MagickExport
char **GetLogList(
const char *pattern,
629 assert(pattern != (
char *) NULL);
630 assert(number_preferences != (
size_t *) NULL);
631 if (IsEventLogging() != MagickFalse)
632 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
633 *number_preferences=0;
634 p=GetLogInfo(
"*",exception);
635 if (p == (
const LogInfo *) NULL)
636 return((
char **) NULL);
637 preferences=(
char **) AcquireQuantumMemory((
size_t)
638 GetNumberOfElementsInLinkedList(log_cache)+1UL,
sizeof(*preferences));
639 if (preferences == (
char **) NULL)
640 return((
char **) NULL);
644 LockSemaphoreInfo(log_semaphore);
645 ResetLinkedListIterator(log_cache);
646 p=(
const LogInfo *) GetNextValueInLinkedList(log_cache);
647 for (i=0; p != (
const LogInfo *) NULL; )
649 if ((p->stealth == MagickFalse) &&
650 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
651 preferences[i++]=ConstantString(p->name);
652 p=(
const LogInfo *) GetNextValueInLinkedList(log_cache);
654 UnlockSemaphoreInfo(log_semaphore);
655 qsort((
void *) preferences,(
size_t) i,
sizeof(*preferences),LogCompare);
656 preferences[i]=(
char *) NULL;
657 *number_preferences=(size_t) i;
679 MagickExport
char *GetLogName(
void)
708 static inline void CheckEventLogging(
void)
713 if (IsLinkedListEmpty(log_cache) != MagickFalse)
714 event_logging=MagickFalse;
720 ResetLinkedListIterator(log_cache);
721 p=(
LogInfo *) GetNextValueInLinkedList(log_cache);
722 event_logging=(p != (
LogInfo *) NULL) && (p->event_mask != NoEvents) ?
723 MagickTrue: MagickFalse;
727 static MagickBooleanType IsLogCacheInstantiated(
ExceptionInfo *exception)
732 ActivateSemaphoreInfo(&log_semaphore);
733 LockSemaphoreInfo(log_semaphore);
736 log_cache=AcquireLogCache(LogFilename,exception);
739 UnlockSemaphoreInfo(log_semaphore);
741 return(log_cache != (
LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
763 MagickExport MagickBooleanType IsEventLogging(
void)
765 return(event_logging);
791 MagickExport MagickBooleanType ListLogInfo(FILE *file,
ExceptionInfo *exception)
793 #define MegabytesToBytes(value) ((MagickSizeType) (value)*1024*1024)
810 if (file == (
const FILE *) NULL)
812 log_info=GetLogInfoList(
"*",&number_aliases,exception);
813 if (log_info == (
const LogInfo **) NULL)
816 path=(
const char *) NULL;
817 for (i=0; i < (ssize_t) number_aliases; i++)
819 if (log_info[i]->stealth != MagickFalse)
821 if ((path == (
const char *) NULL) ||
822 (LocaleCompare(path,log_info[i]->path) != 0))
827 if (log_info[i]->path != (
char *) NULL)
828 (
void) FormatLocaleFile(file,
"\nPath: %s\n\n",log_info[i]->path);
830 for (j=0; j < (ssize_t) (8*
sizeof(LogHandlerType)); j++)
835 if (*LogHandlers[j].name ==
'\0')
839 if ((log_info[i]->handler_mask & mask) != 0)
841 (void) FormatLocaleFile(file,
"%s ",LogHandlers[j].name);
842 length+=strlen(LogHandlers[j].name);
845 for (j=(ssize_t) length; j <= 12; j++)
846 (
void) FormatLocaleFile(file,
" ");
847 (void) FormatLocaleFile(file,
" Generations Limit Format\n");
848 (void) FormatLocaleFile(file,
"-----------------------------------------"
849 "--------------------------------------\n");
851 path=log_info[i]->path;
852 if (log_info[i]->filename != (
char *) NULL)
854 (void) FormatLocaleFile(file,
"%s",log_info[i]->filename);
855 for (j=(ssize_t) strlen(log_info[i]->filename); j <= 16; j++)
856 (
void) FormatLocaleFile(file,
" ");
858 (void) FormatLocaleFile(file,
"%9g ",(
double) log_info[i]->generations);
859 (void) FormatLocaleFile(file,
"%8g ",(
double) log_info[i]->limit);
860 if (log_info[i]->format != (
char *) NULL)
861 (
void) FormatLocaleFile(file,
"%s",log_info[i]->format);
862 (void) FormatLocaleFile(file,
"\n");
865 log_info=(
const LogInfo **) RelinquishMagickMemory((
void *) log_info);
887 MagickExport MagickBooleanType LogComponentGenesis(
void)
893 log_semaphore=AllocateSemaphoreInfo();
894 exception=AcquireExceptionInfo();
895 (void) GetLogInfo(
"*",exception);
896 exception=DestroyExceptionInfo(exception);
919 static void *DestroyLogElement(
void *log_info)
925 if (p->file != (FILE *) NULL)
927 (void) FormatLocaleFile(p->file,
"</log>\n");
928 (void) fclose(p->file);
929 p->file=(FILE *) NULL;
931 if (p->format != (
char *) NULL)
932 p->format=DestroyString(p->format);
933 if (p->path != (
char *) NULL)
934 p->path=DestroyString(p->path);
935 if (p->filename != (
char *) NULL)
936 p->filename=DestroyString(p->filename);
938 DestroySemaphoreInfo(&p->event_semaphore);
939 p=(
LogInfo *) RelinquishMagickMemory(p);
940 return((
void *) NULL);
943 MagickExport
void LogComponentTerminus(
void)
946 ActivateSemaphoreInfo(&log_semaphore);
947 LockSemaphoreInfo(log_semaphore);
949 log_cache=DestroyLinkedList(log_cache,DestroyLogElement);
950 event_logging=MagickFalse;
951 UnlockSemaphoreInfo(log_semaphore);
952 DestroySemaphoreInfo(&log_semaphore);
988 static char *TranslateEvent(
const LogEventType magick_unused(type),
989 const char *module,
const char *
function,
const size_t line,
const char *domain,
1017 magick_unreferenced(type);
1019 exception=AcquireExceptionInfo();
1020 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1021 exception=DestroyExceptionInfo(exception);
1022 text=AcquireString(event);
1023 if (log_info == (
LogInfo *) NULL)
1025 seconds=GetMagickTime();
1026 elapsed_time=GetElapsedTime(&log_info->timer);
1027 user_time=GetUserTime(&log_info->timer);
1028 if (log_info->format == (
char *) NULL)
1030 extent=strlen(event)+MaxTextExtent;
1031 if (LocaleCompare(log_info->format,
"xml") == 0)
1034 timestamp[MaxTextExtent];
1039 (void) FormatMagickTime(seconds,extent,timestamp);
1040 (void) FormatLocaleString(text,extent,
1042 " <timestamp>%s</timestamp>\n"
1043 " <elapsed-time>%lu:%02lu.%06lu</elapsed-time>\n"
1044 " <user-time>%0.3f</user-time>\n"
1045 " <process-id>%.20g</process-id>\n"
1046 " <thread-id>%.20g</thread-id>\n"
1047 " <module>%s</module>\n"
1048 " <function>%s</function>\n"
1049 " <line>%.20g</line>\n"
1050 " <domain>%s</domain>\n"
1051 " <event>%s</event>\n"
1052 "</entry>",timestamp,(
unsigned long) (elapsed_time/60.0),
1053 (
unsigned long) floor(fmod(elapsed_time,60.0)),(
unsigned long)
1054 (1000000.0*(elapsed_time-floor(elapsed_time))+0.5),user_time,
1055 (
double) getpid(),(double) GetMagickThreadSignature(),module,
function,
1056 (double) line,domain,event);
1063 for (p=log_info->format; *p !=
'\0'; p++)
1066 if ((
size_t) (q-text+MaxTextExtent) >= extent)
1069 text=(
char *) ResizeQuantumMemory(text,extent,
sizeof(*text));
1070 if (text == (
char *) NULL)
1071 return((
char *) NULL);
1072 q=text+strlen(text);
1095 if ((*p ==
'\\') && (*(p+1) ==
'r'))
1101 if ((*p ==
'\\') && (*(p+1) ==
'n'))
1119 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),extent-(q-text));
1124 q+=(ptrdiff_t) CopyMagickString(q,domain,extent-(q-text));
1129 q+=(ptrdiff_t) CopyMagickString(q,event,extent-(q-text));
1134 q+=(ptrdiff_t) CopyMagickString(q,
function,extent-(q-text));
1139 if (log_info->generations == 0)
1141 (void) CopyMagickString(q,
"0",extent-(q-text));
1145 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(double)
1146 (log_info->generation % log_info->generations));
1151 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(double)
1152 GetMagickThreadSignature());
1157 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(double)
1166 for (p=module+strlen(module)-1; p > module; p--)
1167 if (*p == *DirectorySeparator)
1172 q+=(ptrdiff_t) CopyMagickString(q,p,extent-(q-text));
1177 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),extent-(q-text));
1182 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(double)
1188 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%lu:%02lu.%03lu",
1189 (
unsigned long) (elapsed_time/60.0),(
unsigned long) floor(fmod(
1190 elapsed_time,60.0)),(
unsigned long) (1000.0*(elapsed_time-floor(
1191 elapsed_time))+0.5));
1196 q+=(ptrdiff_t) FormatMagickTime(seconds,extent-(q-text),q);
1201 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%0.3fu",user_time);
1206 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,extent-(q-text));
1226 static char *TranslateFilename(
const LogInfo *log_info)
1243 assert(log_info != (
LogInfo *) NULL);
1244 assert(log_info->filename != (
char *) NULL);
1245 filename=AcquireString((
char *) NULL);
1246 extent=MaxTextExtent;
1248 for (p=log_info->filename; *p !=
'\0'; p++)
1251 if ((
size_t) (q-filename+MaxTextExtent) >= extent)
1254 filename=(
char *) ResizeQuantumMemory(filename,extent,
1256 if (filename == (
char *) NULL)
1257 return((
char *) NULL);
1258 q=filename+strlen(filename);
1287 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),extent-(q-filename));
1292 if (log_info->generations == 0)
1294 (void) CopyMagickString(q,
"0",extent);
1298 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-filename),
"%.20g",
1299 (double) (log_info->generation % log_info->generations));
1304 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),extent-(q-filename));
1309 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-filename),
"%.20g",
1315 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,extent-
1336 MagickExport MagickBooleanType LogMagickEventList(
const LogEventType type,
1337 const char *module,
const char *
function,
const size_t line,
const char *format,
1341 event[MaxTextExtent],
1356 exception=AcquireExceptionInfo();
1357 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1358 exception=DestroyExceptionInfo(exception);
1359 if (log_info == (
LogInfo *) NULL)
1360 return(MagickFalse);
1362 ActivateSemaphoreInfo(&log_info->event_semaphore);
1363 LockSemaphoreInfo(log_info->event_semaphore);
1364 if ((log_info->event_mask & type) == 0)
1366 UnlockSemaphoreInfo(log_info->event_semaphore);
1369 domain=CommandOptionToMnemonic(MagickLogEventOptions,type);
1370 n=vsnprintf(event,MaxTextExtent,format,operands);
1372 event[MaxTextExtent-1]=
'\0';
1373 text=TranslateEvent(type,module,
function,line,domain,event);
1374 if (text == (
char *) NULL)
1376 (void) ContinueTimer((
TimerInfo *) &log_info->timer);
1377 UnlockSemaphoreInfo(log_info->event_semaphore);
1378 return(MagickFalse);
1380 if ((log_info->handler_mask & ConsoleHandler) != 0)
1382 (void) FormatLocaleFile(stderr,
"%s\n",text);
1383 (void) fflush(stderr);
1385 if ((log_info->handler_mask & DebugHandler) != 0)
1387 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1388 OutputDebugString(text);
1389 OutputDebugString(
"\n");
1392 if ((log_info->handler_mask & EventHandler) != 0)
1394 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1395 (void) NTReportEvent(text,MagickFalse);
1398 if ((log_info->handler_mask & FileHandler) != 0)
1403 file_info.st_size=0;
1404 if (log_info->file != (FILE *) NULL)
1405 (
void) fstat(fileno(log_info->file),&file_info);
1406 if (file_info.st_size > (MagickOffsetType) (1024*1024*log_info->limit))
1408 (void) FormatLocaleFile(log_info->file,
"</log>\n");
1409 (void) fclose(log_info->file);
1410 log_info->file=(FILE *) NULL;
1412 if (log_info->file == (FILE *) NULL)
1417 filename=TranslateFilename(log_info);
1418 if (filename == (
char *) NULL)
1420 (void) ContinueTimer((
TimerInfo *) &log_info->timer);
1421 UnlockSemaphoreInfo(log_info->event_semaphore);
1422 return(MagickFalse);
1424 log_info->append=IsPathAccessible(filename);
1425 log_info->file=fopen_utf8(filename,
"ab");
1426 filename=(
char *) RelinquishMagickMemory(filename);
1427 if (log_info->file == (FILE *) NULL)
1429 UnlockSemaphoreInfo(log_info->event_semaphore);
1430 return(MagickFalse);
1432 log_info->generation++;
1433 if (log_info->append == MagickFalse)
1434 (void) FormatLocaleFile(log_info->file,
"<?xml version=\"1.0\" "
1435 "encoding=\"UTF-8\" standalone=\"yes\"?>\n");
1436 (void) FormatLocaleFile(log_info->file,
"<log>\n");
1438 (void) FormatLocaleFile(log_info->file,
" <event>%s</event>\n",text);
1439 (void) fflush(log_info->file);
1441 if ((log_info->handler_mask & MethodHandler) != 0)
1443 if (log_info->method != (MagickLogMethod) NULL)
1444 log_info->method(type,text);
1446 if ((log_info->handler_mask & StdoutHandler) != 0)
1448 (void) FormatLocaleFile(stdout,
"%s\n",text);
1449 (void) fflush(stdout);
1451 if ((log_info->handler_mask & StderrHandler) != 0)
1453 (void) FormatLocaleFile(stderr,
"%s\n",text);
1454 (void) fflush(stderr);
1456 text=(
char *) RelinquishMagickMemory(text);
1457 (void) ContinueTimer((
TimerInfo *) &log_info->timer);
1458 UnlockSemaphoreInfo(log_info->event_semaphore);
1462 MagickExport MagickBooleanType LogMagickEvent(
const LogEventType type,
1463 const char *module,
const char *
function,
const size_t line,
1464 const char *format,...)
1472 if (IsEventLogging() == MagickFalse)
1473 return(MagickFalse);
1474 va_start(operands,format);
1475 status=LogMagickEventList(type,module,
function,line,format,operands);
1480 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
1511 static MagickBooleanType LoadLogCache(
LinkedListInfo *cache,
const char *xml,
1512 const char *filename,
const size_t depth,
ExceptionInfo *exception)
1515 keyword[MaxTextExtent],
1533 if (xml == (
const char *) NULL)
1534 return(MagickFalse);
1536 token=AcquireString(xml);
1537 extent=strlen(token)+MaxTextExtent;
1538 for (q=(
const char *) xml; *q !=
'\0'; )
1543 (void) GetNextToken(q,&q,extent,token);
1546 (void) CopyMagickString(keyword,token,MaxTextExtent);
1547 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
1552 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
1553 (
void) GetNextToken(q,&q,extent,token);
1556 if (LocaleNCompare(keyword,
"<!--",4) == 0)
1561 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
1562 (void) GetNextToken(q,&q,extent,token);
1565 if (LocaleCompare(keyword,
"<include") == 0)
1570 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
1572 (void) CopyMagickString(keyword,token,MaxTextExtent);
1573 (void) GetNextToken(q,&q,extent,token);
1576 (void) GetNextToken(q,&q,extent,token);
1577 if (LocaleCompare(keyword,
"file") == 0)
1579 if (depth > MagickMaxRecursionDepth)
1580 (void) ThrowMagickException(exception,GetMagickModule(),
1581 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
1585 path[MaxTextExtent],
1588 GetPathComponent(filename,HeadPath,path);
1590 (void) ConcatenateMagickString(path,DirectorySeparator,
1592 if (*token == *DirectorySeparator)
1593 (void) CopyMagickString(path,token,MaxTextExtent);
1595 (
void) ConcatenateMagickString(path,token,MaxTextExtent);
1596 xml=FileToXML(path,~0UL);
1597 if (xml != (
char *) NULL)
1599 status&=LoadLogCache(cache,xml,path,depth+1,
1601 xml=DestroyString(xml);
1608 if (LocaleCompare(keyword,
"<logmap>") == 0)
1613 log_info=(
LogInfo *) AcquireMagickMemory(
sizeof(*log_info));
1614 if (log_info == (
LogInfo *) NULL)
1615 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
1616 (void) memset(log_info,0,
sizeof(*log_info));
1617 log_info->path=ConstantString(filename);
1618 GetTimerInfo((
TimerInfo *) &log_info->timer);
1619 log_info->signature=MagickCoreSignature;
1622 if (log_info == (
LogInfo *) NULL)
1624 if (LocaleCompare(keyword,
"</logmap>") == 0)
1626 status=AppendValueToLinkedList(cache,log_info);
1627 if (status == MagickFalse)
1628 (void) ThrowMagickException(exception,GetMagickModule(),
1629 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",filename);
1633 (void) GetNextToken(q,(
const char **) NULL,extent,token);
1636 (void) GetNextToken(q,&q,extent,token);
1637 (void) GetNextToken(q,&q,extent,token);
1643 if (LocaleCompare((
char *) keyword,
"events") == 0)
1645 log_info->event_mask=(LogEventType) (log_info->event_mask |
1646 ParseCommandOption(MagickLogEventOptions,MagickTrue,token));
1654 if (LocaleCompare((
char *) keyword,
"filename") == 0)
1656 if (log_info->filename != (
char *) NULL)
1657 log_info->filename=(
char *)
1658 RelinquishMagickMemory(log_info->filename);
1659 log_info->filename=ConstantString(token);
1662 if (LocaleCompare((
char *) keyword,
"format") == 0)
1664 if (log_info->format != (
char *) NULL)
1665 log_info->format=(
char *)
1666 RelinquishMagickMemory(log_info->format);
1667 log_info->format=ConstantString(token);
1675 if (LocaleCompare((
char *) keyword,
"generations") == 0)
1677 if (LocaleCompare(token,
"unlimited") == 0)
1679 log_info->generations=(~0UL);
1682 log_info->generations=StringToUnsignedLong(token);
1690 if (LocaleCompare((
char *) keyword,
"limit") == 0)
1692 if (LocaleCompare(token,
"unlimited") == 0)
1694 log_info->limit=(~0UL);
1697 log_info->limit=StringToUnsignedLong(token);
1705 if (LocaleCompare((
char *) keyword,
"output") == 0)
1707 log_info->handler_mask=(LogHandlerType)
1708 (log_info->handler_mask | ParseLogHandlers(token));
1717 token=DestroyString(token);
1719 return(MagickFalse);
1720 return(status != 0 ? MagickTrue : MagickFalse);
1724 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
1748 static LogHandlerType ParseLogHandlers(
const char *handlers)
1762 handler_mask=NoHandler;
1763 for (p=handlers; p != (
char *) NULL; p=strchr(p,
','))
1765 while ((*p !=
'\0') && ((isspace((
int) ((
unsigned char) *p)) != 0) ||
1768 for (i=0; *LogHandlers[i].name !=
'\0'; i++)
1770 length=strlen(LogHandlers[i].name);
1771 if (LocaleNCompare(p,LogHandlers[i].name,length) == 0)
1773 handler_mask=(LogHandlerType) (handler_mask | LogHandlers[i].handler);
1777 if (*LogHandlers[i].name ==
'\0')
1778 return(UndefinedHandler);
1780 return(handler_mask);
1808 MagickExport LogEventType SetLogEventMask(
const char *events)
1819 exception=AcquireExceptionInfo();
1820 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1821 exception=DestroyExceptionInfo(exception);
1822 if (log_info == (
LogInfo *) NULL)
1824 option=ParseCommandOption(MagickLogEventOptions,MagickTrue,events);
1825 LockSemaphoreInfo(log_semaphore);
1826 log_info=(
LogInfo *) GetValueFromLinkedList(log_cache,0);
1827 if (log_info == (
LogInfo *) NULL)
1829 UnlockSemaphoreInfo(log_semaphore);
1832 log_info->event_mask=(LogEventType) option;
1834 log_info->event_mask=UndefinedEvents;
1835 CheckEventLogging();
1836 UnlockSemaphoreInfo(log_semaphore);
1837 return(log_info->event_mask);
1862 MagickExport
void SetLogFormat(
const char *format)
1870 exception=AcquireExceptionInfo();
1871 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1872 exception=DestroyExceptionInfo(exception);
1873 if (log_info == (
LogInfo *) NULL)
1875 LockSemaphoreInfo(log_semaphore);
1876 if (log_info->format != (
char *) NULL)
1877 log_info->format=DestroyString(log_info->format);
1878 log_info->format=ConstantString(format);
1879 UnlockSemaphoreInfo(log_semaphore);
1905 MagickExport
void SetLogMethod(MagickLogMethod method)
1913 exception=AcquireExceptionInfo();
1914 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1915 exception=DestroyExceptionInfo(exception);
1916 if (log_info == (
LogInfo *) NULL)
1918 LockSemaphoreInfo(log_semaphore);
1919 log_info=(
LogInfo *) GetValueFromLinkedList(log_cache,0);
1920 if (log_info == (
LogInfo *) NULL)
1922 UnlockSemaphoreInfo(log_semaphore);
1925 log_info->handler_mask=(LogHandlerType) (log_info->handler_mask |
1927 log_info->method=method;
1928 UnlockSemaphoreInfo(log_semaphore);
1955 MagickExport
char *SetLogName(
const char *name)
1957 if ((name != (
char *) NULL) && (*name !=
'\0'))
1958 (void) CopyMagickString(log_name,name,MaxTextExtent);