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 if (LoadLogCache(cache,(
const char *) GetStringInfoDatum(option),
298 GetStringInfoPath(option),0,exception) == MagickFalse)
300 option=(
const StringInfo *) GetNextValueInLinkedList(options);
302 options=DestroyConfigureOptions(options);
305 magick_unreferenced(filename);
310 for (i=0; i < (ssize_t) (
sizeof(LogMap)/
sizeof(*LogMap)); i++)
319 log_info=(LogInfo *) AcquireMagickMemory(
sizeof(*log_info));
320 if (log_info == (LogInfo *) NULL)
322 (void) ThrowMagickException(exception,GetMagickModule(),
323 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",p->filename);
326 (void) memset(log_info,0,
sizeof(*log_info));
327 log_info->path=ConstantString(
"[built-in]");
328 GetTimerInfo((TimerInfo *) &log_info->timer);
329 log_info->event_mask=p->event_mask;
330 log_info->handler_mask=p->handler_mask;
331 log_info->filename=ConstantString(p->filename);
332 log_info->format=ConstantString(p->format);
333 log_info->signature=MagickCoreSignature;
334 if (AppendValueToLinkedList(cache,log_info) == MagickFalse)
336 if (status == MagickFalse)
337 (void) ThrowMagickException(exception,GetMagickModule(),
338 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",log_info->name);
361MagickExport
void CloseMagickLog(
void)
369 if (IsEventLogging() == MagickFalse)
371 exception=AcquireExceptionInfo();
372 log_info=GetLogInfo(
"*",exception);
373 exception=DestroyExceptionInfo(exception);
374 if (log_info == (LogInfo *) NULL)
376 LockSemaphoreInfo(log_semaphore);
377 if ((log_info != (LogInfo *) NULL) && (log_info->file != (FILE *) NULL))
379 (void) FormatLocaleFile(log_info->file,
"</log>\n");
380 (void) fclose(log_info->file);
381 log_info->file=(FILE *) NULL;
383 UnlockSemaphoreInfo(log_semaphore);
404MagickExport LogEventType GetLogEventMask(
void)
412 exception=AcquireExceptionInfo();
413 log_info=GetLogInfo(
"*",exception);
414 exception=DestroyExceptionInfo(exception);
415 if (log_info == (
const LogInfo *) NULL)
417 return(log_info->event_mask);
445static LogInfo *GetLogInfo(
const char *name,ExceptionInfo *exception)
453 assert(exception != (ExceptionInfo *) NULL);
454 if (IsLogCacheInstantiated(exception) == MagickFalse)
455 return((LogInfo *) NULL);
459 log_info=(LogInfo *) NULL;
460 LockSemaphoreInfo(log_semaphore);
461 p=GetHeadElementInLinkedList(log_cache);
462 if ((name == (
const char *) NULL) || (LocaleCompare(name,
"*") == 0))
464 if (p != (ElementInfo *) NULL)
465 log_info=(LogInfo *) p->value;
466 UnlockSemaphoreInfo(log_semaphore);
469 while (p != (ElementInfo *) NULL)
471 log_info=(LogInfo* ) p->value;
472 if (LocaleCompare(name,log_info->name) == 0)
476 if (p == (ElementInfo *) NULL)
477 log_info=(LogInfo *) NULL;
479 SetHeadElementInLinkedList(log_cache,p);
480 UnlockSemaphoreInfo(log_semaphore);
511#if defined(__cplusplus) || defined(c_plusplus)
515static int LogInfoCompare(
const void *x,
const void *y)
521 p=(
const LogInfo **) x,
522 q=(
const LogInfo **) y;
523 if (LocaleCompare((*p)->path,(*q)->path) == 0)
524 return(LocaleCompare((*p)->name,(*q)->name));
525 return(LocaleCompare((*p)->path,(*q)->path));
528#if defined(__cplusplus) || defined(c_plusplus)
532MagickExport
const LogInfo **GetLogInfoList(
const char *pattern,
533 size_t *number_preferences,ExceptionInfo *exception)
544 assert(pattern != (
char *) NULL);
545 assert(number_preferences != (
size_t *) NULL);
546 if (IsEventLogging() != MagickFalse)
547 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
548 *number_preferences=0;
549 if (IsLogCacheInstantiated(exception) == MagickFalse)
550 return((
const LogInfo **) NULL);
551 preferences=(
const LogInfo **) AcquireQuantumMemory((
size_t)
552 GetNumberOfElementsInLinkedList(log_cache)+1UL,
sizeof(*preferences));
553 if (preferences == (
const LogInfo **) NULL)
554 return((
const LogInfo **) NULL);
555 LockSemaphoreInfo(log_semaphore);
556 p=GetHeadElementInLinkedList(log_cache);
557 for (i=0; p != (ElementInfo *) NULL; )
562 log_info=(
const LogInfo *) p->value;
563 if ((log_info->stealth == MagickFalse) &&
564 (GlobExpression(log_info->name,pattern,MagickFalse) != MagickFalse))
565 preferences[i++]=log_info;
568 UnlockSemaphoreInfo(log_semaphore);
570 preferences=(
const LogInfo **) RelinquishMagickMemory((
void*) preferences);
573 qsort((
void *) preferences,(
size_t) i,
sizeof(*preferences),LogInfoCompare);
574 preferences[i]=(LogInfo *) NULL;
576 *number_preferences=(size_t) i;
608#if defined(__cplusplus) || defined(c_plusplus)
612static int LogCompare(
const void *x,
const void *y)
620 return(LocaleCompare(*p,*q));
623#if defined(__cplusplus) || defined(c_plusplus)
627MagickExport
char **GetLogList(
const char *pattern,
size_t *number_preferences,
628 ExceptionInfo *exception)
639 assert(pattern != (
char *) NULL);
640 assert(number_preferences != (
size_t *) NULL);
641 if (IsEventLogging() != MagickFalse)
642 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
643 *number_preferences=0;
644 if (IsLogCacheInstantiated(exception) == MagickFalse)
645 return((
char **) NULL);
646 preferences=(
char **) AcquireQuantumMemory((
size_t)
647 GetNumberOfElementsInLinkedList(log_cache)+1UL,
sizeof(*preferences));
648 if (preferences == (
char **) NULL)
649 return((
char **) NULL);
650 LockSemaphoreInfo(log_semaphore);
651 p=GetHeadElementInLinkedList(log_cache);
652 for (i=0; p != (ElementInfo *) NULL; )
657 log_info=(
const LogInfo *) p->value;
658 if ((log_info->stealth == MagickFalse) &&
659 (GlobExpression(log_info->name,pattern,MagickFalse) != MagickFalse))
660 preferences[i++]=ConstantString(log_info->name);
663 UnlockSemaphoreInfo(log_semaphore);
665 preferences=(
char **) RelinquishMagickMemory(preferences);
668 qsort((
void *) preferences,(
size_t) i,
sizeof(*preferences),LogCompare);
669 preferences[i]=(
char *) NULL;
671 *number_preferences=(size_t) i;
693MagickExport
const char *GetLogName(
void)
722static inline void CheckEventLogging(
void)
727 if (IsLinkedListEmpty(log_cache) != MagickFalse)
728 event_logging=MagickFalse;
734 p=GetHeadElementInLinkedList(log_cache);
735 event_logging=(p != (ElementInfo *) NULL) &&
736 (((LogInfo *) p->value)->event_mask != NoEvents) ?
737 MagickTrue: MagickFalse;
741static MagickBooleanType IsLogCacheInstantiated(ExceptionInfo *exception)
743 if (log_cache == (LinkedListInfo *) NULL)
746 ActivateSemaphoreInfo(&log_semaphore);
747 LockSemaphoreInfo(log_semaphore);
748 if (log_cache == (LinkedListInfo *) NULL)
750 log_cache=AcquireLogCache(LogFilename,exception);
753 UnlockSemaphoreInfo(log_semaphore);
755 return(log_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
777MagickExport MagickBooleanType IsEventLogging(
void)
779 return(event_logging);
806MagickExport MagickBooleanType ListLogInfo(FILE *file,ExceptionInfo *exception)
808#define MegabytesToBytes(value) ((MagickSizeType) (value)*1024*1024)
825 if (file == (
const FILE *) NULL)
827 log_info=GetLogInfoList(
"*",&number_aliases,exception);
828 if (log_info == (
const LogInfo **) NULL)
831 path=(
const char *) NULL;
832 for (i=0; i < (ssize_t) number_aliases; i++)
835 limit[MagickPathExtent];
837 if (log_info[i]->stealth != MagickFalse)
839 if ((path == (
const char *) NULL) ||
840 (LocaleCompare(path,log_info[i]->path) != 0))
842 if (log_info[i]->path != (
char *) NULL)
843 (void) FormatLocaleFile(file,
"\nPath: %s\nHandler: ",
845 for (j=0; j < (ssize_t) (8*
sizeof(LogHandlerType)); j++)
850 if (*LogHandlers[j].name ==
'\0')
854 if (((
size_t) log_info[i]->handler_mask & mask) != 0)
855 (void) FormatLocaleFile(file,
"%s ",LogHandlers[j].name);
857 (void) FormatLocaleFile(file,
"\n\n");
859 (void) FormatLocaleFile(file,
860 "Generations Limit Filename\n");
861 (void) FormatLocaleFile(file,
"---------------------------------------------"
862 "----------------------------------\n");
863 (void) FormatLocaleFile(file,
"%g ",(
double) log_info[i]->generations);
864 (void) CopyMagickString(limit,
"unlimited",MagickPathExtent);
865 if (log_info[i]->limit > 0)
866 (void) FormatMagickSize(log_info[i]->limit,MagickTrue,
"B",
867 MagickFormatExtent,limit);
868 (void) FormatLocaleFile(file,
" %9s",limit);
869 if (log_info[i]->filename != (
char *) NULL)
870 (void) FormatLocaleFile(file,
" %s",log_info[i]->filename);
871 (void) FormatLocaleFile(file,
"\n");
872 if (log_info[i]->format != (
char *) NULL)
873 (void) FormatLocaleFile(file,
" Format: %s\n",log_info[i]->format);
874 (void) FormatLocaleFile(file,
"\n");
875 path=log_info[i]->path;
878 log_info=(
const LogInfo **) RelinquishMagickMemory((
void *) log_info);
882#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
913static MagickBooleanType LoadLogCache(LinkedListInfo *cache,
const char *xml,
914 const char *filename,
const size_t depth,ExceptionInfo *exception)
917 keyword[MagickPathExtent],
924 *log_info = (LogInfo *) NULL;
935 if (xml == (
const char *) NULL)
938 token=AcquireString(xml);
939 extent=strlen(token)+MagickPathExtent;
940 for (q=(
const char *) xml; *q !=
'\0'; )
945 if (SkipXMLComment(&q) == MagickFalse)
947 (void) ThrowMagickException(exception,GetMagickModule(),
948 ConfigureError,
"UnterminatedComment",
"`%s'",filename);
952 (void) GetNextToken(q,&q,extent,token);
955 (void) CopyMagickString(keyword,token,MagickPathExtent);
956 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
958 if (SkipXMLDocType(&q) == MagickFalse)
963 (void) ThrowMagickException(exception,GetMagickModule(),
964 ConfigureError,
"UnterminatedDOCTYPE",
"`%s'",filename);
970 if (LocaleCompare(keyword,
"<include") == 0)
975 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
977 (void) CopyMagickString(keyword,token,MagickPathExtent);
978 (void) GetNextToken(q,&q,extent,token);
981 (void) GetNextToken(q,&q,extent,token);
982 if (LocaleCompare(keyword,
"file") == 0)
984 if (depth >= MagickMaxRecursionDepth)
985 (void) ThrowMagickException(exception,GetMagickModule(),
986 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
990 path[MagickPathExtent],
993 GetPathComponent(filename,HeadPath,path);
995 (void) ConcatenateMagickString(path,DirectorySeparator,
997 if (*token == *DirectorySeparator)
998 (void) CopyMagickString(path,token,MagickPathExtent);
1000 (
void) ConcatenateMagickString(path,token,MagickPathExtent);
1001 file_xml=FileToXML(path,~0UL);
1002 if (file_xml != (
char *) NULL)
1004 if (LoadLogCache(cache,file_xml,path,depth+1,exception) == MagickFalse)
1006 file_xml=DestroyString(file_xml);
1007 if (status == MagickFalse)
1013 if (status == MagickFalse)
1017 if (LocaleCompare(keyword,
"<logmap>") == 0)
1022 log_info=(LogInfo *) AcquireCriticalMemory(
sizeof(*log_info));
1023 (void) memset(log_info,0,
sizeof(*log_info));
1024 log_info->path=ConstantString(filename);
1025 GetTimerInfo((TimerInfo *) &log_info->timer);
1026 log_info->signature=MagickCoreSignature;
1029 if (log_info == (LogInfo *) NULL)
1031 if (LocaleCompare(keyword,
"</logmap>") == 0)
1033 status=AppendValueToLinkedList(cache,log_info);
1034 if (status == MagickFalse)
1035 (void) ThrowMagickException(exception,GetMagickModule(),
1036 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",filename);
1037 log_info=(LogInfo *) NULL;
1040 (void) GetNextToken(q,(
const char **) NULL,extent,token);
1043 (void) GetNextToken(q,&q,extent,token);
1044 (void) GetNextToken(q,&q,extent,token);
1050 if (LocaleCompare((
char *) keyword,
"events") == 0)
1052 log_info->event_mask=(LogEventType) (log_info->event_mask |
1053 ParseCommandOption(MagickLogEventOptions,MagickTrue,token));
1061 if (LocaleCompare((
char *) keyword,
"filename") == 0)
1063 if (log_info->filename != (
char *) NULL)
1064 log_info->filename=(
char *)
1065 RelinquishMagickMemory(log_info->filename);
1066 log_info->filename=ConstantString(token);
1069 if (LocaleCompare((
char *) keyword,
"format") == 0)
1071 if (log_info->format != (
char *) NULL)
1072 log_info->format=(
char *)
1073 RelinquishMagickMemory(log_info->format);
1074 log_info->format=ConstantString(token);
1082 if (LocaleCompare((
char *) keyword,
"generations") == 0)
1084 if (LocaleCompare(token,
"unlimited") == 0)
1086 log_info->generations=(~0UL);
1089 log_info->generations=StringToUnsignedLong(token);
1097 if (LocaleCompare((
char *) keyword,
"limit") == 0)
1099 if (LocaleCompare(token,
"unlimited") == 0)
1101 log_info->limit=(~0UL);
1104 log_info->limit=StringToMagickSizeType(token,100.0);
1105 if (log_info->limit < 1024)
1106 log_info->limit=1024*1024*StringToUnsignedLong(token);
1114 if (LocaleCompare((
char *) keyword,
"output") == 0)
1116 log_info->handler_mask=(LogHandlerType)
1117 (log_info->handler_mask | ParseLogHandlers(token));
1126 token=DestroyString(token);
1127 if (cache == (LinkedListInfo *) NULL)
1128 return(MagickFalse);
1151MagickPrivate MagickBooleanType LogComponentGenesis(
void)
1157 log_semaphore=AcquireSemaphoreInfo();
1158 exception=AcquireExceptionInfo();
1159 (void) GetLogInfo(
"*",exception);
1160 exception=DestroyExceptionInfo(exception);
1183static void *DestroyLogElement(
void *log_info)
1188 p=(LogInfo *) log_info;
1189 if (p->file != (FILE *) NULL)
1191 (void) FormatLocaleFile(p->file,
"</log>\n");
1192 (void) fclose(p->file);
1193 p->file=(FILE *) NULL;
1195 if (p->format != (
char *) NULL)
1196 p->format=DestroyString(p->format);
1197 if (p->path != (
char *) NULL)
1198 p->path=DestroyString(p->path);
1199 if (p->filename != (
char *) NULL)
1200 p->filename=DestroyString(p->filename);
1202 RelinquishSemaphoreInfo(&p->event_semaphore);
1203 p=(LogInfo *) RelinquishMagickMemory(p);
1204 return((
void *) NULL);
1207MagickPrivate
void LogComponentTerminus(
void)
1210 ActivateSemaphoreInfo(&log_semaphore);
1211 LockSemaphoreInfo(log_semaphore);
1212 if (log_cache != (LinkedListInfo *) NULL)
1213 log_cache=DestroyLinkedList(log_cache,DestroyLogElement);
1214 event_logging=MagickFalse;
1215 UnlockSemaphoreInfo(log_semaphore);
1216 RelinquishSemaphoreInfo(&log_semaphore);
1253static void FormatLogFilename(
const LogInfo *log_info,
const ssize_t generation,
1265 assert(log_info != (LogInfo *) NULL);
1267 for (p=log_info->filename; *p !=
'\0'; p++)
1296 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),MagickPathExtent);
1301 if (log_info->generations == 0)
1303 (void) CopyMagickString(q,
"0",MagickPathExtent);
1307 q+=(ptrdiff_t) FormatLocaleString(q,MagickPathExtent,
"%.17g",(
double)
1308 (generation % log_info->generations));
1313 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),MagickPathExtent);
1318 q+=(ptrdiff_t) FormatLocaleString(q,MagickPathExtent,
"%.17g",(
double)
1324 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,
1344static char *TranslateEvent(
const char *module,
const char *function,
1345 const size_t line,
const char *domain,
const char *event)
1372 exception=AcquireExceptionInfo();
1373 log_info=GetLogInfo(
"*",exception);
1374 exception=DestroyExceptionInfo(exception);
1375 text=AcquireString(event);
1376 if (log_info == (LogInfo *) NULL)
1378 seconds=GetMagickTime();
1379 elapsed_time=GetElapsedTime(&log_info->timer);
1380 user_time=GetUserTime(&log_info->timer);
1381 if (log_info->format == (
char *) NULL)
1383 extent=strlen(event)+MagickPathExtent;
1384 if (LocaleCompare(log_info->format,
"xml") == 0)
1387 timestamp[MagickTimeExtent];
1392 (void) FormatMagickTime(seconds,
sizeof(timestamp),timestamp);
1393 (void) FormatLocaleString(text,extent,
1395 " <timestamp>%s</timestamp>\n"
1396 " <elapsed-time>%lu:%02lu.%06lu</elapsed-time>\n"
1397 " <user-time>%0.3f</user-time>\n"
1398 " <process-id>%.17g</process-id>\n"
1399 " <thread-id>%.17g</thread-id>\n"
1400 " <module>%s</module>\n"
1401 " <function>%s</function>\n"
1402 " <line>%.17g</line>\n"
1403 " <domain>%s</domain>\n"
1404 " <event>%s</event>\n"
1405 "</entry>",timestamp,(
unsigned long) (elapsed_time/60.0),
1406 (
unsigned long) floor(fmod(elapsed_time,60.0)),(
unsigned long)
1407 (1000000.0*(elapsed_time-floor(elapsed_time))+0.5),user_time,
1408 (
double) getpid(),(
double) GetMagickThreadSignature(),module,function,
1409 (
double) line,domain,event);
1416 for (p=log_info->format; *p !=
'\0'; p++)
1419 if ((
size_t) (q-text+MagickPathExtent) >= extent)
1422 text=(
char *) ResizeQuantumMemory(text,extent,
sizeof(*text));
1423 if (text == (
char *) NULL)
1424 return((
char *) NULL);
1425 q=text+strlen(text);
1447 if ((*p ==
'\\') && (*(p+1) ==
'r'))
1453 if ((*p ==
'\\') && (*(p+1) ==
'n'))
1471 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),extent-(q-text));
1476 q+=(ptrdiff_t) CopyMagickString(q,domain,extent-(q-text));
1481 q+=(ptrdiff_t) CopyMagickString(q,event,extent-(q-text));
1486 q+=(ptrdiff_t) CopyMagickString(q,function,extent-(q-text));
1491 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.17g",(
double)
1492 GetMagickThreadSignature());
1497 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.17g",(
double)
1506 for (r=module+strlen(module)-1; r > module; r--)
1507 if (*r == *DirectorySeparator)
1512 q+=(ptrdiff_t) CopyMagickString(q,r,extent-(q-text));
1517 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),extent-(q-text));
1522 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%.17g",(
double)
1528 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%lu:%02lu.%03lu",
1529 (
unsigned long) (elapsed_time/60.0),(
unsigned long) floor(fmod(
1530 elapsed_time,60.0)),(
unsigned long) (1000.0*(elapsed_time-floor(
1531 elapsed_time))+0.5));
1536 q+=(ptrdiff_t) FormatMagickTime(seconds,extent-(q-text),q);
1541 q+=(ptrdiff_t) FormatLocaleString(q,extent-(q-text),
"%0.3fu",user_time);
1546 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,extent-(q-text));
1566MagickExport MagickBooleanType LogMagickEventList(
const LogEventType type,
1567 const char *module,
const char *function,
const size_t line,
const char *format,
1571 event[MagickPathExtent],
1586 exception=AcquireExceptionInfo();
1587 log_info=(LogInfo *) GetLogInfo(
"*",exception);
1588 exception=DestroyExceptionInfo(exception);
1589 if (log_info == (LogInfo *) NULL)
1590 return(MagickFalse);
1592 ActivateSemaphoreInfo(&log_info->event_semaphore);
1593 LockSemaphoreInfo(log_info->event_semaphore);
1594 if ((log_info->event_mask & type) == 0)
1596 UnlockSemaphoreInfo(log_info->event_semaphore);
1599 domain=CommandOptionToMnemonic(MagickLogEventOptions,type);
1600 n=vsnprintf(event,MagickPathExtent,format,operands);
1602 event[MagickPathExtent-1]=
'\0';
1603 text=TranslateEvent(module,function,line,domain,event);
1604 if (text == (
char *) NULL)
1606 (void) ContinueTimer((TimerInfo *) &log_info->timer);
1607 UnlockSemaphoreInfo(log_info->event_semaphore);
1608 return(MagickFalse);
1610 if ((log_info->handler_mask & ConsoleHandler) != 0)
1612 (void) FormatLocaleFile(stderr,
"%s\n",text);
1613 (void) fflush(stderr);
1615 if ((log_info->handler_mask & DebugHandler) != 0)
1617#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1618 OutputDebugString(text);
1619 OutputDebugString(
"\n");
1622 if ((log_info->handler_mask & EventHandler) != 0)
1624#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1625 (void) NTReportEvent(text,MagickFalse);
1628 if ((log_info->handler_mask & FileHandler) != 0)
1633 file_info.st_size=0;
1634 if (log_info->file != (FILE *) NULL)
1635 (void) fstat(fileno(log_info->file),&file_info);
1636 if (file_info.st_size > (MagickOffsetType) log_info->limit)
1644 (void) FormatLocaleFile(log_info->file,
"</log>\n");
1645 (void) FormatLocaleFile(log_info->file,
"</logEntries>\n");
1646 (void) fclose(log_info->file);
1647 for (i=(ssize_t) log_info->generations-1; i > 0; i--)
1650 new_filename[MagickPathExtent],
1651 old_filename[MagickPathExtent];
1656 FormatLogFilename(log_info,i-1,old_filename);
1657 FormatLogFilename(log_info,i,new_filename);
1658 (void) rename_utf8(old_filename,new_filename);
1660 log_info->file=(FILE *) NULL;
1662 if (log_info->file == (FILE *) NULL)
1665 log_filename[MagickPathExtent];
1667 FormatLogFilename(log_info,0,log_filename);
1668 log_info->append=IsPathAccessible(log_filename);
1669 log_info->file=fopen_utf8(log_filename,
"ab");
1670 if (log_info->file == (FILE *) NULL)
1672 UnlockSemaphoreInfo(log_info->event_semaphore);
1673 return(MagickFalse);
1675 if (log_info->append == MagickFalse)
1677 (void) FormatLocaleFile(log_info->file,
"<?xml version=\"1.0\" "
1678 "encoding=\"UTF-8\" standalone=\"yes\"?>\n");
1679 (void) FormatLocaleFile(log_info->file,
"<logEntries>\n");
1681 (void) FormatLocaleFile(log_info->file,
"<log>\n");
1683 (void) FormatLocaleFile(log_info->file,
" <event>%s</event>\n",text);
1684 (void) fflush(log_info->file);
1686 if ((log_info->handler_mask & MethodHandler) != 0)
1688 if (log_info->method != (MagickLogMethod) NULL)
1689 log_info->method(type,text);
1691 if ((log_info->handler_mask & StdoutHandler) != 0)
1693 (void) FormatLocaleFile(stdout,
"%s\n",text);
1694 (void) fflush(stdout);
1696 if ((log_info->handler_mask & StderrHandler) != 0)
1698 (void) FormatLocaleFile(stderr,
"%s\n",text);
1699 (void) fflush(stderr);
1701 text=(
char *) RelinquishMagickMemory(text);
1702 (void) ContinueTimer((TimerInfo *) &log_info->timer);
1703 UnlockSemaphoreInfo(log_info->event_semaphore);
1707MagickExport MagickBooleanType LogMagickEvent(
const LogEventType type,
1708 const char *module,
const char *function,
const size_t line,
1709 const char *format,...)
1717 if (IsEventLogging() == MagickFalse)
1718 return(MagickFalse);
1719 va_start(operands,format);
1720 status=LogMagickEventList(type,module,function,line,format,operands);
1725#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
1749static LogHandlerType ParseLogHandlers(
const char *handlers)
1763 handler_mask=NoHandler;
1764 for (p=handlers; p != (
char *) NULL; p=strchr(p,
','))
1766 while ((*p !=
'\0') && ((isspace((
int) ((
unsigned char) *p)) != 0) ||
1769 for (i=0; *LogHandlers[i].name !=
'\0'; i++)
1771 length=strlen(LogHandlers[i].name);
1772 if (LocaleNCompare(p,LogHandlers[i].name,length) == 0)
1774 handler_mask=(LogHandlerType) (handler_mask | LogHandlers[i].handler);
1778 if (*LogHandlers[i].name ==
'\0')
1779 return(UndefinedHandler);
1781 return(handler_mask);
1809MagickExport LogEventType SetLogEventMask(
const char *events)
1823 event_mask=UndefinedEvents;
1824 exception=AcquireExceptionInfo();
1825 log_info=GetLogInfo(
"*",exception);
1826 exception=DestroyExceptionInfo(exception);
1827 if (log_info == (LogInfo *) NULL)
1829 option=ParseCommandOption(MagickLogEventOptions,MagickTrue,events);
1830 LockSemaphoreInfo(log_semaphore);
1831 event_mask=log_info->event_mask;
1833 log_info->event_mask=UndefinedEvents;
1835 log_info->event_mask=(LogEventType) option;
1836 CheckEventLogging();
1837 UnlockSemaphoreInfo(log_semaphore);
1863MagickExport
void SetLogFormat(
const char *format)
1871 exception=AcquireExceptionInfo();
1872 log_info=(LogInfo *) GetLogInfo(
"*",exception);
1873 exception=DestroyExceptionInfo(exception);
1874 if (log_info == (LogInfo *) NULL)
1876 LockSemaphoreInfo(log_semaphore);
1877 if (log_info->format != (
char *) NULL)
1878 log_info->format=DestroyString(log_info->format);
1879 log_info->format=ConstantString(format);
1880 UnlockSemaphoreInfo(log_semaphore);
1906MagickExport
void SetLogMethod(MagickLogMethod method)
1914 exception=AcquireExceptionInfo();
1915 log_info=(LogInfo *) GetLogInfo(
"*",exception);
1916 exception=DestroyExceptionInfo(exception);
1917 if (log_info == (LogInfo *) NULL)
1919 LockSemaphoreInfo(log_semaphore);
1920 log_info=(LogInfo *) GetValueFromLinkedList(log_cache,0);
1921 log_info->handler_mask=(LogHandlerType) (log_info->handler_mask |
1923 log_info->method=method;
1924 UnlockSemaphoreInfo(log_semaphore);
1951MagickExport
const char *SetLogName(
const char *name)
1953 if ((name != (
char *) NULL) && (*name !=
'\0'))
1954 (void) CopyMagickString(log_name,name,MagickPathExtent);