20
% Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization %
20
% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
21
21
% dedicated to making software imaging solutions freely available. %
23
23
% You may not use this file except in compliance with the License. You may %
52
52
#include "magick/semaphore.h"
53
53
#include "magick/timer.h"
54
54
#include "magick/string_.h"
55
#include "magick/string-private.h"
55
56
#include "magick/token.h"
56
57
#include "magick/thread_.h"
57
58
#include "magick/thread-private.h"
225
226
exception=AcquireExceptionInfo();
226
227
log_info=GetLogInfo("*",exception);
227
228
exception=DestroyExceptionInfo(exception);
228
(void) LockSemaphoreInfo(log_semaphore);
229
LockSemaphoreInfo(log_semaphore);
229
230
if (log_info->file != (FILE *) NULL)
231
232
if (log_info->append == MagickFalse)
279
280
Search for log tag.
281
(void) LockSemaphoreInfo(log_semaphore);
282
LockSemaphoreInfo(log_semaphore);
282
283
ResetLinkedListIterator(log_list);
283
284
p=(LogInfo *) GetNextValueInLinkedList(log_list);
284
285
while (p != (LogInfo *) NULL)
290
291
if (p != (LogInfo *) NULL)
291
292
(void) InsertValueInLinkedList(log_list,0,
292
293
RemoveElementByValueFromLinkedList(log_list,p));
293
(void) UnlockSemaphoreInfo(log_semaphore);
294
UnlockSemaphoreInfo(log_semaphore);
310
311
% The format of the GetLogInfoList function is:
312
313
% const LogInfo **GetLogInfoList(const char *pattern,
313
% unsigned long *number_preferences,ExceptionInfo *exception)
314
% size_t *number_preferences,ExceptionInfo *exception)
315
316
% A description of each parameter follows:
345
346
MagickExport const LogInfo **GetLogInfoList(const char *pattern,
346
unsigned long *number_preferences,ExceptionInfo *exception)
347
size_t *number_preferences,ExceptionInfo *exception)
360
361
assert(pattern != (char *) NULL);
361
362
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
362
assert(number_preferences != (unsigned long *) NULL);
363
assert(number_preferences != (size_t *) NULL);
363
364
*number_preferences=0;
364
365
p=GetLogInfo("*",exception);
365
366
if (p == (const LogInfo *) NULL)
372
373
Generate log list.
374
(void) LockSemaphoreInfo(log_semaphore);
375
LockSemaphoreInfo(log_semaphore);
375
376
ResetLinkedListIterator(log_list);
376
377
p=(const LogInfo *) GetNextValueInLinkedList(log_list);
377
378
for (i=0; p != (const LogInfo *) NULL; )
381
382
preferences[i++]=p;
382
383
p=(const LogInfo *) GetNextValueInLinkedList(log_list);
384
(void) UnlockSemaphoreInfo(log_semaphore);
385
UnlockSemaphoreInfo(log_semaphore);
385
386
qsort((void *) preferences,(size_t) i,sizeof(*preferences),LogInfoCompare);
386
387
preferences[i]=(LogInfo *) NULL;
387
*number_preferences=(unsigned long) i;
388
*number_preferences=(size_t) i;
388
389
return(preferences);
404
405
% The format of the GetLogList function is:
406
% char **GetLogList(const char *pattern,unsigned long *number_preferences,
407
% char **GetLogList(const char *pattern,size_t *number_preferences,
407
408
% ExceptionInfo *exception)
409
410
% A description of each parameter follows:
438
439
MagickExport char **GetLogList(const char *pattern,
439
unsigned long *number_preferences,ExceptionInfo *exception)
440
size_t *number_preferences,ExceptionInfo *exception)
453
454
assert(pattern != (char *) NULL);
454
455
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
455
assert(number_preferences != (unsigned long *) NULL);
456
assert(number_preferences != (size_t *) NULL);
456
457
*number_preferences=0;
457
458
p=GetLogInfo("*",exception);
458
459
if (p == (const LogInfo *) NULL)
465
466
Generate log list.
467
(void) LockSemaphoreInfo(log_semaphore);
468
LockSemaphoreInfo(log_semaphore);
468
469
ResetLinkedListIterator(log_list);
469
470
p=(const LogInfo *) GetNextValueInLinkedList(log_list);
470
471
for (i=0; p != (const LogInfo *) NULL; )
474
475
preferences[i++]=ConstantString(p->name);
475
476
p=(const LogInfo *) GetNextValueInLinkedList(log_list);
477
(void) UnlockSemaphoreInfo(log_semaphore);
478
UnlockSemaphoreInfo(log_semaphore);
478
479
qsort((void *) preferences,(size_t) i,sizeof(*preferences),LogCompare);
479
480
preferences[i]=(char *) NULL;
480
*number_preferences=(unsigned long) i;
481
*number_preferences=(size_t) i;
481
482
return(preferences);
533
534
if (log_semaphore == (SemaphoreInfo *) NULL)
534
535
AcquireSemaphoreInfo(&log_semaphore);
535
(void) LockSemaphoreInfo(log_semaphore);
536
LockSemaphoreInfo(log_semaphore);
536
537
if ((log_list == (LinkedListInfo *) NULL) &&
537
538
(instantiate_log == MagickFalse))
539
540
(void) LoadLogLists(LogFilename,exception);
540
541
instantiate_log=MagickTrue;
542
(void) UnlockSemaphoreInfo(log_semaphore);
543
UnlockSemaphoreInfo(log_semaphore);
544
545
return(log_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
649
650
if (log_info[i]->filename != (char *) NULL)
651
652
(void) fprintf(file,"%s",log_info[i]->filename);
652
for (j=(long) strlen(log_info[i]->filename); j <= 16; j++)
653
for (j=(ssize_t) strlen(log_info[i]->filename); j <= 16; j++)
653
654
(void) fprintf(file," ");
655
(void) fprintf(file,"%9lu ",log_info[i]->generations);
656
(void) FormatMagickSize(MegabytesToBytes(log_info[i]->limit),limit);
657
(void) fprintf(file,"%8s ",limit);
656
(void) fprintf(file,"%9g ",(double) log_info[i]->generations);
657
(void) FormatMagickSize(MegabytesToBytes(log_info[i]->limit),MagickFalse,
659
(void) fprintf(file,"%8sB ",limit);
658
660
if (log_info[i]->format != (char *) NULL)
659
661
(void) fprintf(file,"%s",log_info[i]->format);
660
662
(void) fprintf(file,"\n");
738
740
if (log_semaphore == (SemaphoreInfo *) NULL)
739
741
AcquireSemaphoreInfo(&log_semaphore);
740
(void) LockSemaphoreInfo(log_semaphore);
742
LockSemaphoreInfo(log_semaphore);
741
743
if (log_list != (LinkedListInfo *) NULL)
742
744
log_list=DestroyLinkedList(log_list,DestroyLogElement);
743
745
instantiate_log=MagickFalse;
744
(void) UnlockSemaphoreInfo(log_semaphore);
746
UnlockSemaphoreInfo(log_semaphore);
745
747
DestroySemaphoreInfo(&log_semaphore);
762
764
% The format of the LogMagickEvent method is:
764
766
% MagickBooleanType LogMagickEvent(const LogEventType type,
765
% const char *module,const char *function,const unsigned long line,
767
% const char *module,const char *function,const size_t line,
766
768
% const char *format,...)
768
770
% A description of each parameter follows:
781
783
static char *TranslateEvent(const LogEventType magick_unused(type),
782
const char *module,const char *function,const unsigned long line,
784
const char *module,const char *function,const size_t line,
783
785
const char *domain,const char *event)
829
831
(void) FormatMagickString(text,extent,
831
833
" <timestamp>%s</timestamp>\n"
832
" <elapsed-time>%ld:%02ld.%03ld</elapsed-time>\n"
834
" <elapsed-time>%lu:%02lu.%03lu</elapsed-time>\n"
833
835
" <user-time>%0.3f</user-time>\n"
834
" <process-id>%ld</process-id>\n"
835
" <thread-id>%lu</thread-id>\n"
836
" <process-id>%.20g</process-id>\n"
837
" <thread-id>%.20g</thread-id>\n"
836
838
" <module>%s</module>\n"
837
839
" <function>%s</function>\n"
838
" <line>%lu</line>\n"
840
" <line>%.20g</line>\n"
839
841
" <domain>%s</domain>\n"
840
842
" <event>%s</event>\n"
841
"</entry>",timestamp,(long) (elapsed_time/60.0),(long)
842
floor(fmod(elapsed_time,60.0)),(long) (1000.0*(elapsed_time-
843
floor(elapsed_time))+0.5),user_time,(long) getpid(),
844
GetMagickThreadSignature(),module,function,line,domain,event);
843
"</entry>",timestamp,(unsigned long) (elapsed_time/60.0),
844
(unsigned long) floor(fmod(elapsed_time,60.0)),(unsigned long)
845
(1000.0*(elapsed_time-floor(elapsed_time))+0.5),user_time,
846
(double) getpid(),(double) GetMagickThreadSignature(),module,function,
847
(double) line,domain,event);
931
q+=FormatMagickString(q,extent,"%lu",log_info->generation %
932
log_info->generations);
934
q+=FormatMagickString(q,extent,"%.20g",(double) (log_info->generation %
935
log_info->generations));
937
q+=FormatMagickString(q,extent,"%lu",line);
940
q+=FormatMagickString(q,extent,"%.20g",(double) line);
961
q+=FormatMagickString(q,extent,"%ld",(long) getpid());
964
q+=FormatMagickString(q,extent,"%.20g",(double) getpid());
966
q+=FormatMagickString(q,extent,"%ld:%02ld.%03ld",(long)
967
(elapsed_time/60.0),(long) floor(fmod(elapsed_time,60.0)),
968
(long) (1000.0*(elapsed_time-floor(elapsed_time))+0.5));
969
q+=FormatMagickString(q,extent,"%lu:%02lu.%03lu",(unsigned long)
970
(elapsed_time/60.0),(unsigned long) floor(fmod(elapsed_time,60.0)),
971
(unsigned long) (1000.0*(elapsed_time-floor(elapsed_time))+0.5));
1068
q+=FormatMagickString(q,extent,"%lu",log_info->generation %
1069
log_info->generations);
1071
q+=FormatMagickString(q,extent,"%.20g",(double) (log_info->generation %
1072
log_info->generations));
1079
q+=FormatMagickString(q,extent,"%ld",(long) getpid());
1082
q+=FormatMagickString(q,extent,"%.20g",(double) getpid());
1104
1107
MagickBooleanType LogMagickEventList(const LogEventType type,const char *module,
1105
const char *function,const unsigned long line,const char *format,
1108
const char *function,const size_t line,const char *format,
1106
1109
va_list operands)
1126
1129
exception=AcquireExceptionInfo();
1127
1130
log_info=(LogInfo *) GetLogInfo("*",exception);
1128
1131
exception=DestroyExceptionInfo(exception);
1129
(void) LockSemaphoreInfo(log_semaphore);
1132
LockSemaphoreInfo(log_semaphore);
1130
1133
if ((log_info->event_mask & type) == 0)
1132
(void) UnlockSemaphoreInfo(log_semaphore);
1135
UnlockSemaphoreInfo(log_semaphore);
1133
1136
return(MagickTrue);
1135
1138
domain=MagickOptionToMnemonic(MagickLogEventOptions,type);
1144
1147
if (text == (char *) NULL)
1146
1149
(void) ContinueTimer((TimerInfo *) &log_info->timer);
1147
(void) UnlockSemaphoreInfo(log_semaphore);
1150
UnlockSemaphoreInfo(log_semaphore);
1148
1151
return(MagickFalse);
1150
1153
if ((log_info->handler_mask & ConsoleHandler) != 0)
1155
1158
if ((log_info->handler_mask & DebugHandler) != 0)
1157
#if defined(__WINDOWS__)
1160
#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1158
1161
OutputDebugString(text);
1161
1164
if ((log_info->handler_mask & EventHandler) != 0)
1163
#if defined(__WINDOWS__)
1166
#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1164
1167
(void) NTReportEvent(text,MagickFalse);
1187
1190
if (filename == (char *) NULL)
1189
1192
(void) ContinueTimer((TimerInfo *) &log_info->timer);
1190
(void) UnlockSemaphoreInfo(log_semaphore);
1193
UnlockSemaphoreInfo(log_semaphore);
1191
1194
return(MagickFalse);
1193
1196
log_info->append=IsPathAccessible(filename);
1222
1225
text=(char *) RelinquishMagickMemory(text);
1223
1226
(void) ContinueTimer((TimerInfo *) &log_info->timer);
1224
(void) UnlockSemaphoreInfo(log_semaphore);
1227
UnlockSemaphoreInfo(log_semaphore);
1225
1228
return(MagickTrue);
1228
1231
MagickBooleanType LogMagickEvent(const LogEventType type,const char *module,
1229
const char *function,const unsigned long line,const char *format,...)
1232
const char *function,const size_t line,const char *format,...)
1257
1260
% The format of the LoadLogList method is:
1259
1262
% MagickBooleanType LoadLogList(const char *xml,const char *filename,
1260
% const unsigned long depth,ExceptionInfo *exception)
1263
% const size_t depth,ExceptionInfo *exception)
1262
1265
% A description of each parameter follows:
1273
1276
static MagickBooleanType LoadLogList(const char *xml,const char *filename,
1274
const unsigned long depth,ExceptionInfo *exception)
1277
const size_t depth,ExceptionInfo *exception)
1277
1280
keyword[MaxTextExtent],
1378
1381
Allocate memory for the log list.
1380
log_info=(LogInfo *) AcquireMagickMemory(sizeof(*log_info));
1383
log_info=(LogInfo *) AcquireAlignedMemory(1,sizeof(*log_info));
1381
1384
if (log_info == (LogInfo *) NULL)
1382
1385
ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
1383
1386
(void) ResetMagickMemory(log_info,0,sizeof(*log_info));
1554
log_info=(LogInfo *) AcquireMagickMemory(sizeof(*log_info));
1557
log_info=(LogInfo *) AcquireAlignedMemory(1,sizeof(*log_info));
1555
1558
if (log_info == (LogInfo *) NULL)
1557
1560
(void) ThrowMagickException(exception,GetMagickModule(),
1563
1566
GetTimerInfo((TimerInfo *) &log_info->timer);
1564
1567
log_info->event_mask=p->event_mask;
1565
1568
log_info->handler_mask=p->handler_mask;
1566
log_info->filename=(char *) p->filename;
1567
log_info->format=(char *) p->format;
1569
log_info->filename=ConstantString(p->filename);
1570
log_info->format=ConstantString(p->format);
1568
1571
log_info->exempt=MagickTrue;
1569
1572
log_info->signature=MagickSignature;
1570
1573
status=AppendValueToLinkedList(log_list,log_info);
1683
1686
exception=AcquireExceptionInfo();
1684
1687
log_info=(LogInfo *) GetLogInfo("*",exception);
1685
1688
exception=DestroyExceptionInfo(exception);
1686
1689
option=ParseMagickOption(MagickLogEventOptions,MagickTrue,events);
1687
(void) LockSemaphoreInfo(log_semaphore);
1690
LockSemaphoreInfo(log_semaphore);
1688
1691
log_info=(LogInfo *) GetValueFromLinkedList(log_list,0);
1689
1692
log_info->event_mask=(LogEventType) option;
1690
1693
if (option == -1)
1691
1694
log_info->event_mask=UndefinedEvents;
1692
(void) UnlockSemaphoreInfo(log_semaphore);
1695
UnlockSemaphoreInfo(log_semaphore);
1693
1696
return(log_info->event_mask);
1726
1729
exception=AcquireExceptionInfo();
1727
1730
log_info=(LogInfo *) GetLogInfo("*",exception);
1728
1731
exception=DestroyExceptionInfo(exception);
1729
(void) LockSemaphoreInfo(log_semaphore);
1732
LockSemaphoreInfo(log_semaphore);
1730
1733
if (log_info->format != (char *) NULL)
1731
1734
log_info->format=DestroyString(log_info->format);
1732
1735
log_info->format=ConstantString(format);
1733
(void) UnlockSemaphoreInfo(log_semaphore);
1736
UnlockSemaphoreInfo(log_semaphore);