42#include "MagickCore/studio.h"
43#include "MagickCore/blob.h"
44#include "MagickCore/client.h"
45#include "MagickCore/configure.h"
46#include "MagickCore/configure-private.h"
47#include "MagickCore/exception.h"
48#include "MagickCore/exception-private.h"
49#include "MagickCore/linked-list.h"
50#include "MagickCore/linked-list-private.h"
51#include "MagickCore/log.h"
52#include "MagickCore/log-private.h"
53#include "MagickCore/memory_.h"
54#include "MagickCore/nt-base-private.h"
55#include "MagickCore/option.h"
56#include "MagickCore/resource-private.h"
57#include "MagickCore/semaphore.h"
58#include "MagickCore/string_.h"
59#include "MagickCore/string-private.h"
60#include "MagickCore/thread_.h"
61#include "MagickCore/thread-private.h"
62#include "MagickCore/timer.h"
63#include "MagickCore/timer-private.h"
64#include "MagickCore/token.h"
65#include "MagickCore/utility.h"
66#include "MagickCore/utility-private.h"
67#include "MagickCore/version.h"
68#include "MagickCore/xml-tree.h"
69#include "MagickCore/xml-tree-private.h"
74#define LogFilename "log.xml"
81 UndefinedHandler = 0x0000,
83 ConsoleHandler = 0x0001,
84 StdoutHandler = 0x0002,
85 StderrHandler = 0x0004,
87 DebugHandler = 0x0010,
88 EventHandler = 0x0020,
89 MethodHandler = 0x0040
166static const HandlerInfo
169 {
"Console", ConsoleHandler },
170 {
"Debug", DebugHandler },
171 {
"Event", EventHandler },
172 {
"File", FileHandler },
173 {
"None", NoHandler },
174 {
"Stderr", StderrHandler },
175 {
"Stdout", StdoutHandler },
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 },
198 {
"", UndefinedHandler },
199 {
"", UndefinedHandler },
200 {
"", UndefinedHandler }
203static const LogMapInfo
206 { NoEvents, ConsoleHandler,
"Magick-%g.log",
207 "%t %r %u %v %d %c[%p]: %m/%f/%l/%d\\n %e" }
211 log_name[MagickPathExtent] =
"Magick";
214 *log_cache = (LinkedListInfo *) NULL;
216static MagickBooleanType
217 event_logging = MagickFalse;
225#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
227 ParseLogHandlers(
const char *) magick_attribute((__pure__));
231 *GetLogInfo(
const char *,ExceptionInfo *);
233static MagickBooleanType
234 IsLogCacheInstantiated(ExceptionInfo *) magick_attribute((__pure__));
236#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
237static MagickBooleanType
238 LoadLogCache(LinkedListInfo *,
const char *,
const char *,
const size_t,
268static LinkedListInfo *AcquireLogCache(
const char *filename,
269 ExceptionInfo *exception)
283 cache=NewLinkedList(0);
285#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
293 options=GetConfigureOptions(filename,exception);
294 option=(
const StringInfo *) GetNextValueInLinkedList(options);
295 while (option != (
const StringInfo *) NULL)
297 status&=(MagickStatusType) LoadLogCache(cache,(
const char *)
298 GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
299 option=(
const StringInfo *) GetNextValueInLinkedList(options);
301 options=DestroyConfigureOptions(options);
304 magick_unreferenced(filename);
309 for (i=0; i < (ssize_t) (
sizeof(LogMap)/
sizeof(*LogMap)); i++)
318 log_info=(LogInfo *) AcquireMagickMemory(
sizeof(*log_info));
319 if (log_info == (LogInfo *) NULL)
321 (void) ThrowMagickException(exception,GetMagickModule(),
322 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",p->filename);
325 (void) memset(log_info,0,
sizeof(*log_info));
326 log_info->path=ConstantString(
"[built-in]");
327 GetTimerInfo((TimerInfo *) &log_info->timer);
328 log_info->event_mask=p->event_mask;
329 log_info->handler_mask=p->handler_mask;
330 log_info->filename=ConstantString(p->filename);
331 log_info->format=ConstantString(p->format);
332 log_info->signature=MagickCoreSignature;
333 status&=(MagickStatusType) AppendValueToLinkedList(cache,log_info);
334 if (status == MagickFalse)
335 (void) ThrowMagickException(exception,GetMagickModule(),
336 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",log_info->name);
359MagickExport
void CloseMagickLog(
void)
367 if (IsEventLogging() == MagickFalse)
369 exception=AcquireExceptionInfo();
370 log_info=GetLogInfo(
"*",exception);
371 exception=DestroyExceptionInfo(exception);
372 if (log_info == (LogInfo *) NULL)
374 LockSemaphoreInfo(log_semaphore);
375 if ((log_info != (LogInfo *) NULL) && (log_info->file != (FILE *) NULL))
377 (void) FormatLocaleFile(log_info->file,
"</log>\n");
378 (void) fclose(log_info->file);
379 log_info->file=(FILE *) NULL;
381 UnlockSemaphoreInfo(log_semaphore);
402MagickExport LogEventType GetLogEventMask(
void)
410 exception=AcquireExceptionInfo();
411 log_info=GetLogInfo(
"*",exception);
412 exception=DestroyExceptionInfo(exception);
413 if (log_info == (
const LogInfo *) NULL)
415 return(log_info->event_mask);
443static LogInfo *GetLogInfo(
const char *name,ExceptionInfo *exception)
451 assert(exception != (ExceptionInfo *) NULL);
452 if (IsLogCacheInstantiated(exception) == MagickFalse)
453 return((LogInfo *) NULL);
457 log_info=(LogInfo *) NULL;
458 LockSemaphoreInfo(log_semaphore);
459 p=GetHeadElementInLinkedList(log_cache);
460 if ((name == (
const char *) NULL) || (LocaleCompare(name,
"*") == 0))
462 if (p != (ElementInfo *) NULL)
463 log_info=(LogInfo *) p->value;
464 UnlockSemaphoreInfo(log_semaphore);
467 while (p != (ElementInfo *) NULL)
469 log_info=(LogInfo* ) p->value;
470 if (LocaleCompare(name,log_info->name) == 0)
474 if (p == (ElementInfo *) NULL)
475 log_info=(LogInfo *) NULL;
477 SetHeadElementInLinkedList(log_cache,p);
478 UnlockSemaphoreInfo(log_semaphore);
509#if defined(__cplusplus) || defined(c_plusplus)
513static int LogInfoCompare(
const void *x,
const void *y)
519 p=(
const LogInfo **) x,
520 q=(
const LogInfo **) y;
521 if (LocaleCompare((*p)->path,(*q)->path) == 0)
522 return(LocaleCompare((*p)->name,(*q)->name));
523 return(LocaleCompare((*p)->path,(*q)->path));
526#if defined(__cplusplus) || defined(c_plusplus)
530MagickExport
const LogInfo **GetLogInfoList(
const char *pattern,
531 size_t *number_preferences,ExceptionInfo *exception)
542 assert(pattern != (
char *) NULL);
543 assert(number_preferences != (
size_t *) NULL);
544 if (IsEventLogging() != MagickFalse)
545 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
546 *number_preferences=0;
547 if (IsLogCacheInstantiated(exception) == MagickFalse)
548 return((
const LogInfo **) NULL);
549 preferences=(
const LogInfo **) AcquireQuantumMemory((
size_t)
550 GetNumberOfElementsInLinkedList(log_cache)+1UL,
sizeof(*preferences));
551 if (preferences == (
const LogInfo **) NULL)
552 return((
const LogInfo **) NULL);
553 LockSemaphoreInfo(log_semaphore);
554 p=GetHeadElementInLinkedList(log_cache);
555 for (i=0; p != (ElementInfo *) NULL; )
560 log_info=(
const LogInfo *) p->value;
561 if ((log_info->stealth == MagickFalse) &&
562 (GlobExpression(log_info->name,pattern,MagickFalse) != MagickFalse))
563 preferences[i++]=log_info;
566 UnlockSemaphoreInfo(log_semaphore);
568 preferences=(
const LogInfo **) RelinquishMagickMemory((
void*) preferences);
571 qsort((
void *) preferences,(
size_t) i,
sizeof(*preferences),LogInfoCompare);
572 preferences[i]=(LogInfo *) NULL;
574 *number_preferences=(size_t) i;
606#if defined(__cplusplus) || defined(c_plusplus)
610static int LogCompare(
const void *x,
const void *y)
618 return(LocaleCompare(*p,*q));
621#if defined(__cplusplus) || defined(c_plusplus)
625MagickExport
char **GetLogList(
const char *pattern,
size_t *number_preferences,
626 ExceptionInfo *exception)
637 assert(pattern != (
char *) NULL);
638 assert(number_preferences != (
size_t *) NULL);
639 if (IsEventLogging() != MagickFalse)
640 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
641 *number_preferences=0;
642 if (IsLogCacheInstantiated(exception) == MagickFalse)
643 return((
char **) NULL);
644 preferences=(
char **) AcquireQuantumMemory((
size_t)
645 GetNumberOfElementsInLinkedList(log_cache)+1UL,
sizeof(*preferences));
646 if (preferences == (
char **) NULL)
647 return((
char **) NULL);
648 LockSemaphoreInfo(log_semaphore);
649 p=GetHeadElementInLinkedList(log_cache);
650 for (i=0; p != (ElementInfo *) NULL; )
655 log_info=(
const LogInfo *) p->value;
656 if ((log_info->stealth == MagickFalse) &&
657 (GlobExpression(log_info->name,pattern,MagickFalse) != MagickFalse))
658 preferences[i++]=ConstantString(log_info->name);
661 UnlockSemaphoreInfo(log_semaphore);
663 preferences=(
char **) RelinquishMagickMemory(preferences);
666 qsort((
void *) preferences,(
size_t) i,
sizeof(*preferences),LogCompare);
667 preferences[i]=(
char *) NULL;
669 *number_preferences=(size_t) i;
691MagickExport
const char *GetLogName(
void)
720static inline void CheckEventLogging(
void)
725 if (IsLinkedListEmpty(log_cache) != MagickFalse)
726 event_logging=MagickFalse;
732 p=GetHeadElementInLinkedList(log_cache);
733 event_logging=(p != (ElementInfo *) NULL) &&
734 (((LogInfo *) p->value)->event_mask != NoEvents) ?
735 MagickTrue: MagickFalse;
739static MagickBooleanType IsLogCacheInstantiated(ExceptionInfo *exception)
741 if (log_cache == (LinkedListInfo *) NULL)
744 ActivateSemaphoreInfo(&log_semaphore);
745 LockSemaphoreInfo(log_semaphore);
746 if (log_cache == (LinkedListInfo *) NULL)
748 log_cache=AcquireLogCache(LogFilename,exception);
751 UnlockSemaphoreInfo(log_semaphore);
753 return(log_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
775MagickExport MagickBooleanType IsEventLogging(
void)
777 return(event_logging);
804MagickExport MagickBooleanType ListLogInfo(FILE *file,ExceptionInfo *exception)
806#define MegabytesToBytes(value) ((MagickSizeType) (value)*1024*1024)
823 if (file == (
const FILE *) NULL)
825 log_info=GetLogInfoList(
"*",&number_aliases,exception);
826 if (log_info == (
const LogInfo **) NULL)
829 path=(
const char *) NULL;
830 for (i=0; i < (ssize_t) number_aliases; i++)
833 limit[MagickPathExtent];
835 if (log_info[i]->stealth != MagickFalse)
837 if ((path == (
const char *) NULL) ||
838 (LocaleCompare(path,log_info[i]->path) != 0))
840 if (log_info[i]->path != (
char *) NULL)
841 (void) FormatLocaleFile(file,
"\nPath: %s\nHandler: ",
843 for (j=0; j < (ssize_t) (8*
sizeof(LogHandlerType)); j++)
848 if (*LogHandlers[j].name ==
'\0')
852 if (((
size_t) log_info[i]->handler_mask & mask) != 0)
853 (void) FormatLocaleFile(file,
"%s ",LogHandlers[j].name);
855 (void) FormatLocaleFile(file,
"\n\n");
857 (void) FormatLocaleFile(file,
858 "Generations Limit Filename\n");
859 (void) FormatLocaleFile(file,
"---------------------------------------------"
860 "----------------------------------\n");
861 (void) FormatLocaleFile(file,
"%g ",(
double) log_info[i]->generations);
862 (void) CopyMagickString(limit,
"unlimited",MagickPathExtent);
863 if (log_info[i]->limit > 0)
864 (void) FormatMagickSize(log_info[i]->limit,MagickTrue,
"B",
865 MagickFormatExtent,limit);
866 (void) FormatLocaleFile(file,
" %9s",limit);
867 if (log_info[i]->filename != (
char *) NULL)
868 (void) FormatLocaleFile(file,
" %s",log_info[i]->filename);
869 (void) FormatLocaleFile(file,
"\n");
870 if (log_info[i]->format != (
char *) NULL)
871 (void) FormatLocaleFile(file,
" Format: %s\n",log_info[i]->format);
872 (void) FormatLocaleFile(file,
"\n");
873 path=log_info[i]->path;
876 log_info=(
const LogInfo **) RelinquishMagickMemory((
void *) log_info);
880#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
911static MagickBooleanType LoadLogCache(LinkedListInfo *cache,
const char *xml,
912 const char *filename,
const size_t depth,ExceptionInfo *exception)
915 keyword[MagickPathExtent],
922 *log_info = (LogInfo *) NULL;
933 if (xml == (
const char *) NULL)
936 token=AcquireString(xml);
937 extent=strlen(token)+MagickPathExtent;
938 for (q=(
const char *) xml; *q !=
'\0'; )
943 (void) GetNextToken(q,&q,extent,token);
946 (void) CopyMagickString(keyword,token,MagickPathExtent);
947 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
952 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
953 (void) GetNextToken(q,&q,extent,token);
956 if (LocaleNCompare(keyword,
"<!--",4) == 0)
961 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
962 (void) GetNextToken(q,&q,extent,token);
965 if (LocaleCompare(keyword,
"<include") == 0)
970 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
972 (void) CopyMagickString(keyword,token,MagickPathExtent);
973 (void) GetNextToken(q,&q,extent,token);
976 (void) GetNextToken(q,&q,extent,token);
977 if (LocaleCompare(keyword,
"file") == 0)
979 if (depth > MagickMaxRecursionDepth)
980 (void) ThrowMagickException(exception,GetMagickModule(),
981 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
985 path[MagickPathExtent],
988 GetPathComponent(filename,HeadPath,path);
990 (void) ConcatenateMagickString(path,DirectorySeparator,
992 if (*token == *DirectorySeparator)
993 (void) CopyMagickString(path,token,MagickPathExtent);
995 (
void) ConcatenateMagickString(path,token,MagickPathExtent);
996 file_xml=FileToXML(path,~0UL);
997 if (file_xml != (
char *) NULL)
999 status&=(MagickStatusType) LoadLogCache(cache,file_xml,
1000 path,depth+1,exception);
1001 file_xml=DestroyString(file_xml);
1008 if (LocaleCompare(keyword,
"<logmap>") == 0)
1013 log_info=(LogInfo *) AcquireCriticalMemory(
sizeof(*log_info));
1014 (void) memset(log_info,0,
sizeof(*log_info));
1015 log_info->path=ConstantString(filename);
1016 GetTimerInfo((TimerInfo *) &log_info->timer);
1017 log_info->signature=MagickCoreSignature;
1020 if (log_info == (LogInfo *) NULL)
1022 if (LocaleCompare(keyword,
"</logmap>") == 0)
1024 status=AppendValueToLinkedList(cache,log_info);
1025 if (status == MagickFalse)
1026 (void) ThrowMagickException(exception,GetMagickModule(),
1027 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",filename);
1028 log_info=(LogInfo *) NULL;
1031 (void) GetNextToken(q,(
const char **) NULL,extent,token);
1034 (void) GetNextToken(q,&q,extent,token);
1035 (void) GetNextToken(q,&q,extent,token);
1041 if (LocaleCompare((
char *) keyword,
"events") == 0)
1043 log_info->event_mask=(LogEventType) (log_info->event_mask |
1044 ParseCommandOption(MagickLogEventOptions,MagickTrue,token));
1052 if (LocaleCompare((
char *) keyword,
"filename") == 0)
1054 if (log_info->filename != (
char *) NULL)
1055 log_info->filename=(
char *)
1056 RelinquishMagickMemory(log_info->filename);
1057 log_info->filename=ConstantString(token);
1060 if (LocaleCompare((
char *) keyword,
"format") == 0)
1062 if (log_info->format != (
char *) NULL)
1063 log_info->format=(
char *)
1064 RelinquishMagickMemory(log_info->format);
1065 log_info->format=ConstantString(token);
1073 if (LocaleCompare((
char *) keyword,
"generations") == 0)
1075 if (LocaleCompare(token,
"unlimited") == 0)
1077 log_info->generations=(~0UL);
1080 log_info->generations=StringToUnsignedLong(token);
1088 if (LocaleCompare((
char *) keyword,
"limit") == 0)
1090 if (LocaleCompare(token,
"unlimited") == 0)
1092 log_info->limit=(~0UL);
1095 log_info->limit=StringToMagickSizeType(token,100.0);
1096 if (log_info->limit < 1024)
1097 log_info->limit=1024*1024*StringToUnsignedLong(token);
1105 if (LocaleCompare((
char *) keyword,
"output") == 0)
1107 log_info->handler_mask=(LogHandlerType)
1108 (log_info->handler_mask | ParseLogHandlers(token));
1117 token=DestroyString(token);
1118 if (cache == (LinkedListInfo *) NULL)
1119 return(MagickFalse);
1120 return(status != 0 ? MagickTrue : MagickFalse);
1142MagickPrivate MagickBooleanType LogComponentGenesis(
void)
1148 log_semaphore=AcquireSemaphoreInfo();
1149 exception=AcquireExceptionInfo();
1150 (void) GetLogInfo(
"*",exception);
1151 exception=DestroyExceptionInfo(exception);
1174static void *DestroyLogElement(
void *log_info)
1179 p=(LogInfo *) log_info;
1180 if (p->file != (FILE *) NULL)
1182 (void) FormatLocaleFile(p->file,
"</log>\n");
1183 (void) fclose(p->file);
1184 p->file=(FILE *) NULL;
1186 if (p->format != (
char *) NULL)
1187 p->format=DestroyString(p->format);
1188 if (p->path != (
char *) NULL)
1189 p->path=DestroyString(p->path);
1190 if (p->filename != (
char *) NULL)
1191 p->filename=DestroyString(p->filename);
1193 RelinquishSemaphoreInfo(&p->event_semaphore);
1194 p=(LogInfo *) RelinquishMagickMemory(p);
1195 return((
void *) NULL);
1198MagickPrivate
void LogComponentTerminus(
void)
1201 ActivateSemaphoreInfo(&log_semaphore);
1202 LockSemaphoreInfo(log_semaphore);
1203 if (log_cache != (LinkedListInfo *) NULL)
1204 log_cache=DestroyLinkedList(log_cache,DestroyLogElement);
1205 event_logging=MagickFalse;
1206 UnlockSemaphoreInfo(log_semaphore);
1207 RelinquishSemaphoreInfo(&log_semaphore);
1244static void FormatLogFilename(
const LogInfo *log_info,
const ssize_t generation,
1256 assert(log_info != (LogInfo *) NULL);
1258 for (p=log_info->filename; *p !=
'\0'; p++)
1287 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),MagickPathExtent);
1292 if (log_info->generations == 0)
1294 (void) CopyMagickString(q,
"0",MagickPathExtent);
1298 q+=(ptrdiff_t) FormatLocaleString(q,MagickPathExtent,
"%.20g",(
double)
1299 (generation % log_info->generations));
1304 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),MagickPathExtent);
1309 q+=(ptrdiff_t) FormatLocaleString(q,MagickPathExtent,
"%.20g",(
double)
1315 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,
1335static char *TranslateEvent(
const char *module,
const char *function,
1336 const size_t line,
const char *domain,
const char *event)
1363 exception=AcquireExceptionInfo();
1364 log_info=GetLogInfo(
"*",exception);
1365 exception=DestroyExceptionInfo(exception);
1366 text=AcquireString(event);
1367 if (log_info == (LogInfo *) NULL)
1369 seconds=GetMagickTime();
1370 elapsed_time=GetElapsedTime(&log_info->timer);
1371 user_time=GetUserTime(&log_info->timer);
1372 if (log_info->format == (
char *) NULL)
1374 extent=strlen(event)+MagickPathExtent;
1375 if (LocaleCompare(log_info->format,
"xml") == 0)
1378 timestamp[MagickTimeExtent];
1383 (void) FormatMagickTime(seconds,
sizeof(timestamp),timestamp);
1384 (void) FormatLocaleString(text,extent,
1386 " <timestamp>%s</timestamp>\n"
1387 " <elapsed-time>%lu:%02lu.%06lu</elapsed-time>\n"
1388 " <user-time>%0.3f</user-time>\n"
1389 " <process-id>%.20g</process-id>\n"
1390 " <thread-id>%.20g</thread-id>\n"
1391 " <module>%s</module>\n"
1392 " <function>%s</function>\n"
1393 " <line>%.20g</line>\n"
1394 " <domain>%s</domain>\n"
1395 " <event>%s</event>\n"
1396 "</entry>",timestamp,(
unsigned long) (elapsed_time/60.0),
1397 (
unsigned long) floor(fmod(elapsed_time,60.0)),(
unsigned long)
1398 (1000000.0*(elapsed_time-floor(elapsed_time))+0.5),user_time,
1399 (
double) getpid(),(
double) GetMagickThreadSignature(),module,function,
1400 (
double) line,domain,event);
1407 for (p=log_info->format; *p !=
'\0'; p++)
1410 if ((
size_t) (q-text+MagickPathExtent) >= extent)
1413 text=(
char *) ResizeQuantumMemory(text,extent,
sizeof(*text));
1414 if (text == (
char *) NULL)
1415 return((
char *) NULL);
1416 q=text+strlen(text);
1438 if ((*p ==
'\\') && (*(p+1) ==
'r'))
1444 if ((*p ==
'\\') && (*(p+1) ==
'n'))
1462 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),extent-(q-text));
1467 q+=(ptrdiff_t) CopyMagickString(q,domain,extent-(q-text));
1472 q+=(ptrdiff_t) CopyMagickString(q,event,extent-(q-text));
1477 q+=(ptrdiff_t) CopyMagickString(q,function,extent-(q-text));
1482 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(
double)
1483 GetMagickThreadSignature());
1488 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(
double)
1497 for (r=module+strlen(module)-1; r > module; r--)
1498 if (*r == *DirectorySeparator)
1503 q+=(ptrdiff_t) CopyMagickString(q,r,extent-(q-text));
1508 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),extent-(q-text));
1513 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(
double)
1519 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%lu:%02lu.%03lu",
1520 (
unsigned long) (elapsed_time/60.0),(
unsigned long) floor(fmod(
1521 elapsed_time,60.0)),(
unsigned long) (1000.0*(elapsed_time-floor(
1522 elapsed_time))+0.5));
1527 q+=(ptrdiff_t) FormatMagickTime(seconds,extent-(q-text),q);
1532 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%0.3fu",user_time);
1537 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,extent-(q-text));
1557MagickExport MagickBooleanType LogMagickEventList(
const LogEventType type,
1558 const char *module,
const char *function,
const size_t line,
const char *format,
1562 event[MagickPathExtent],
1577 exception=AcquireExceptionInfo();
1578 log_info=(LogInfo *) GetLogInfo(
"*",exception);
1579 exception=DestroyExceptionInfo(exception);
1580 if (log_info == (LogInfo *) NULL)
1581 return(MagickFalse);
1583 ActivateSemaphoreInfo(&log_info->event_semaphore);
1584 LockSemaphoreInfo(log_info->event_semaphore);
1585 if ((log_info->event_mask & type) == 0)
1587 UnlockSemaphoreInfo(log_info->event_semaphore);
1590 domain=CommandOptionToMnemonic(MagickLogEventOptions,type);
1591#if defined(MAGICKCORE_HAVE_VSNPRINTF)
1592 n=vsnprintf(event,MagickPathExtent,format,operands);
1594 n=vsprintf(event,format,operands);
1597 event[MagickPathExtent-1]=
'\0';
1598 text=TranslateEvent(module,function,line,domain,event);
1599 if (text == (
char *) NULL)
1601 (void) ContinueTimer((TimerInfo *) &log_info->timer);
1602 UnlockSemaphoreInfo(log_info->event_semaphore);
1603 return(MagickFalse);
1605 if ((log_info->handler_mask & ConsoleHandler) != 0)
1607 (void) FormatLocaleFile(stderr,
"%s\n",text);
1608 (void) fflush(stderr);
1610 if ((log_info->handler_mask & DebugHandler) != 0)
1612#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1613 OutputDebugString(text);
1614 OutputDebugString(
"\n");
1617 if ((log_info->handler_mask & EventHandler) != 0)
1619#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1620 (void) NTReportEvent(text,MagickFalse);
1623 if ((log_info->handler_mask & FileHandler) != 0)
1628 file_info.st_size=0;
1629 if (log_info->file != (FILE *) NULL)
1630 (void) fstat(fileno(log_info->file),&file_info);
1631 if (file_info.st_size > (MagickOffsetType) log_info->limit)
1639 (void) FormatLocaleFile(log_info->file,
"</log>\n");
1640 (void) FormatLocaleFile(log_info->file,
"</logEntries>\n");
1641 (void) fclose(log_info->file);
1642 for (i=(ssize_t) log_info->generations-1; i > 0; i--)
1645 new_filename[MagickPathExtent],
1646 old_filename[MagickPathExtent];
1651 FormatLogFilename(log_info,i-1,old_filename);
1652 FormatLogFilename(log_info,i,new_filename);
1653 (void) rename_utf8(old_filename,new_filename);
1655 log_info->file=(FILE *) NULL;
1657 if (log_info->file == (FILE *) NULL)
1660 log_filename[MagickPathExtent];
1662 FormatLogFilename(log_info,0,log_filename);
1663 log_info->append=IsPathAccessible(log_filename);
1664 log_info->file=fopen_utf8(log_filename,
"ab");
1665 if (log_info->file == (FILE *) NULL)
1667 UnlockSemaphoreInfo(log_info->event_semaphore);
1668 return(MagickFalse);
1670 if (log_info->append == MagickFalse)
1672 (void) FormatLocaleFile(log_info->file,
"<?xml version=\"1.0\" "
1673 "encoding=\"UTF-8\" standalone=\"yes\"?>\n");
1674 (void) FormatLocaleFile(log_info->file,
"<logEntries>\n");
1676 (void) FormatLocaleFile(log_info->file,
"<log>\n");
1678 (void) FormatLocaleFile(log_info->file,
" <event>%s</event>\n",text);
1679 (void) fflush(log_info->file);
1681 if ((log_info->handler_mask & MethodHandler) != 0)
1683 if (log_info->method != (MagickLogMethod) NULL)
1684 log_info->method(type,text);
1686 if ((log_info->handler_mask & StdoutHandler) != 0)
1688 (void) FormatLocaleFile(stdout,
"%s\n",text);
1689 (void) fflush(stdout);
1691 if ((log_info->handler_mask & StderrHandler) != 0)
1693 (void) FormatLocaleFile(stderr,
"%s\n",text);
1694 (void) fflush(stderr);
1696 text=(
char *) RelinquishMagickMemory(text);
1697 (void) ContinueTimer((TimerInfo *) &log_info->timer);
1698 UnlockSemaphoreInfo(log_info->event_semaphore);
1702MagickExport MagickBooleanType LogMagickEvent(
const LogEventType type,
1703 const char *module,
const char *function,
const size_t line,
1704 const char *format,...)
1712 if (IsEventLogging() == MagickFalse)
1713 return(MagickFalse);
1714 va_start(operands,format);
1715 status=LogMagickEventList(type,module,function,line,format,operands);
1720#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
1744static LogHandlerType ParseLogHandlers(
const char *handlers)
1758 handler_mask=NoHandler;
1759 for (p=handlers; p != (
char *) NULL; p=strchr(p,
','))
1761 while ((*p !=
'\0') && ((isspace((
int) ((
unsigned char) *p)) != 0) ||
1764 for (i=0; *LogHandlers[i].name !=
'\0'; i++)
1766 length=strlen(LogHandlers[i].name);
1767 if (LocaleNCompare(p,LogHandlers[i].name,length) == 0)
1769 handler_mask=(LogHandlerType) (handler_mask | LogHandlers[i].handler);
1773 if (*LogHandlers[i].name ==
'\0')
1774 return(UndefinedHandler);
1776 return(handler_mask);
1804MagickExport LogEventType SetLogEventMask(
const char *events)
1818 event_mask=UndefinedEvents;
1819 exception=AcquireExceptionInfo();
1820 log_info=GetLogInfo(
"*",exception);
1821 exception=DestroyExceptionInfo(exception);
1822 if (log_info == (LogInfo *) NULL)
1824 option=ParseCommandOption(MagickLogEventOptions,MagickTrue,events);
1825 LockSemaphoreInfo(log_semaphore);
1826 event_mask=log_info->event_mask;
1828 log_info->event_mask=UndefinedEvents;
1830 log_info->event_mask=(LogEventType) option;
1831 CheckEventLogging();
1832 UnlockSemaphoreInfo(log_semaphore);
1858MagickExport
void SetLogFormat(
const char *format)
1866 exception=AcquireExceptionInfo();
1867 log_info=(LogInfo *) GetLogInfo(
"*",exception);
1868 exception=DestroyExceptionInfo(exception);
1869 if (log_info == (LogInfo *) NULL)
1871 LockSemaphoreInfo(log_semaphore);
1872 if (log_info->format != (
char *) NULL)
1873 log_info->format=DestroyString(log_info->format);
1874 log_info->format=ConstantString(format);
1875 UnlockSemaphoreInfo(log_semaphore);
1901MagickExport
void SetLogMethod(MagickLogMethod method)
1909 exception=AcquireExceptionInfo();
1910 log_info=(LogInfo *) GetLogInfo(
"*",exception);
1911 exception=DestroyExceptionInfo(exception);
1912 if (log_info == (LogInfo *) NULL)
1914 LockSemaphoreInfo(log_semaphore);
1915 log_info=(LogInfo *) GetValueFromLinkedList(log_cache,0);
1916 log_info->handler_mask=(LogHandlerType) (log_info->handler_mask |
1918 log_info->method=method;
1919 UnlockSemaphoreInfo(log_semaphore);
1946MagickExport
const char *SetLogName(
const char *name)
1948 if ((name != (
char *) NULL) && (*name !=
'\0'))
1949 (void) CopyMagickString(log_name,name,MagickPathExtent);