% MagickCore Log Events %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% September 2002 %
% %
% %
-% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
#include "MagickCore/blob.h"
#include "MagickCore/client.h"
#include "MagickCore/configure.h"
+#include "MagickCore/configure-private.h"
#include "MagickCore/exception.h"
#include "MagickCore/exception-private.h"
#include "MagickCore/hashmap.h"
#include "MagickCore/log.h"
#include "MagickCore/log-private.h"
#include "MagickCore/memory_.h"
+#include "MagickCore/nt-base-private.h"
#include "MagickCore/option.h"
#include "MagickCore/semaphore.h"
#include "MagickCore/timer.h"
#include "MagickCore/utility-private.h"
#include "MagickCore/version.h"
#include "MagickCore/xml-tree.h"
+#include "MagickCore/xml-tree-private.h"
\f
/*
Define declarations.
StderrHandler = 0x0004,
FileHandler = 0x0008,
DebugHandler = 0x0010,
- EventHandler = 0x0020
+ EventHandler = 0x0020,
+ MethodHandler = 0x0040
} LogHandlerType;
typedef struct _EventInfo
MagickBooleanType
append,
- exempt,
stealth;
TimerInfo
size_t
signature;
+
+ MagickLogMethod
+ method;
};
typedef struct _LogMapInfo
static const HandlerInfo
LogHandlers[] =
{
- { "console", ConsoleHandler },
- { "debug", DebugHandler },
- { "event", EventHandler },
- { "file", FileHandler },
- { "none", NoHandler },
- { "stderr", StderrHandler },
- { "stdout", StdoutHandler },
+ { "Console", ConsoleHandler },
+ { "Debug", DebugHandler },
+ { "Event", EventHandler },
+ { "File", FileHandler },
+ { "None", NoHandler },
+ { "Stderr", StderrHandler },
+ { "Stdout", StdoutHandler },
{ (char *) NULL, UndefinedHandler }
};
static const LogMapInfo
LogMap[] =
{
- { NoEvents, ConsoleHandler, "Magick-%d.log",
- "%t %r %u %v %d %c[%p]: %m/%f/%l/%d\n %e" }
+ { NoEvents, ConsoleHandler, "Magick-%g.log",
+ "%t %r %u %v %d %c[%p]: %m/%f/%l/%d\\n %e" }
};
static char
log_name[MaxTextExtent] = "Magick";
static LinkedListInfo
- *log_list = (LinkedListInfo *) NULL;
+ *log_cache = (LinkedListInfo *) NULL;
static SemaphoreInfo
+ *event_semaphore = (SemaphoreInfo *) NULL,
*log_semaphore = (SemaphoreInfo *) NULL;
-
-static volatile MagickBooleanType
- instantiate_log = MagickFalse;
\f
/*
Forward declarations.
*GetLogInfo(const char *,ExceptionInfo *);
static MagickBooleanType
- InitializeLogList(ExceptionInfo *),
- LoadLogLists(const char *,ExceptionInfo *);
+ IsLogCacheInstantiated(ExceptionInfo *),
+ LoadLogCache(LinkedListInfo *,const char *,const char *,const size_t,
+ ExceptionInfo *);
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% A c q u i r e L o g C a c h e %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% AcquireLogCache() caches one or more log configurations which provides a
+% mapping between log attributes and log name.
+%
+% The format of the AcquireLogCache method is:
+%
+% LinkedListInfo *AcquireLogCache(const char *filename,
+% ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o filename: the log configuration filename.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
+static LinkedListInfo *AcquireLogCache(const char *filename,
+ ExceptionInfo *exception)
+{
+ const StringInfo
+ *option;
+
+ LinkedListInfo
+ *log_cache,
+ *options;
+
+ MagickStatusType
+ status;
+
+ register ssize_t
+ i;
+
+ /*
+ Load external log map.
+ */
+ log_cache=NewLinkedList(0);
+ if (log_cache == (LinkedListInfo *) NULL)
+ ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
+ status=MagickTrue;
+ options=GetConfigureOptions(filename,exception);
+ option=(const StringInfo *) GetNextValueInLinkedList(options);
+ while (option != (const StringInfo *) NULL)
+ {
+ status&=LoadLogCache(log_cache,(const char *) GetStringInfoDatum(option),
+ GetStringInfoPath(option),0,exception);
+ option=(const StringInfo *) GetNextValueInLinkedList(options);
+ }
+ options=DestroyConfigureOptions(options);
+ /*
+ Load built-in log map.
+ */
+ for (i=0; i < (ssize_t) (sizeof(LogMap)/sizeof(*LogMap)); i++)
+ {
+ LogInfo
+ *log_info;
+
+ register const LogMapInfo
+ *p;
+
+ p=LogMap+i;
+ log_info=(LogInfo *) AcquireMagickMemory(sizeof(*log_info));
+ if (log_info == (LogInfo *) NULL)
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ ResourceLimitError,"MemoryAllocationFailed","`%s'",p->filename);
+ continue;
+ }
+ (void) ResetMagickMemory(log_info,0,sizeof(*log_info));
+ log_info->path=ConstantString("[built-in]");
+ GetTimerInfo((TimerInfo *) &log_info->timer);
+ log_info->event_mask=p->event_mask;
+ log_info->handler_mask=p->handler_mask;
+ log_info->filename=ConstantString(p->filename);
+ log_info->format=ConstantString(p->format);
+ log_info->signature=MagickSignature;
+ status&=AppendValueToLinkedList(log_cache,log_info);
+ if (status == MagickFalse)
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ ResourceLimitError,"MemoryAllocationFailed","`%s'",log_info->name);
+ }
+ return(log_cache);
+}
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
LockSemaphoreInfo(log_semaphore);
if (log_info->file != (FILE *) NULL)
{
- if (log_info->append == MagickFalse)
- (void) FormatLocaleFile(log_info->file,"</log>\n");
+ (void) FormatLocaleFile(log_info->file,"</log>\n");
(void) fclose(log_info->file);
log_info->file=(FILE *) NULL;
}
*p;
assert(exception != (ExceptionInfo *) NULL);
- if ((log_list == (LinkedListInfo *) NULL) || (instantiate_log == MagickFalse))
- if (InitializeLogList(exception) == MagickFalse)
- return((LogInfo *) NULL);
- if ((log_list == (LinkedListInfo *) NULL) ||
- (IsLinkedListEmpty(log_list) != MagickFalse))
+ if (IsLogCacheInstantiated(exception) == MagickFalse)
return((LogInfo *) NULL);
- if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
- return((LogInfo *) GetValueFromLinkedList(log_list,0));
/*
Search for log tag.
*/
LockSemaphoreInfo(log_semaphore);
- ResetLinkedListIterator(log_list);
- p=(LogInfo *) GetNextValueInLinkedList(log_list);
+ ResetLinkedListIterator(log_cache);
+ p=(LogInfo *) GetNextValueInLinkedList(log_cache);
+ if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
+ {
+ UnlockSemaphoreInfo(log_semaphore);
+ return(p);
+ }
while (p != (LogInfo *) NULL)
{
if (LocaleCompare(name,p->name) == 0)
break;
- p=(LogInfo *) GetNextValueInLinkedList(log_list);
+ p=(LogInfo *) GetNextValueInLinkedList(log_cache);
}
if (p != (LogInfo *) NULL)
- (void) InsertValueInLinkedList(log_list,0,
- RemoveElementByValueFromLinkedList(log_list,p));
+ (void) InsertValueInLinkedList(log_cache,0,
+ RemoveElementByValueFromLinkedList(log_cache,p));
UnlockSemaphoreInfo(log_semaphore);
return(p);
}
if (p == (const LogInfo *) NULL)
return((const LogInfo **) NULL);
preferences=(const LogInfo **) AcquireQuantumMemory((size_t)
- GetNumberOfElementsInLinkedList(log_list)+1UL,sizeof(*preferences));
+ GetNumberOfElementsInLinkedList(log_cache)+1UL,sizeof(*preferences));
if (preferences == (const LogInfo **) NULL)
return((const LogInfo **) NULL);
/*
Generate log list.
*/
LockSemaphoreInfo(log_semaphore);
- ResetLinkedListIterator(log_list);
- p=(const LogInfo *) GetNextValueInLinkedList(log_list);
+ ResetLinkedListIterator(log_cache);
+ p=(const LogInfo *) GetNextValueInLinkedList(log_cache);
for (i=0; p != (const LogInfo *) NULL; )
{
if ((p->stealth == MagickFalse) &&
(GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
preferences[i++]=p;
- p=(const LogInfo *) GetNextValueInLinkedList(log_list);
+ p=(const LogInfo *) GetNextValueInLinkedList(log_cache);
}
UnlockSemaphoreInfo(log_semaphore);
qsort((void *) preferences,(size_t) i,sizeof(*preferences),LogInfoCompare);
if (p == (const LogInfo *) NULL)
return((char **) NULL);
preferences=(char **) AcquireQuantumMemory((size_t)
- GetNumberOfElementsInLinkedList(log_list)+1UL,sizeof(*preferences));
+ GetNumberOfElementsInLinkedList(log_cache)+1UL,sizeof(*preferences));
if (preferences == (char **) NULL)
return((char **) NULL);
/*
Generate log list.
*/
LockSemaphoreInfo(log_semaphore);
- ResetLinkedListIterator(log_list);
- p=(const LogInfo *) GetNextValueInLinkedList(log_list);
+ ResetLinkedListIterator(log_cache);
+ p=(const LogInfo *) GetNextValueInLinkedList(log_cache);
for (i=0; p != (const LogInfo *) NULL; )
{
if ((p->stealth == MagickFalse) &&
(GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
preferences[i++]=ConstantString(p->name);
- p=(const LogInfo *) GetNextValueInLinkedList(log_list);
+ p=(const LogInfo *) GetNextValueInLinkedList(log_cache);
}
UnlockSemaphoreInfo(log_semaphore);
qsort((void *) preferences,(size_t) i,sizeof(*preferences),LogCompare);
% %
% %
% %
-+ I n i t i a l i z e L o g L i s t %
++ I s L o g C a c h e I n s t a n t i a t e d %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% InitializeLogList() initialize the log list.
+% IsLogCacheInstantiated() determines if the log list is instantiated. If
+% not, it instantiates the list and returns it.
%
-% The format of the InitializeLogList method is:
+% The format of the IsLogInstantiated method is:
%
-% MagickBooleanType InitializeLogList(ExceptionInfo *exception)
+% MagickBooleanType IsLogCacheInstantiated(ExceptionInfo *exception)
%
% A description of each parameter follows.
%
% o exception: return any errors or warnings in this structure.
%
*/
-static MagickBooleanType InitializeLogList(ExceptionInfo *exception)
+static MagickBooleanType IsLogCacheInstantiated(ExceptionInfo *exception)
{
- if ((log_list == (LinkedListInfo *) NULL) && (instantiate_log == MagickFalse))
+ if (log_cache == (LinkedListInfo *) NULL)
{
if (log_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&log_semaphore);
+ ActivateSemaphoreInfo(&log_semaphore);
LockSemaphoreInfo(log_semaphore);
- if ((log_list == (LinkedListInfo *) NULL) &&
- (instantiate_log == MagickFalse))
- {
- (void) LoadLogLists(LogFilename,exception);
- instantiate_log=MagickTrue;
- }
+ if (log_cache == (LinkedListInfo *) NULL)
+ log_cache=AcquireLogCache(LogFilename,exception);
UnlockSemaphoreInfo(log_semaphore);
}
- return(log_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
+ return(log_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
}
\f
/*
ExceptionInfo
*exception;
- if ((log_list == (LinkedListInfo *) NULL) ||
- (IsLinkedListEmpty(log_list) != MagickFalse))
+ if ((log_cache == (LinkedListInfo *) NULL) ||
+ (IsLinkedListEmpty(log_cache) != MagickFalse))
return(MagickFalse);
exception=AcquireExceptionInfo();
log_info=GetLogInfo("*",exception);
{
#define MegabytesToBytes(value) ((MagickSizeType) (value)*1024*1024)
- char
- limit[MaxTextExtent];
-
const char
*path;
if ((path == (const char *) NULL) ||
(LocaleCompare(path,log_info[i]->path) != 0))
{
+ size_t
+ length;
+
if (log_info[i]->path != (char *) NULL)
(void) FormatLocaleFile(file,"\nPath: %s\n\n",log_info[i]->path);
- (void) FormatLocaleFile(file,
- "Filename Generations Limit Format\n");
- (void) FormatLocaleFile(file,
- "-------------------------------------------------"
- "------------------------------\n");
+ length=0;
+ for (j=0; j < (ssize_t) (8*sizeof(LogHandlerType)); j++)
+ {
+ size_t
+ mask;
+
+ if (LogHandlers[j].name == (const char *) NULL)
+ break;
+ mask=1;
+ mask<<=j;
+ if ((log_info[i]->handler_mask & mask) != 0)
+ {
+ (void) FormatLocaleFile(file,"%s ",LogHandlers[j].name);
+ length+=strlen(LogHandlers[j].name);
+ }
+ }
+ for (j=(ssize_t) length; j <= 12; j++)
+ (void) FormatLocaleFile(file," ");
+ (void) FormatLocaleFile(file," Generations Limit Format\n");
+ (void) FormatLocaleFile(file,"-----------------------------------------"
+ "--------------------------------------\n");
}
path=log_info[i]->path;
if (log_info[i]->filename != (char *) NULL)
(void) FormatLocaleFile(file," ");
}
(void) FormatLocaleFile(file,"%9g ",(double) log_info[i]->generations);
- (void) FormatMagickSize(MegabytesToBytes(log_info[i]->limit),MagickFalse,
- limit);
- (void) FormatLocaleFile(file,"%8sB ",limit);
+ (void) FormatLocaleFile(file,"%8g ",(double) log_info[i]->limit);
if (log_info[i]->format != (char *) NULL)
(void) FormatLocaleFile(file,"%s",log_info[i]->format);
(void) FormatLocaleFile(file,"\n");
*/
MagickPrivate MagickBooleanType LogComponentGenesis(void)
{
- AcquireSemaphoreInfo(&log_semaphore);
+ ExceptionInfo
+ *exception;
+
+ if (log_semaphore == (SemaphoreInfo *) NULL)
+ log_semaphore=AcquireSemaphoreInfo();
+ exception=AcquireExceptionInfo();
+ (void) GetLogInfo("*",exception);
+ exception=DestroyExceptionInfo(exception);
+ event_semaphore=AcquireSemaphoreInfo();
return(MagickTrue);
}
\f
p=(LogInfo *) log_info;
if (p->file != (FILE *) NULL)
{
- if (p->append == MagickFalse)
- (void) FormatLocaleFile(p->file,"</log>\n");
+ (void) FormatLocaleFile(p->file,"</log>\n");
(void) fclose(p->file);
p->file=(FILE *) NULL;
}
- if (p->exempt == MagickFalse)
- {
- if (p->format != (char *) NULL)
- p->format=DestroyString(p->format);
- if (p->path != (char *) NULL)
- p->path=DestroyString(p->path);
- if (p->filename != (char *) NULL)
- p->filename=DestroyString(p->filename);
- }
+ if (p->format != (char *) NULL)
+ p->format=DestroyString(p->format);
+ if (p->path != (char *) NULL)
+ p->path=DestroyString(p->path);
+ if (p->filename != (char *) NULL)
+ p->filename=DestroyString(p->filename);
p=(LogInfo *) RelinquishMagickMemory(p);
return((void *) NULL);
}
MagickPrivate void LogComponentTerminus(void)
{
+ if (event_semaphore == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&event_semaphore);
+ LockSemaphoreInfo(event_semaphore);
+ UnlockSemaphoreInfo(event_semaphore);
+ RelinquishSemaphoreInfo(&event_semaphore);
if (log_semaphore == (SemaphoreInfo *) NULL)
- AcquireSemaphoreInfo(&log_semaphore);
+ ActivateSemaphoreInfo(&log_semaphore);
LockSemaphoreInfo(log_semaphore);
- if (log_list != (LinkedListInfo *) NULL)
- log_list=DestroyLinkedList(log_list,DestroyLogElement);
- instantiate_log=MagickFalse;
+ if (log_cache != (LinkedListInfo *) NULL)
+ log_cache=DestroyLinkedList(log_cache,DestroyLogElement);
UnlockSemaphoreInfo(log_semaphore);
- DestroySemaphoreInfo(&log_semaphore);
+ RelinquishSemaphoreInfo(&log_semaphore);
}
\f
/*
exception=AcquireExceptionInfo();
log_info=(LogInfo *) GetLogInfo("*",exception);
exception=DestroyExceptionInfo(exception);
- LockSemaphoreInfo(log_semaphore);
+ if (event_semaphore == (SemaphoreInfo *) NULL)
+ ActivateSemaphoreInfo(&event_semaphore);
+ LockSemaphoreInfo(event_semaphore);
if ((log_info->event_mask & type) == 0)
{
- UnlockSemaphoreInfo(log_semaphore);
+ UnlockSemaphoreInfo(event_semaphore);
return(MagickTrue);
}
domain=CommandOptionToMnemonic(MagickLogEventOptions,type);
if (text == (char *) NULL)
{
(void) ContinueTimer((TimerInfo *) &log_info->timer);
- UnlockSemaphoreInfo(log_semaphore);
+ UnlockSemaphoreInfo(event_semaphore);
return(MagickFalse);
}
if ((log_info->handler_mask & ConsoleHandler) != 0)
{
#if defined(MAGICKCORE_WINDOWS_SUPPORT)
OutputDebugString(text);
+ OutputDebugString("\n");
#endif
}
if ((log_info->handler_mask & EventHandler) != 0)
file_info.st_size=0;
if (log_info->file != (FILE *) NULL)
(void) fstat(fileno(log_info->file),&file_info);
- if (file_info.st_size > (1024*1024*log_info->limit))
+ if (file_info.st_size > (ssize_t) (1024*1024*log_info->limit))
{
(void) FormatLocaleFile(log_info->file,"</log>\n");
(void) fclose(log_info->file);
if (filename == (char *) NULL)
{
(void) ContinueTimer((TimerInfo *) &log_info->timer);
- UnlockSemaphoreInfo(log_semaphore);
+ UnlockSemaphoreInfo(event_semaphore);
return(MagickFalse);
}
log_info->append=IsPathAccessible(filename);
- log_info->file=OpenMagickStream(filename,"ab");
+ log_info->file=fopen_utf8(filename,"ab");
filename=(char *) RelinquishMagickMemory(filename);
if (log_info->file == (FILE *) NULL)
{
- UnlockSemaphoreInfo(log_semaphore);
+ UnlockSemaphoreInfo(event_semaphore);
return(MagickFalse);
}
log_info->generation++;
if (log_info->append == MagickFalse)
- {
- (void) FormatLocaleFile(log_info->file,"<?xml version=\"1.0\" "
- "encoding=\"UTF-8\" standalone=\"yes\"?>\n");
- (void) FormatLocaleFile(log_info->file,"<log>\n");
- }
+ (void) FormatLocaleFile(log_info->file,"<?xml version=\"1.0\" "
+ "encoding=\"UTF-8\" standalone=\"yes\"?>\n");
+ (void) FormatLocaleFile(log_info->file,"<log>\n");
}
- (void) FormatLocaleFile(log_info->file,"%s\n",text);
+ (void) FormatLocaleFile(log_info->file," <event>%s</event>\n",text);
(void) fflush(log_info->file);
}
+ if ((log_info->handler_mask & MethodHandler) != 0)
+ {
+ if (log_info->method != (MagickLogMethod) NULL)
+ log_info->method(type,text);
+ }
if ((log_info->handler_mask & StdoutHandler) != 0)
{
(void) FormatLocaleFile(stdout,"%s\n",text);
}
text=(char *) RelinquishMagickMemory(text);
(void) ContinueTimer((TimerInfo *) &log_info->timer);
- UnlockSemaphoreInfo(log_semaphore);
+ UnlockSemaphoreInfo(event_semaphore);
return(MagickTrue);
}
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% LoadLogList() loads the log configuration file which provides a
+% LoadLogCache() loads the log configurations which provides a
% mapping between log attributes and log name.
%
-% The format of the LoadLogList method is:
+% The format of the LoadLogCache method is:
%
-% MagickBooleanType LoadLogList(const char *xml,const char *filename,
-% const size_t depth,ExceptionInfo *exception)
+% MagickBooleanType LoadLogCache(LinkedListInfo *log_cache,const char *xml,
+% const char *filename,const size_t depth,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o exception: return any errors or warnings in this structure.
%
*/
-static MagickBooleanType LoadLogList(const char *xml,const char *filename,
- const size_t depth,ExceptionInfo *exception)
+static MagickBooleanType LoadLogCache(LinkedListInfo *log_cache,const char *xml,
+ const char *filename,const size_t depth,ExceptionInfo *exception)
{
char
keyword[MaxTextExtent],
*/
if (xml == (const char *) NULL)
return(MagickFalse);
- if (log_list == (LinkedListInfo *) NULL)
- {
- log_list=NewLinkedList(0);
- if (log_list == (LinkedListInfo *) NULL)
- {
- ThrowFileException(exception,ResourceLimitError,
- "MemoryAllocationFailed",filename);
- return(MagickFalse);
- }
- }
status=MagickTrue;
token=AcquireString((const char *) xml);
for (q=(const char *) xml; *q != '\0'; )
(void) CopyMagickString(path,token,MaxTextExtent);
else
(void) ConcatenateMagickString(path,token,MaxTextExtent);
- xml=FileToString(path,~0,exception);
+ xml=FileToXML(path,~0UL);
if (xml != (char *) NULL)
{
- status|=LoadLogList(xml,path,depth+1,exception);
+ status&=LoadLogCache(log_cache,xml,path,depth+1,
+ exception);
xml=DestroyString(xml);
}
}
(void) ResetMagickMemory(log_info,0,sizeof(*log_info));
log_info->path=ConstantString(filename);
GetTimerInfo((TimerInfo *) &log_info->timer);
- log_info->exempt=MagickFalse;
log_info->signature=MagickSignature;
continue;
}
continue;
if (LocaleCompare(keyword,"</logmap>") == 0)
{
- status=AppendValueToLinkedList(log_list,log_info);
+ status=AppendValueToLinkedList(log_cache,log_info);
if (status == MagickFalse)
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",filename);
log_info=(LogInfo *) NULL;
+ continue;
}
GetMagickToken(q,(const char **) NULL,token);
if (*token != '=')
}
}
token=DestroyString(token);
- if (log_list == (LinkedListInfo *) NULL)
+ if (log_cache == (LinkedListInfo *) NULL)
return(MagickFalse);
return(status != 0 ? MagickTrue : MagickFalse);
}
% %
% %
% %
-% L o a d L o g L i s t s %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% LoadLogLists() loads one or more log configuration file which provides a
-% mapping between log attributes and log name.
-%
-% The format of the LoadLogLists method is:
-%
-% MagickBooleanType LoadLogLists(const char *filename,
-% ExceptionInfo *exception)
-%
-% A description of each parameter follows:
-%
-% o filename: the log configuration filename.
-%
-% o exception: return any errors or warnings in this structure.
-%
-*/
-static MagickBooleanType LoadLogLists(const char *filename,
- ExceptionInfo *exception)
-{
- const StringInfo
- *option;
-
- LinkedListInfo
- *options;
-
- MagickStatusType
- status;
-
- register ssize_t
- i;
-
- /*
- Load built-in log map.
- */
- status=MagickFalse;
- if (log_list == (LinkedListInfo *) NULL)
- {
- log_list=NewLinkedList(0);
- if (log_list == (LinkedListInfo *) NULL)
- {
- ThrowFileException(exception,ResourceLimitError,
- "MemoryAllocationFailed",filename);
- return(MagickFalse);
- }
- }
- for (i=0; i < (ssize_t) (sizeof(LogMap)/sizeof(*LogMap)); i++)
- {
- LogInfo
- *log_info;
-
- register const LogMapInfo
- *p;
-
- p=LogMap+i;
- log_info=(LogInfo *) AcquireMagickMemory(sizeof(*log_info));
- if (log_info == (LogInfo *) NULL)
- {
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",log_info->name);
- continue;
- }
- (void) ResetMagickMemory(log_info,0,sizeof(*log_info));
- log_info->path=(char *) "[built-in]";
- GetTimerInfo((TimerInfo *) &log_info->timer);
- log_info->event_mask=p->event_mask;
- log_info->handler_mask=p->handler_mask;
- log_info->filename=ConstantString(p->filename);
- log_info->format=ConstantString(p->format);
- log_info->exempt=MagickTrue;
- log_info->signature=MagickSignature;
- status=AppendValueToLinkedList(log_list,log_info);
- if (status == MagickFalse)
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",log_info->name);
- }
- /*
- Load external log map.
- */
- options=GetConfigureOptions(filename,exception);
- option=(const StringInfo *) GetNextValueInLinkedList(options);
- while (option != (const StringInfo *) NULL)
- {
- status|=LoadLogList((const char *) GetStringInfoDatum(option),
- GetStringInfoPath(option),0,exception);
- option=(const StringInfo *) GetNextValueInLinkedList(options);
- }
- options=DestroyConfigureOptions(options);
- return(status != 0 ? MagickTrue : MagickFalse);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
+ P a r s e L o g H a n d l e r s %
% %
% %
exception=DestroyExceptionInfo(exception);
option=ParseCommandOption(MagickLogEventOptions,MagickTrue,events);
LockSemaphoreInfo(log_semaphore);
- log_info=(LogInfo *) GetValueFromLinkedList(log_list,0);
+ log_info=(LogInfo *) GetValueFromLinkedList(log_cache,0);
log_info->event_mask=(LogEventType) option;
if (option == -1)
log_info->event_mask=UndefinedEvents;
log_info->format=ConstantString(format);
UnlockSemaphoreInfo(log_semaphore);
}
+
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% S e t L o g M e t h o d %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% SetLogMethod() sets the method that will be called when an event is logged.
+%
+% The format of the SetLogMethod method is:
+%
+% void SetLogMethod(MagickLogMethod method)
+%
+% A description of each parameter follows:
+%
+% o method: pointer to a method that will be called when LogMagickEvent is
+% being called.
+%
+*/
+MagickExport void SetLogMethod(MagickLogMethod method)
+{
+ ExceptionInfo
+ *exception;
+
+ LogInfo
+ *log_info;
+
+ exception=AcquireExceptionInfo();
+ log_info=(LogInfo *) GetLogInfo("*",exception);
+ exception=DestroyExceptionInfo(exception);
+ LockSemaphoreInfo(log_semaphore);
+ log_info=(LogInfo *) GetValueFromLinkedList(log_cache,0);
+ log_info->handler_mask=(LogHandlerType) (log_info->handler_mask |
+ MethodHandler);
+ log_info->method=method;
+ UnlockSemaphoreInfo(log_semaphore);
+}
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%