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/semaphore.h"
57#include "MagickCore/timer.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-private.h"
63#include "MagickCore/token.h"
64#include "MagickCore/utility.h"
65#include "MagickCore/utility-private.h"
66#include "MagickCore/version.h"
67#include "MagickCore/xml-tree.h"
68#include "MagickCore/xml-tree-private.h"
73#define LogFilename "log.xml"
80 UndefinedHandler = 0x0000,
82 ConsoleHandler = 0x0001,
83 StdoutHandler = 0x0002,
84 StderrHandler = 0x0004,
86 DebugHandler = 0x0010,
87 EventHandler = 0x0020,
88 MethodHandler = 0x0040
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 }
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";
216static MagickBooleanType
217 event_logging = MagickFalse;
225#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
227 ParseLogHandlers(
const char *) magick_attribute((__pure__));
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,
283 cache=NewLinkedList(0);
285#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
293 options=GetConfigureOptions(filename,exception);
294 option=(
const StringInfo *) GetNextValueInLinkedList(options);
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 LockSemaphoreInfo(log_semaphore);
375 if (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);
452 if (IsLogCacheInstantiated(exception) == MagickFalse)
458 LockSemaphoreInfo(log_semaphore);
459 p=GetHeadElementInLinkedList(log_cache);
460 if ((name == (
const char *) NULL) || (LocaleCompare(name,
"*") == 0))
464 UnlockSemaphoreInfo(log_semaphore);
470 if (LocaleCompare(name,log_info->name) == 0)
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)
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,
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);
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,
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);
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);
734 (((
LogInfo *) p->value)->event_mask != NoEvents) ?
735 MagickTrue: MagickFalse;
739static MagickBooleanType IsLogCacheInstantiated(
ExceptionInfo *exception)
744 ActivateSemaphoreInfo(&log_semaphore);
745 LockSemaphoreInfo(log_semaphore);
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++)
832 if (log_info[i]->stealth != MagickFalse)
834 if ((path == (
const char *) NULL) ||
835 (LocaleCompare(path,log_info[i]->path) != 0))
840 if (log_info[i]->path != (
char *) NULL)
841 (
void) FormatLocaleFile(file,
"\nPath: %s\n\n",log_info[i]->path);
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)
854 (void) FormatLocaleFile(file,
"%s ",LogHandlers[j].name);
855 length+=strlen(LogHandlers[j].name);
858 for (j=(ssize_t) length; j <= 12; j++)
859 (
void) FormatLocaleFile(file,
" ");
860 (void) FormatLocaleFile(file,
" Generations Limit Format\n");
861 (void) FormatLocaleFile(file,
"-----------------------------------------"
862 "--------------------------------------\n");
864 path=log_info[i]->path;
865 if (log_info[i]->filename != (
char *) NULL)
867 (void) FormatLocaleFile(file,
"%s",log_info[i]->filename);
868 for (j=(ssize_t) strlen(log_info[i]->filename); j <= 16; j++)
869 (
void) FormatLocaleFile(file,
" ");
871 (void) FormatLocaleFile(file,
"%9g ",(
double) log_info[i]->generations);
872 (void) FormatLocaleFile(file,
"%8g ",(
double) log_info[i]->limit);
873 if (log_info[i]->format != (
char *) NULL)
874 (
void) FormatLocaleFile(file,
"%s",log_info[i]->format);
875 (void) FormatLocaleFile(file,
"\n");
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],
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);
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=StringToUnsignedLong(token);
1112 if (LocaleCompare((
char *) keyword,
"output") == 0)
1114 log_info->handler_mask=(LogHandlerType)
1115 (log_info->handler_mask | ParseLogHandlers(token));
1124 token=DestroyString(token);
1126 return(MagickFalse);
1149MagickPrivate MagickBooleanType LogComponentGenesis(
void)
1155 log_semaphore=AcquireSemaphoreInfo();
1156 exception=AcquireExceptionInfo();
1157 (void) GetLogInfo(
"*",exception);
1158 exception=DestroyExceptionInfo(exception);
1181static void *DestroyLogElement(
void *log_info)
1187 if (p->file != (FILE *) NULL)
1189 (void) FormatLocaleFile(p->file,
"</log>\n");
1190 (void) fclose(p->file);
1191 p->file=(FILE *) NULL;
1193 if (p->format != (
char *) NULL)
1194 p->format=DestroyString(p->format);
1195 if (p->path != (
char *) NULL)
1196 p->path=DestroyString(p->path);
1197 if (p->filename != (
char *) NULL)
1198 p->filename=DestroyString(p->filename);
1200 RelinquishSemaphoreInfo(&p->event_semaphore);
1201 p=(
LogInfo *) RelinquishMagickMemory(p);
1202 return((
void *) NULL);
1205MagickPrivate
void LogComponentTerminus(
void)
1208 ActivateSemaphoreInfo(&log_semaphore);
1209 LockSemaphoreInfo(log_semaphore);
1211 log_cache=DestroyLinkedList(log_cache,DestroyLogElement);
1212 event_logging=MagickFalse;
1213 UnlockSemaphoreInfo(log_semaphore);
1214 RelinquishSemaphoreInfo(&log_semaphore);
1251static char *TranslateEvent(
const char *module,
const char *function,
1252 const size_t line,
const char *domain,
const char *event)
1279 exception=AcquireExceptionInfo();
1280 log_info=GetLogInfo(
"*",exception);
1281 exception=DestroyExceptionInfo(exception);
1282 seconds=GetMagickTime();
1283 elapsed_time=GetElapsedTime(&log_info->timer);
1284 user_time=GetUserTime(&log_info->timer);
1285 text=AcquireString(event);
1286 if (log_info->format == (
char *) NULL)
1288 extent=strlen(event)+MagickPathExtent;
1289 if (LocaleCompare(log_info->format,
"xml") == 0)
1292 timestamp[MagickTimeExtent];
1297 (void) FormatMagickTime(seconds,
sizeof(timestamp),timestamp);
1298 (void) FormatLocaleString(text,extent,
1300 " <timestamp>%s</timestamp>\n"
1301 " <elapsed-time>%lu:%02lu.%06lu</elapsed-time>\n"
1302 " <user-time>%0.3f</user-time>\n"
1303 " <process-id>%.20g</process-id>\n"
1304 " <thread-id>%.20g</thread-id>\n"
1305 " <module>%s</module>\n"
1306 " <function>%s</function>\n"
1307 " <line>%.20g</line>\n"
1308 " <domain>%s</domain>\n"
1309 " <event>%s</event>\n"
1310 "</entry>",timestamp,(
unsigned long) (elapsed_time/60.0),
1311 (
unsigned long) floor(fmod(elapsed_time,60.0)),(
unsigned long)
1312 (1000000.0*(elapsed_time-floor(elapsed_time))+0.5),user_time,
1313 (
double) getpid(),(double) GetMagickThreadSignature(),module,function,
1314 (double) line,domain,event);
1321 for (p=log_info->format; *p !=
'\0'; p++)
1324 if ((
size_t) (q-text+MagickPathExtent) >= extent)
1326 extent+=MagickPathExtent;
1327 text=(
char *) ResizeQuantumMemory(text,extent+MagickPathExtent,
1329 if (text == (
char *) NULL)
1330 return((
char *) NULL);
1331 q=text+strlen(text);
1354 if ((*p ==
'\\') && (*(p+1) ==
'r'))
1360 if ((*p ==
'\\') && (*(p+1) ==
'n'))
1378 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),extent);
1383 q+=(ptrdiff_t) CopyMagickString(q,domain,extent);
1388 q+=(ptrdiff_t) CopyMagickString(q,event,extent);
1393 q+=(ptrdiff_t) CopyMagickString(q,function,extent);
1398 if (log_info->generations == 0)
1400 (void) CopyMagickString(q,
"0",extent);
1404 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%.20g",(
double) (log_info->generation %
1405 log_info->generations));
1410 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%.20g",(
double)
1411 GetMagickThreadSignature());
1416 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%.20g",(
double) line);
1424 for (r=module+strlen(module)-1; r >
module; r--)
1425 if (*r == *DirectorySeparator)
1430 q+=(ptrdiff_t) CopyMagickString(q,r,extent);
1435 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),extent);
1440 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%.20g",(
double) getpid());
1445 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%lu:%02lu.%03lu",(
unsigned long)
1446 (elapsed_time/60.0),(
unsigned long) floor(fmod(elapsed_time,60.0)),
1447 (
unsigned long) (1000.0*(elapsed_time-floor(elapsed_time))+0.5));
1452 q+=(ptrdiff_t) FormatMagickTime(seconds,extent,q);
1457 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%0.3fu",user_time);
1462 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,extent);
1482static char *TranslateFilename(
const LogInfo *log_info)
1499 assert(log_info != (
LogInfo *) NULL);
1500 assert(log_info->filename != (
char *) NULL);
1501 filename=AcquireString((
char *) NULL);
1502 extent=MagickPathExtent;
1504 for (p=log_info->filename; *p !=
'\0'; p++)
1507 if ((
size_t) (q-filename+MagickPathExtent) >= extent)
1509 extent+=MagickPathExtent;
1510 filename=(
char *) ResizeQuantumMemory(filename,extent+MagickPathExtent,
1512 if (filename == (
char *) NULL)
1513 return((
char *) NULL);
1514 q=filename+strlen(filename);
1543 q+=(ptrdiff_t) CopyMagickString(q,GetClientName(),extent);
1548 if (log_info->generations == 0)
1550 (void) CopyMagickString(q,
"0",extent);
1554 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%.20g",(
double) (log_info->generation %
1555 log_info->generations));
1560 q+=(ptrdiff_t) CopyMagickString(q,GetLogName(),extent);
1565 q+=(ptrdiff_t) FormatLocaleString(q,extent,
"%.20g",(
double) getpid());
1570 q+=(ptrdiff_t) CopyMagickString(q,MagickLibVersionText,extent);
1590MagickExport MagickBooleanType LogMagickEventList(
const LogEventType type,
1591 const char *module,
const char *function,
const size_t line,
const char *format,
1595 event[MagickPathExtent],
1610 exception=AcquireExceptionInfo();
1611 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1612 exception=DestroyExceptionInfo(exception);
1614 ActivateSemaphoreInfo(&log_info->event_semaphore);
1615 LockSemaphoreInfo(log_info->event_semaphore);
1616 if ((log_info->event_mask & type) == 0)
1618 UnlockSemaphoreInfo(log_info->event_semaphore);
1621 domain=CommandOptionToMnemonic(MagickLogEventOptions,type);
1622#if defined(MAGICKCORE_HAVE_VSNPRINTF)
1623 n=vsnprintf(event,MagickPathExtent,format,operands);
1625 n=vsprintf(event,format,operands);
1628 event[MagickPathExtent-1]=
'\0';
1629 text=TranslateEvent(module,function,line,domain,event);
1630 if (text == (
char *) NULL)
1632 (void) ContinueTimer((
TimerInfo *) &log_info->timer);
1633 UnlockSemaphoreInfo(log_info->event_semaphore);
1634 return(MagickFalse);
1636 if ((log_info->handler_mask & ConsoleHandler) != 0)
1638 (void) FormatLocaleFile(stderr,
"%s\n",text);
1639 (void) fflush(stderr);
1641 if ((log_info->handler_mask & DebugHandler) != 0)
1643#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1644 OutputDebugString(text);
1645 OutputDebugString(
"\n");
1648 if ((log_info->handler_mask & EventHandler) != 0)
1650#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1651 (void) NTReportEvent(text,MagickFalse);
1654 if ((log_info->handler_mask & FileHandler) != 0)
1659 file_info.st_size=0;
1660 if (log_info->file != (FILE *) NULL)
1661 (
void) fstat(fileno(log_info->file),&file_info);
1662 if (file_info.st_size > (MagickOffsetType) (1024*1024*log_info->limit))
1664 (void) FormatLocaleFile(log_info->file,
"</log>\n");
1665 (void) fclose(log_info->file);
1666 log_info->file=(FILE *) NULL;
1668 if (log_info->file == (FILE *) NULL)
1673 filename=TranslateFilename(log_info);
1674 if (filename == (
char *) NULL)
1676 (void) ContinueTimer((
TimerInfo *) &log_info->timer);
1677 UnlockSemaphoreInfo(log_info->event_semaphore);
1678 return(MagickFalse);
1680 log_info->append=IsPathAccessible(filename);
1681 log_info->file=fopen_utf8(filename,
"ab");
1682 filename=(
char *) RelinquishMagickMemory(filename);
1683 if (log_info->file == (FILE *) NULL)
1685 UnlockSemaphoreInfo(log_info->event_semaphore);
1686 return(MagickFalse);
1688 log_info->generation++;
1689 if (log_info->append == MagickFalse)
1690 (void) FormatLocaleFile(log_info->file,
"<?xml version=\"1.0\" "
1691 "encoding=\"UTF-8\" standalone=\"yes\"?>\n");
1692 (void) FormatLocaleFile(log_info->file,
"<log>\n");
1694 (void) FormatLocaleFile(log_info->file,
" <event>%s</event>\n",text);
1695 (void) fflush(log_info->file);
1697 if ((log_info->handler_mask & MethodHandler) != 0)
1699 if (log_info->method != (MagickLogMethod) NULL)
1700 log_info->method(type,text);
1702 if ((log_info->handler_mask & StdoutHandler) != 0)
1704 (void) FormatLocaleFile(stdout,
"%s\n",text);
1705 (void) fflush(stdout);
1707 if ((log_info->handler_mask & StderrHandler) != 0)
1709 (void) FormatLocaleFile(stderr,
"%s\n",text);
1710 (void) fflush(stderr);
1712 text=(
char *) RelinquishMagickMemory(text);
1713 (void) ContinueTimer((
TimerInfo *) &log_info->timer);
1714 UnlockSemaphoreInfo(log_info->event_semaphore);
1718MagickExport MagickBooleanType LogMagickEvent(
const LogEventType type,
1719 const char *module,
const char *function,
const size_t line,
1720 const char *format,...)
1728 if (IsEventLogging() == MagickFalse)
1729 return(MagickFalse);
1730 va_start(operands,format);
1731 status=LogMagickEventList(type,module,function,line,format,operands);
1736#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
1760static LogHandlerType ParseLogHandlers(
const char *handlers)
1774 handler_mask=NoHandler;
1775 for (p=handlers; p != (
char *) NULL; p=strchr(p,
','))
1777 while ((*p !=
'\0') && ((isspace((
int) ((
unsigned char) *p)) != 0) ||
1780 for (i=0; *LogHandlers[i].name !=
'\0'; i++)
1782 length=strlen(LogHandlers[i].name);
1783 if (LocaleNCompare(p,LogHandlers[i].name,length) == 0)
1785 handler_mask=(LogHandlerType) (handler_mask | LogHandlers[i].handler);
1789 if (*LogHandlers[i].name ==
'\0')
1790 return(UndefinedHandler);
1792 return(handler_mask);
1820MagickExport LogEventType SetLogEventMask(
const char *events)
1834 event_mask=UndefinedEvents;
1835 exception=AcquireExceptionInfo();
1836 log_info=GetLogInfo(
"*",exception);
1837 exception=DestroyExceptionInfo(exception);
1838 if (log_info == (
LogInfo *) NULL)
1840 option=ParseCommandOption(MagickLogEventOptions,MagickTrue,events);
1841 LockSemaphoreInfo(log_semaphore);
1842 event_mask=log_info->event_mask;
1844 log_info->event_mask=UndefinedEvents;
1846 log_info->event_mask=(LogEventType) option;
1847 CheckEventLogging();
1848 UnlockSemaphoreInfo(log_semaphore);
1874MagickExport
void SetLogFormat(
const char *format)
1882 exception=AcquireExceptionInfo();
1883 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1884 exception=DestroyExceptionInfo(exception);
1885 if (log_info == (
LogInfo *) NULL)
1887 LockSemaphoreInfo(log_semaphore);
1888 if (log_info->format != (
char *) NULL)
1889 log_info->format=DestroyString(log_info->format);
1890 log_info->format=ConstantString(format);
1891 UnlockSemaphoreInfo(log_semaphore);
1917MagickExport
void SetLogMethod(MagickLogMethod method)
1925 exception=AcquireExceptionInfo();
1926 log_info=(
LogInfo *) GetLogInfo(
"*",exception);
1927 exception=DestroyExceptionInfo(exception);
1928 LockSemaphoreInfo(log_semaphore);
1929 log_info=(
LogInfo *) GetValueFromLinkedList(log_cache,0);
1930 log_info->handler_mask=(LogHandlerType) (log_info->handler_mask |
1932 log_info->method=method;
1933 UnlockSemaphoreInfo(log_semaphore);
1960MagickExport
const char *SetLogName(
const char *name)
1962 if ((name != (
char *) NULL) && (*name !=
'\0'))
1963 (void) CopyMagickString(log_name,name,MagickPathExtent);