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 LockSemaphoreInfo(log_semaphore);
373 if (log_info->file != (FILE *) NULL)
375 (void) FormatLocaleFile(log_info->file,
"</log>\n");
376 (void) fclose(log_info->file);
377 log_info->file=(FILE *) NULL;
379 UnlockSemaphoreInfo(log_semaphore);
400MagickExport LogEventType GetLogEventMask(
void)
408 exception=AcquireExceptionInfo();
409 log_info=GetLogInfo(
"*",exception);
410 exception=DestroyExceptionInfo(exception);
411 if (log_info == (
const LogInfo *) NULL)
413 return(log_info->event_mask);
441static LogInfo *GetLogInfo(
const char *name,ExceptionInfo *exception)
449 assert(exception != (ExceptionInfo *) NULL);
450 if (IsLogCacheInstantiated(exception) == MagickFalse)
451 return((LogInfo *) NULL);
455 log_info=(LogInfo *) NULL;
456 LockSemaphoreInfo(log_semaphore);
457 p=GetHeadElementInLinkedList(log_cache);
458 if ((name == (
const char *) NULL) || (LocaleCompare(name,
"*") == 0))
460 if (p != (ElementInfo *) NULL)
461 log_info=(LogInfo *) p->value;
462 UnlockSemaphoreInfo(log_semaphore);
465 while (p != (ElementInfo *) NULL)
467 log_info=(LogInfo* ) p->value;
468 if (LocaleCompare(name,log_info->name) == 0)
472 if (p == (ElementInfo *) NULL)
473 log_info=(LogInfo *) NULL;
475 SetHeadElementInLinkedList(log_cache,p);
476 UnlockSemaphoreInfo(log_semaphore);
507#if defined(__cplusplus) || defined(c_plusplus)
511static int LogInfoCompare(
const void *x,
const void *y)
517 p=(
const LogInfo **) x,
518 q=(
const LogInfo **) y;
519 if (LocaleCompare((*p)->path,(*q)->path) == 0)
520 return(LocaleCompare((*p)->name,(*q)->name));
521 return(LocaleCompare((*p)->path,(*q)->path));
524#if defined(__cplusplus) || defined(c_plusplus)
528MagickExport
const LogInfo **GetLogInfoList(
const char *pattern,
529 size_t *number_preferences,ExceptionInfo *exception)
540 assert(pattern != (
char *) NULL);
541 assert(number_preferences != (
size_t *) NULL);
542 if (IsEventLogging() != MagickFalse)
543 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
544 *number_preferences=0;
545 if (IsLogCacheInstantiated(exception) == MagickFalse)
546 return((
const LogInfo **) NULL);
547 preferences=(
const LogInfo **) AcquireQuantumMemory((
size_t)
548 GetNumberOfElementsInLinkedList(log_cache)+1UL,
sizeof(*preferences));
549 if (preferences == (
const LogInfo **) NULL)
550 return((
const LogInfo **) NULL);
551 LockSemaphoreInfo(log_semaphore);
552 p=GetHeadElementInLinkedList(log_cache);
553 for (i=0; p != (ElementInfo *) NULL; )
558 log_info=(
const LogInfo *) p->value;
559 if ((log_info->stealth == MagickFalse) &&
560 (GlobExpression(log_info->name,pattern,MagickFalse) != MagickFalse))
561 preferences[i++]=log_info;
564 UnlockSemaphoreInfo(log_semaphore);
566 preferences=(
const LogInfo **) RelinquishMagickMemory((
void*) preferences);
569 qsort((
void *) preferences,(
size_t) i,
sizeof(*preferences),LogInfoCompare);
570 preferences[i]=(LogInfo *) NULL;
572 *number_preferences=(size_t) i;
604#if defined(__cplusplus) || defined(c_plusplus)
608static int LogCompare(
const void *x,
const void *y)
616 return(LocaleCompare(*p,*q));
619#if defined(__cplusplus) || defined(c_plusplus)
623MagickExport
char **GetLogList(
const char *pattern,
size_t *number_preferences,
624 ExceptionInfo *exception)
635 assert(pattern != (
char *) NULL);
636 assert(number_preferences != (
size_t *) NULL);
637 if (IsEventLogging() != MagickFalse)
638 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
639 *number_preferences=0;
640 if (IsLogCacheInstantiated(exception) == MagickFalse)
641 return((
char **) NULL);
642 preferences=(
char **) AcquireQuantumMemory((
size_t)
643 GetNumberOfElementsInLinkedList(log_cache)+1UL,
sizeof(*preferences));
644 if (preferences == (
char **) NULL)
645 return((
char **) NULL);
646 LockSemaphoreInfo(log_semaphore);
647 p=GetHeadElementInLinkedList(log_cache);
648 for (i=0; p != (ElementInfo *) NULL; )
653 log_info=(
const LogInfo *) p->value;
654 if ((log_info->stealth == MagickFalse) &&
655 (GlobExpression(log_info->name,pattern,MagickFalse) != MagickFalse))
656 preferences[i++]=ConstantString(log_info->name);
659 UnlockSemaphoreInfo(log_semaphore);
661 preferences=(
char **) RelinquishMagickMemory(preferences);
664 qsort((
void *) preferences,(
size_t) i,
sizeof(*preferences),LogCompare);
665 preferences[i]=(
char *) NULL;
667 *number_preferences=(size_t) i;
689MagickExport
const char *GetLogName(
void)
718static inline void CheckEventLogging(
void)
723 if (IsLinkedListEmpty(log_cache) != MagickFalse)
724 event_logging=MagickFalse;
730 p=GetHeadElementInLinkedList(log_cache);
731 event_logging=(p != (ElementInfo *) NULL) &&
732 (((LogInfo *) p->value)->event_mask != NoEvents) ?
733 MagickTrue: MagickFalse;
737static MagickBooleanType IsLogCacheInstantiated(ExceptionInfo *exception)
739 if (log_cache == (LinkedListInfo *) NULL)
742 ActivateSemaphoreInfo(&log_semaphore);
743 LockSemaphoreInfo(log_semaphore);
744 if (log_cache == (LinkedListInfo *) NULL)
746 log_cache=AcquireLogCache(LogFilename,exception);
749 UnlockSemaphoreInfo(log_semaphore);
751 return(log_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
773MagickExport MagickBooleanType IsEventLogging(
void)
775 return(event_logging);
802MagickExport MagickBooleanType ListLogInfo(FILE *file,ExceptionInfo *exception)
804#define MegabytesToBytes(value) ((MagickSizeType) (value)*1024*1024)
821 if (file == (
const FILE *) NULL)
823 log_info=GetLogInfoList(
"*",&number_aliases,exception);
824 if (log_info == (
const LogInfo **) NULL)
827 path=(
const char *) NULL;
828 for (i=0; i < (ssize_t) number_aliases; i++)
831 limit[MagickPathExtent];
833 if (log_info[i]->stealth != MagickFalse)
835 if ((path == (
const char *) NULL) ||
836 (LocaleCompare(path,log_info[i]->path) != 0))
838 if (log_info[i]->path != (
char *) NULL)
839 (void) FormatLocaleFile(file,
"\nPath: %s\nHandler: ",
841 for (j=0; j < (ssize_t) (8*
sizeof(LogHandlerType)); j++)
846 if (*LogHandlers[j].name ==
'\0')
850 if (((
size_t) log_info[i]->handler_mask & mask) != 0)
851 (void) FormatLocaleFile(file,
"%s ",LogHandlers[j].name);
853 (void) FormatLocaleFile(file,
"\n\n");
855 (void) FormatLocaleFile(file,
856 "Generations Limit Filename\n");
857 (void) FormatLocaleFile(file,
"---------------------------------------------"
858 "----------------------------------\n");
859 (void) FormatLocaleFile(file,
"%g ",(
double) log_info[i]->generations);
860 (void) CopyMagickString(limit,
"unlimited",MagickPathExtent);
861 if (log_info[i]->limit > 0)
862 (void) FormatMagickSize(log_info[i]->limit,MagickTrue,
"B",
863 MagickFormatExtent,limit);
864 (void) FormatLocaleFile(file,
" %9s",limit);
865 if (log_info[i]->filename != (
char *) NULL)
866 (void) FormatLocaleFile(file,
" %s",log_info[i]->filename);
867 (void) FormatLocaleFile(file,
"\n");
868 if (log_info[i]->format != (
char *) NULL)
869 (void) FormatLocaleFile(file,
" Format: %s\n",log_info[i]->format);
870 (void) FormatLocaleFile(file,
"\n");
871 path=log_info[i]->path;
874 log_info=(
const LogInfo **) RelinquishMagickMemory((
void *) log_info);
878#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
909static MagickBooleanType LoadLogCache(LinkedListInfo *cache,
const char *xml,
910 const char *filename,
const size_t depth,ExceptionInfo *exception)
913 keyword[MagickPathExtent],
920 *log_info = (LogInfo *) NULL;
931 if (xml == (
const char *) NULL)
934 token=AcquireString(xml);
935 extent=strlen(token)+MagickPathExtent;
936 for (q=(
const char *) xml; *q !=
'\0'; )
941 (void) GetNextToken(q,&q,extent,token);
944 (void) CopyMagickString(keyword,token,MagickPathExtent);
945 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
950 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
951 (void) GetNextToken(q,&q,extent,token);
954 if (LocaleNCompare(keyword,
"<!--",4) == 0)
959 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
960 (void) GetNextToken(q,&q,extent,token);
963 if (LocaleCompare(keyword,
"<include") == 0)
968 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
970 (void) CopyMagickString(keyword,token,MagickPathExtent);
971 (void) GetNextToken(q,&q,extent,token);
974 (void) GetNextToken(q,&q,extent,token);
975 if (LocaleCompare(keyword,
"file") == 0)
977 if (depth > MagickMaxRecursionDepth)
978 (void) ThrowMagickException(exception,GetMagickModule(),
979 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
983 path[MagickPathExtent],
986 GetPathComponent(filename,HeadPath,path);
988 (void) ConcatenateMagickString(path,DirectorySeparator,
990 if (*token == *DirectorySeparator)
991 (void) CopyMagickString(path,token,MagickPathExtent);
993 (
void) ConcatenateMagickString(path,token,MagickPathExtent);
994 file_xml=FileToXML(path,~0UL);
995 if (file_xml != (
char *) NULL)
997 status&=(MagickStatusType) LoadLogCache(cache,file_xml,
998 path,depth+1,exception);
999 file_xml=DestroyString(file_xml);
1006 if (LocaleCompare(keyword,
"<logmap>") == 0)
1011 log_info=(LogInfo *) AcquireCriticalMemory(
sizeof(*log_info));
1012 (void) memset(log_info,0,
sizeof(*log_info));
1013 log_info->path=ConstantString(filename);
1014 GetTimerInfo((TimerInfo *) &log_info->timer);
1015 log_info->signature=MagickCoreSignature;
1018 if (log_info == (LogInfo *) NULL)
1020 if (LocaleCompare(keyword,
"</logmap>") == 0)
1022 status=AppendValueToLinkedList(cache,log_info);
1023 if (status == MagickFalse)
1024 (void) ThrowMagickException(exception,GetMagickModule(),
1025 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",filename);
1026 log_info=(LogInfo *) NULL;
1029 (void) GetNextToken(q,(
const char **) NULL,extent,token);
1032 (void) GetNextToken(q,&q,extent,token);
1033 (void) GetNextToken(q,&q,extent,token);
1039 if (LocaleCompare((
char *) keyword,
"events") == 0)
1041 log_info->event_mask=(LogEventType) (log_info->event_mask |
1042 ParseCommandOption(MagickLogEventOptions,MagickTrue,token));
1050 if (LocaleCompare((
char *) keyword,
"filename") == 0)
1052 if (log_info->filename != (
char *) NULL)
1053 log_info->filename=(
char *)
1054 RelinquishMagickMemory(log_info->filename);
1055 log_info->filename=ConstantString(token);
1058 if (LocaleCompare((
char *) keyword,
"format") == 0)
1060 if (log_info->format != (
char *) NULL)
1061 log_info->format=(
char *)
1062 RelinquishMagickMemory(log_info->format);
1063 log_info->format=ConstantString(token);
1071 if (LocaleCompare((
char *) keyword,
"generations") == 0)
1073 if (LocaleCompare(token,
"unlimited") == 0)
1075 log_info->generations=(~0UL);
1078 log_info->generations=StringToUnsignedLong(token);
1086 if (LocaleCompare((
char *) keyword,
"limit") == 0)
1088 if (LocaleCompare(token,
"unlimited") == 0)
1090 log_info->limit=(~0UL);
1093 log_info->limit=StringToMagickSizeType(token,100.0);
1094 if (log_info->limit < 1024)
1095 log_info->limit=1024*1024*StringToUnsignedLong(token);
1103 if (LocaleCompare((
char *) keyword,
"output") == 0)
1105 log_info->handler_mask=(LogHandlerType)
1106 (log_info->handler_mask | ParseLogHandlers(token));
1115 token=DestroyString(token);
1116 if (cache == (LinkedListInfo *) NULL)
1117 return(MagickFalse);
1118 return(status != 0 ? MagickTrue : MagickFalse);
1140MagickPrivate MagickBooleanType LogComponentGenesis(
void)
1146 log_semaphore=AcquireSemaphoreInfo();
1147 exception=AcquireExceptionInfo();
1148 (void) GetLogInfo(
"*",exception);
1149 exception=DestroyExceptionInfo(exception);
1172static void *DestroyLogElement(
void *log_info)
1177 p=(LogInfo *) log_info;
1178 if (p->file != (FILE *) NULL)
1180 (void) FormatLocaleFile(p->file,
"</log>\n");
1181 (void) fclose(p->file);
1182 p->file=(FILE *) NULL;
1184 if (p->format != (
char *) NULL)
1185 p->format=DestroyString(p->format);
1186 if (p->path != (
char *) NULL)
1187 p->path=DestroyString(p->path);
1188 if (p->filename != (
char *) NULL)
1189 p->filename=DestroyString(p->filename);
1191 RelinquishSemaphoreInfo(&p->event_semaphore);
1192 p=(LogInfo *) RelinquishMagickMemory(p);
1193 return((
void *) NULL);
1196MagickPrivate
void LogComponentTerminus(
void)
1199 ActivateSemaphoreInfo(&log_semaphore);
1200 LockSemaphoreInfo(log_semaphore);
1201 if (log_cache != (LinkedListInfo *) NULL)
1202 log_cache=DestroyLinkedList(log_cache,DestroyLogElement);
1203 event_logging=MagickFalse;
1204 UnlockSemaphoreInfo(log_semaphore);
1205 RelinquishSemaphoreInfo(&log_semaphore);
1242static void FormatLogFilename(
const LogInfo *log_info,
const ssize_t generation,
1254 assert(log_info != (LogInfo *) NULL);
1256 for (p=log_info->filename; *p !=
'\0'; p++)
1285 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),MagickPathExtent);
1290 if (log_info->generations == 0)
1292 (void) CopyMagickString(q,
"0",MagickPathExtent);
1296 q+=(ptrdiff_t) FormatLocaleString(q,MagickPathExtent,
"%.20g",(
double)
1297 (generation % log_info->generations));
1302 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),MagickPathExtent);
1307 q+=(ptrdiff_t) FormatLocaleString(q,MagickPathExtent,
"%.20g",(
double)
1313 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,
1333static char *TranslateEvent(
const char *module,
const char *function,
1334 const size_t line,
const char *domain,
const char *event)
1361 exception=AcquireExceptionInfo();
1362 log_info=GetLogInfo(
"*",exception);
1363 exception=DestroyExceptionInfo(exception);
1364 seconds=GetMagickTime();
1365 elapsed_time=GetElapsedTime(&log_info->timer);
1366 user_time=GetUserTime(&log_info->timer);
1367 text=AcquireString(event);
1368 if (log_info->format == (
char *) NULL)
1370 extent=strlen(event)+MagickPathExtent;
1371 if (LocaleCompare(log_info->format,
"xml") == 0)
1374 timestamp[MagickTimeExtent];
1379 (void) FormatMagickTime(seconds,
sizeof(timestamp),timestamp);
1380 (void) FormatLocaleString(text,extent,
1382 " <timestamp>%s</timestamp>\n"
1383 " <elapsed-time>%lu:%02lu.%06lu</elapsed-time>\n"
1384 " <user-time>%0.3f</user-time>\n"
1385 " <process-id>%.20g</process-id>\n"
1386 " <thread-id>%.20g</thread-id>\n"
1387 " <module>%s</module>\n"
1388 " <function>%s</function>\n"
1389 " <line>%.20g</line>\n"
1390 " <domain>%s</domain>\n"
1391 " <event>%s</event>\n"
1392 "</entry>",timestamp,(
unsigned long) (elapsed_time/60.0),
1393 (
unsigned long) floor(fmod(elapsed_time,60.0)),(
unsigned long)
1394 (1000000.0*(elapsed_time-floor(elapsed_time))+0.5),user_time,
1395 (
double) getpid(),(
double) GetMagickThreadSignature(),module,function,
1396 (
double) line,domain,event);
1403 for (p=log_info->format; *p !=
'\0'; p++)
1406 if ((
size_t) (q-text+MagickPathExtent) >= extent)
1409 text=(
char *) ResizeQuantumMemory(text,extent,
sizeof(*text));
1410 if (text == (
char *) NULL)
1411 return((
char *) NULL);
1412 q=text+strlen(text);
1434 if ((*p ==
'\\') && (*(p+1) ==
'r'))
1440 if ((*p ==
'\\') && (*(p+1) ==
'n'))
1458 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),extent-(q-text));
1463 q+=(ptrdiff_t) CopyMagickString(q,domain,extent-(q-text));
1468 q+=(ptrdiff_t) CopyMagickString(q,event,extent-(q-text));
1473 q+=(ptrdiff_t) CopyMagickString(q,function,extent-(q-text));
1478 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(
double)
1479 GetMagickThreadSignature());
1484 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(
double)
1493 for (r=module+strlen(module)-1; r > module; r--)
1494 if (*r == *DirectorySeparator)
1499 q+=(ptrdiff_t) CopyMagickString(q,r,extent-(q-text));
1504 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),extent-(q-text));
1509 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.20g",(
double)
1515 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%lu:%02lu.%03lu",
1516 (
unsigned long) (elapsed_time/60.0),(
unsigned long) floor(fmod(
1517 elapsed_time,60.0)),(
unsigned long) (1000.0*(elapsed_time-floor(
1518 elapsed_time))+0.5));
1523 q+=(ptrdiff_t) FormatMagickTime(seconds,extent-(q-text),q);
1528 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%0.3fu",user_time);
1533 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,extent-(q-text));
1553MagickExport MagickBooleanType LogMagickEventList(
const LogEventType type,
1554 const char *module,
const char *function,
const size_t line,
const char *format,
1558 event[MagickPathExtent],
1573 exception=AcquireExceptionInfo();
1574 log_info=(LogInfo *) GetLogInfo(
"*",exception);
1575 exception=DestroyExceptionInfo(exception);
1577 ActivateSemaphoreInfo(&log_info->event_semaphore);
1578 LockSemaphoreInfo(log_info->event_semaphore);
1579 if ((log_info->event_mask & type) == 0)
1581 UnlockSemaphoreInfo(log_info->event_semaphore);
1584 domain=CommandOptionToMnemonic(MagickLogEventOptions,type);
1585#if defined(MAGICKCORE_HAVE_VSNPRINTF)
1586 n=vsnprintf(event,MagickPathExtent,format,operands);
1588 n=vsprintf(event,format,operands);
1591 event[MagickPathExtent-1]=
'\0';
1592 text=TranslateEvent(module,function,line,domain,event);
1593 if (text == (
char *) NULL)
1595 (void) ContinueTimer((TimerInfo *) &log_info->timer);
1596 UnlockSemaphoreInfo(log_info->event_semaphore);
1597 return(MagickFalse);
1599 if ((log_info->handler_mask & ConsoleHandler) != 0)
1601 (void) FormatLocaleFile(stderr,
"%s\n",text);
1602 (void) fflush(stderr);
1604 if ((log_info->handler_mask & DebugHandler) != 0)
1606#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1607 OutputDebugString(text);
1608 OutputDebugString(
"\n");
1611 if ((log_info->handler_mask & EventHandler) != 0)
1613#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1614 (void) NTReportEvent(text,MagickFalse);
1617 if ((log_info->handler_mask & FileHandler) != 0)
1622 file_info.st_size=0;
1623 if (log_info->file != (FILE *) NULL)
1624 (void) fstat(fileno(log_info->file),&file_info);
1625 if (file_info.st_size > (MagickOffsetType) log_info->limit)
1633 (void) FormatLocaleFile(log_info->file,
"</log>\n");
1634 (void) FormatLocaleFile(log_info->file,
"</logEntries>\n");
1635 (void) fclose(log_info->file);
1636 for (i=(ssize_t) log_info->generations-1; i > 0; i--)
1639 new_filename[MagickPathExtent],
1640 old_filename[MagickPathExtent];
1645 FormatLogFilename(log_info,i-1,old_filename);
1646 FormatLogFilename(log_info,i,new_filename);
1647 (void) rename_utf8(old_filename,new_filename);
1649 log_info->file=(FILE *) NULL;
1651 if (log_info->file == (FILE *) NULL)
1654 log_filename[MagickPathExtent];
1656 FormatLogFilename(log_info,0,log_filename);
1657 log_info->append=IsPathAccessible(log_filename);
1658 log_info->file=fopen_utf8(log_filename,
"ab");
1659 if (log_info->file == (FILE *) NULL)
1661 UnlockSemaphoreInfo(log_info->event_semaphore);
1662 return(MagickFalse);
1664 if (log_info->append == MagickFalse)
1666 (void) FormatLocaleFile(log_info->file,
"<?xml version=\"1.0\" "
1667 "encoding=\"UTF-8\" standalone=\"yes\"?>\n");
1668 (void) FormatLocaleFile(log_info->file,
"<logEntries>\n");
1670 (void) FormatLocaleFile(log_info->file,
"<log>\n");
1672 (void) FormatLocaleFile(log_info->file,
" <event>%s</event>\n",text);
1673 (void) fflush(log_info->file);
1675 if ((log_info->handler_mask & MethodHandler) != 0)
1677 if (log_info->method != (MagickLogMethod) NULL)
1678 log_info->method(type,text);
1680 if ((log_info->handler_mask & StdoutHandler) != 0)
1682 (void) FormatLocaleFile(stdout,
"%s\n",text);
1683 (void) fflush(stdout);
1685 if ((log_info->handler_mask & StderrHandler) != 0)
1687 (void) FormatLocaleFile(stderr,
"%s\n",text);
1688 (void) fflush(stderr);
1690 text=(
char *) RelinquishMagickMemory(text);
1691 (void) ContinueTimer((TimerInfo *) &log_info->timer);
1692 UnlockSemaphoreInfo(log_info->event_semaphore);
1696MagickExport MagickBooleanType LogMagickEvent(
const LogEventType type,
1697 const char *module,
const char *function,
const size_t line,
1698 const char *format,...)
1706 if (IsEventLogging() == MagickFalse)
1707 return(MagickFalse);
1708 va_start(operands,format);
1709 status=LogMagickEventList(type,module,function,line,format,operands);
1714#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
1738static LogHandlerType ParseLogHandlers(
const char *handlers)
1752 handler_mask=NoHandler;
1753 for (p=handlers; p != (
char *) NULL; p=strchr(p,
','))
1755 while ((*p !=
'\0') && ((isspace((
int) ((
unsigned char) *p)) != 0) ||
1758 for (i=0; *LogHandlers[i].name !=
'\0'; i++)
1760 length=strlen(LogHandlers[i].name);
1761 if (LocaleNCompare(p,LogHandlers[i].name,length) == 0)
1763 handler_mask=(LogHandlerType) (handler_mask | LogHandlers[i].handler);
1767 if (*LogHandlers[i].name ==
'\0')
1768 return(UndefinedHandler);
1770 return(handler_mask);
1798MagickExport LogEventType SetLogEventMask(
const char *events)
1812 event_mask=UndefinedEvents;
1813 exception=AcquireExceptionInfo();
1814 log_info=GetLogInfo(
"*",exception);
1815 exception=DestroyExceptionInfo(exception);
1816 if (log_info == (LogInfo *) NULL)
1818 option=ParseCommandOption(MagickLogEventOptions,MagickTrue,events);
1819 LockSemaphoreInfo(log_semaphore);
1820 event_mask=log_info->event_mask;
1822 log_info->event_mask=UndefinedEvents;
1824 log_info->event_mask=(LogEventType) option;
1825 CheckEventLogging();
1826 UnlockSemaphoreInfo(log_semaphore);
1852MagickExport
void SetLogFormat(
const char *format)
1860 exception=AcquireExceptionInfo();
1861 log_info=(LogInfo *) GetLogInfo(
"*",exception);
1862 exception=DestroyExceptionInfo(exception);
1863 if (log_info == (LogInfo *) NULL)
1865 LockSemaphoreInfo(log_semaphore);
1866 if (log_info->format != (
char *) NULL)
1867 log_info->format=DestroyString(log_info->format);
1868 log_info->format=ConstantString(format);
1869 UnlockSemaphoreInfo(log_semaphore);
1895MagickExport
void SetLogMethod(MagickLogMethod method)
1903 exception=AcquireExceptionInfo();
1904 log_info=(LogInfo *) GetLogInfo(
"*",exception);
1905 exception=DestroyExceptionInfo(exception);
1906 LockSemaphoreInfo(log_semaphore);
1907 log_info=(LogInfo *) GetValueFromLinkedList(log_cache,0);
1908 log_info->handler_mask=(LogHandlerType) (log_info->handler_mask |
1910 log_info->method=method;
1911 UnlockSemaphoreInfo(log_semaphore);
1938MagickExport
const char *SetLogName(
const char *name)
1940 if ((name != (
char *) NULL) && (*name !=
'\0'))
1941 (void) CopyMagickString(log_name,name,MagickPathExtent);