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";
213static MagickBooleanType
214 event_logging = MagickFalse;
222#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
224 ParseLogHandlers(
const char *) magick_attribute((__pure__));
230static MagickBooleanType
231 IsLogCacheInstantiated(
ExceptionInfo *) magick_attribute((__pure__));
233#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
234static 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);
356MagickExport
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);
397MagickExport 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)
501static 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)
518MagickExport
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)
597static int LogCompare(
const void *x,
const void *y)
605 return(LocaleCompare(*p,*q));
608#if defined(__cplusplus) || defined(c_plusplus)
612MagickExport
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;
677MagickExport
char *GetLogName(
void)
706static 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;
725static 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);
761MagickExport MagickBooleanType IsEventLogging(
void)
763 return(event_logging);
789MagickExport 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);
885MagickExport MagickBooleanType LogComponentGenesis(
void)
891 log_semaphore=AllocateSemaphoreInfo();
892 exception=AcquireExceptionInfo();
893 (void) GetLogInfo(
"*",exception);
894 exception=DestroyExceptionInfo(exception);
917static 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);
941MagickExport
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);
986static 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)
1064 extent+=MaxTextExtent;
1065 text=(
char *) ResizeQuantumMemory(text,extent+MaxTextExtent,
1067 if (text == (
char *) NULL)
1068 return((
char *) NULL);
1069 q=text+strlen(text);
1092 if ((*p ==
'\\') && (*(p+1) ==
'r'))
1098 if ((*p ==
'\\') && (*(p+1) ==
'n'))
1116 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),extent);
1121 q+=(ptrdiff_t) CopyMagickString(q,domain,extent);
1126 q+=(ptrdiff_t) CopyMagickString(q,event,extent);
1131 q+=(ptrdiff_t) CopyMagickString(q,function,extent);
1136 if (log_info->generations == 0)
1138 (void) CopyMagickString(q,
"0",extent);
1142 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%.20g",(
double) (log_info->generation %
1143 log_info->generations));
1148 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%.20g",(
double)
1149 GetMagickThreadSignature());
1154 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%.20g",(
double) line);
1162 for (p=module+strlen(module)-1; p > module; p--)
1163 if (*p == *DirectorySeparator)
1168 q+=(ptrdiff_t) CopyMagickString(q,p,extent);
1173 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),extent);
1178 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%.20g",(
double) getpid());
1183 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%lu:%02lu.%03lu",(
unsigned long)
1184 (elapsed_time/60.0),(
unsigned long) floor(fmod(elapsed_time,60.0)),
1185 (
unsigned long) (1000.0*(elapsed_time-floor(elapsed_time))+0.5));
1190 q+=(ptrdiff_t) FormatMagickTime(seconds,extent,q);
1195 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%0.3fu",user_time);
1200 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,extent);
1220static char *TranslateFilename(
const LogInfo *log_info)
1237 assert(log_info != (
LogInfo *) NULL);
1238 assert(log_info->filename != (
char *) NULL);
1239 filename=AcquireString((
char *) NULL);
1240 extent=MaxTextExtent;
1242 for (p=log_info->filename; *p !=
'\0'; p++)
1245 if ((
size_t) (q-filename+MaxTextExtent) >= extent)
1247 extent+=MaxTextExtent;
1248 filename=(
char *) ResizeQuantumMemory(filename,extent+MaxTextExtent,
1250 if (filename == (
char *) NULL)
1251 return((
char *) NULL);
1252 q=filename+strlen(filename);
1281 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),extent);
1286 if (log_info->generations == 0)
1288 (void) CopyMagickString(q,
"0",extent);
1292 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%.20g",(
double) (log_info->generation %
1293 log_info->generations));
1298 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),extent);
1303 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%.20g",(
double) getpid());
1308 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,extent);
1328MagickExport MagickBooleanType LogMagickEventList(
const LogEventType type,
1329 const char *module,
const char *function,
const size_t line,
const char *format,
1333 event[MaxTextExtent],
1348 exception=AcquireExceptionInfo();
1349 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1350 exception=DestroyExceptionInfo(exception);
1352 ActivateSemaphoreInfo(&log_info->event_semaphore);
1353 LockSemaphoreInfo(log_info->event_semaphore);
1354 if ((log_info->event_mask & type) == 0)
1356 UnlockSemaphoreInfo(log_info->event_semaphore);
1359 domain=CommandOptionToMnemonic(MagickLogEventOptions,type);
1360#if defined(MAGICKCORE_HAVE_VSNPRINTF)
1361 n=vsnprintf(event,MaxTextExtent,format,operands);
1363 n=vsprintf(event,format,operands);
1366 event[MaxTextExtent-1]=
'\0';
1367 text=TranslateEvent(type,module,function,line,domain,event);
1368 if (text == (
char *) NULL)
1370 (void) ContinueTimer((
TimerInfo *) &log_info->timer);
1371 UnlockSemaphoreInfo(log_info->event_semaphore);
1372 return(MagickFalse);
1374 if ((log_info->handler_mask & ConsoleHandler) != 0)
1376 (void) FormatLocaleFile(stderr,
"%s\n",text);
1377 (void) fflush(stderr);
1379 if ((log_info->handler_mask & DebugHandler) != 0)
1381#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1382 OutputDebugString(text);
1383 OutputDebugString(
"\n");
1386 if ((log_info->handler_mask & EventHandler) != 0)
1388#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1389 (void) NTReportEvent(text,MagickFalse);
1392 if ((log_info->handler_mask & FileHandler) != 0)
1397 file_info.st_size=0;
1398 if (log_info->file != (FILE *) NULL)
1399 (void) fstat(fileno(log_info->file),&file_info);
1400 if (file_info.st_size > (MagickOffsetType) (1024*1024*log_info->limit))
1402 (void) FormatLocaleFile(log_info->file,
"</log>\n");
1403 (void) fclose(log_info->file);
1404 log_info->file=(FILE *) NULL;
1406 if (log_info->file == (FILE *) NULL)
1411 filename=TranslateFilename(log_info);
1412 if (filename == (
char *) NULL)
1414 (void) ContinueTimer((
TimerInfo *) &log_info->timer);
1415 UnlockSemaphoreInfo(log_info->event_semaphore);
1416 return(MagickFalse);
1418 log_info->append=IsPathAccessible(filename);
1419 log_info->file=fopen_utf8(filename,
"ab");
1420 filename=(
char *) RelinquishMagickMemory(filename);
1421 if (log_info->file == (FILE *) NULL)
1423 UnlockSemaphoreInfo(log_info->event_semaphore);
1424 return(MagickFalse);
1426 log_info->generation++;
1427 if (log_info->append == MagickFalse)
1428 (void) FormatLocaleFile(log_info->file,
"<?xml version=\"1.0\" "
1429 "encoding=\"UTF-8\" standalone=\"yes\"?>\n");
1430 (void) FormatLocaleFile(log_info->file,
"<log>\n");
1432 (void) FormatLocaleFile(log_info->file,
" <event>%s</event>\n",text);
1433 (void) fflush(log_info->file);
1435 if ((log_info->handler_mask & MethodHandler) != 0)
1437 if (log_info->method != (MagickLogMethod) NULL)
1438 log_info->method(type,text);
1440 if ((log_info->handler_mask & StdoutHandler) != 0)
1442 (void) FormatLocaleFile(stdout,
"%s\n",text);
1443 (void) fflush(stdout);
1445 if ((log_info->handler_mask & StderrHandler) != 0)
1447 (void) FormatLocaleFile(stderr,
"%s\n",text);
1448 (void) fflush(stderr);
1450 text=(
char *) RelinquishMagickMemory(text);
1451 (void) ContinueTimer((
TimerInfo *) &log_info->timer);
1452 UnlockSemaphoreInfo(log_info->event_semaphore);
1456MagickExport MagickBooleanType LogMagickEvent(
const LogEventType type,
1457 const char *module,
const char *function,
const size_t line,
1458 const char *format,...)
1466 if (IsEventLogging() == MagickFalse)
1467 return(MagickFalse);
1468 va_start(operands,format);
1469 status=LogMagickEventList(type,module,function,line,format,operands);
1474#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
1505static MagickBooleanType LoadLogCache(
LinkedListInfo *cache,
const char *xml,
1506 const char *filename,
const size_t depth,
ExceptionInfo *exception)
1509 keyword[MaxTextExtent],
1527 if (xml == (
const char *) NULL)
1528 return(MagickFalse);
1530 token=AcquireString(xml);
1531 extent=strlen(token)+MaxTextExtent;
1532 for (q=(
const char *) xml; *q !=
'\0'; )
1537 (void) GetNextToken(q,&q,extent,token);
1540 (void) CopyMagickString(keyword,token,MaxTextExtent);
1541 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
1546 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
1547 (void) GetNextToken(q,&q,extent,token);
1550 if (LocaleNCompare(keyword,
"<!--",4) == 0)
1555 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
1556 (void) GetNextToken(q,&q,extent,token);
1559 if (LocaleCompare(keyword,
"<include") == 0)
1564 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
1566 (void) CopyMagickString(keyword,token,MaxTextExtent);
1567 (void) GetNextToken(q,&q,extent,token);
1570 (void) GetNextToken(q,&q,extent,token);
1571 if (LocaleCompare(keyword,
"file") == 0)
1573 if (depth > MagickMaxRecursionDepth)
1574 (void) ThrowMagickException(exception,GetMagickModule(),
1575 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
1579 path[MaxTextExtent],
1582 GetPathComponent(filename,HeadPath,path);
1584 (void) ConcatenateMagickString(path,DirectorySeparator,
1586 if (*token == *DirectorySeparator)
1587 (void) CopyMagickString(path,token,MaxTextExtent);
1589 (
void) ConcatenateMagickString(path,token,MaxTextExtent);
1590 xml=FileToXML(path,~0UL);
1591 if (xml != (
char *) NULL)
1593 status&=LoadLogCache(cache,xml,path,depth+1,
1595 xml=DestroyString(xml);
1602 if (LocaleCompare(keyword,
"<logmap>") == 0)
1607 log_info=(
LogInfo *) AcquireMagickMemory(
sizeof(*log_info));
1608 if (log_info == (
LogInfo *) NULL)
1609 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
1610 (void) memset(log_info,0,
sizeof(*log_info));
1611 log_info->path=ConstantString(filename);
1612 GetTimerInfo((
TimerInfo *) &log_info->timer);
1613 log_info->signature=MagickCoreSignature;
1616 if (log_info == (
LogInfo *) NULL)
1618 if (LocaleCompare(keyword,
"</logmap>") == 0)
1620 status=AppendValueToLinkedList(cache,log_info);
1621 if (status == MagickFalse)
1622 (void) ThrowMagickException(exception,GetMagickModule(),
1623 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",filename);
1627 (void) GetNextToken(q,(
const char **) NULL,extent,token);
1630 (void) GetNextToken(q,&q,extent,token);
1631 (void) GetNextToken(q,&q,extent,token);
1637 if (LocaleCompare((
char *) keyword,
"events") == 0)
1639 log_info->event_mask=(LogEventType) (log_info->event_mask |
1640 ParseCommandOption(MagickLogEventOptions,MagickTrue,token));
1648 if (LocaleCompare((
char *) keyword,
"filename") == 0)
1650 if (log_info->filename != (
char *) NULL)
1651 log_info->filename=(
char *)
1652 RelinquishMagickMemory(log_info->filename);
1653 log_info->filename=ConstantString(token);
1656 if (LocaleCompare((
char *) keyword,
"format") == 0)
1658 if (log_info->format != (
char *) NULL)
1659 log_info->format=(
char *)
1660 RelinquishMagickMemory(log_info->format);
1661 log_info->format=ConstantString(token);
1669 if (LocaleCompare((
char *) keyword,
"generations") == 0)
1671 if (LocaleCompare(token,
"unlimited") == 0)
1673 log_info->generations=(~0UL);
1676 log_info->generations=StringToUnsignedLong(token);
1684 if (LocaleCompare((
char *) keyword,
"limit") == 0)
1686 if (LocaleCompare(token,
"unlimited") == 0)
1688 log_info->limit=(~0UL);
1691 log_info->limit=StringToUnsignedLong(token);
1699 if (LocaleCompare((
char *) keyword,
"output") == 0)
1701 log_info->handler_mask=(LogHandlerType)
1702 (log_info->handler_mask | ParseLogHandlers(token));
1711 token=DestroyString(token);
1713 return(MagickFalse);
1714 return(status != 0 ? MagickTrue : MagickFalse);
1718#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
1742static LogHandlerType ParseLogHandlers(
const char *handlers)
1756 handler_mask=NoHandler;
1757 for (p=handlers; p != (
char *) NULL; p=strchr(p,
','))
1759 while ((*p !=
'\0') && ((isspace((
int) ((
unsigned char) *p)) != 0) ||
1762 for (i=0; *LogHandlers[i].name !=
'\0'; i++)
1764 length=strlen(LogHandlers[i].name);
1765 if (LocaleNCompare(p,LogHandlers[i].name,length) == 0)
1767 handler_mask=(LogHandlerType) (handler_mask | LogHandlers[i].handler);
1771 if (*LogHandlers[i].name ==
'\0')
1772 return(UndefinedHandler);
1774 return(handler_mask);
1802MagickExport LogEventType SetLogEventMask(
const char *events)
1813 exception=AcquireExceptionInfo();
1814 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1815 exception=DestroyExceptionInfo(exception);
1816 option=ParseCommandOption(MagickLogEventOptions,MagickTrue,events);
1817 LockSemaphoreInfo(log_semaphore);
1818 log_info=(
LogInfo *) GetValueFromLinkedList(log_cache,0);
1819 log_info->event_mask=(LogEventType) option;
1821 log_info->event_mask=UndefinedEvents;
1822 CheckEventLogging();
1823 UnlockSemaphoreInfo(log_semaphore);
1824 return(log_info->event_mask);
1849MagickExport
void SetLogFormat(
const char *format)
1857 exception=AcquireExceptionInfo();
1858 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1859 exception=DestroyExceptionInfo(exception);
1860 LockSemaphoreInfo(log_semaphore);
1861 if (log_info->format != (
char *) NULL)
1862 log_info->format=DestroyString(log_info->format);
1863 log_info->format=ConstantString(format);
1864 UnlockSemaphoreInfo(log_semaphore);
1890MagickExport
void SetLogMethod(MagickLogMethod method)
1898 exception=AcquireExceptionInfo();
1899 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1900 exception=DestroyExceptionInfo(exception);
1901 LockSemaphoreInfo(log_semaphore);
1902 log_info=(
LogInfo *) GetValueFromLinkedList(log_cache,0);
1903 log_info->handler_mask=(LogHandlerType) (log_info->handler_mask |
1905 log_info->method=method;
1906 UnlockSemaphoreInfo(log_semaphore);
1933MagickExport
char *SetLogName(
const char *name)
1935 if ((name != (
char *) NULL) && (*name !=
'\0'))
1936 (void) CopyMagickString(log_name,name,MaxTextExtent);