cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % L OOO GGGG % |
| 7 | % L O O G % |
| 8 | % L O O G GG % |
| 9 | % L O O G G % |
| 10 | % LLLLL OOO GGG % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Log Events % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % September 2002 % |
| 18 | % % |
| 19 | % % |
cristy | 45ef08f | 2012-12-07 13:13:34 +0000 | [diff] [blame] | 20 | % Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/client.h" |
| 45 | #include "MagickCore/configure.h" |
cristy | 9639ba3 | 2011-09-05 15:09:42 +0000 | [diff] [blame] | 46 | #include "MagickCore/configure-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 47 | #include "MagickCore/exception.h" |
| 48 | #include "MagickCore/exception-private.h" |
| 49 | #include "MagickCore/hashmap.h" |
| 50 | #include "MagickCore/log.h" |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 51 | #include "MagickCore/log-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 52 | #include "MagickCore/memory_.h" |
| 53 | #include "MagickCore/option.h" |
| 54 | #include "MagickCore/semaphore.h" |
| 55 | #include "MagickCore/timer.h" |
| 56 | #include "MagickCore/string_.h" |
| 57 | #include "MagickCore/string-private.h" |
| 58 | #include "MagickCore/token.h" |
| 59 | #include "MagickCore/thread_.h" |
| 60 | #include "MagickCore/thread-private.h" |
| 61 | #include "MagickCore/utility.h" |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 62 | #include "MagickCore/utility-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 63 | #include "MagickCore/version.h" |
| 64 | #include "MagickCore/xml-tree.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 65 | |
| 66 | /* |
| 67 | Define declarations. |
| 68 | */ |
| 69 | #define LogFilename "log.xml" |
| 70 | |
| 71 | /* |
| 72 | Typedef declarations. |
| 73 | */ |
| 74 | typedef enum |
| 75 | { |
| 76 | UndefinedHandler = 0x0000, |
| 77 | NoHandler = 0x0000, |
| 78 | ConsoleHandler = 0x0001, |
| 79 | StdoutHandler = 0x0002, |
| 80 | StderrHandler = 0x0004, |
| 81 | FileHandler = 0x0008, |
| 82 | DebugHandler = 0x0010, |
| 83 | EventHandler = 0x0020 |
| 84 | } LogHandlerType; |
| 85 | |
| 86 | typedef struct _EventInfo |
| 87 | { |
| 88 | char |
| 89 | *name; |
| 90 | |
| 91 | LogEventType |
| 92 | event; |
| 93 | } EventInfo; |
| 94 | |
| 95 | typedef struct _HandlerInfo |
| 96 | { |
| 97 | const char |
| 98 | *name; |
| 99 | |
| 100 | LogHandlerType |
| 101 | handler; |
| 102 | } HandlerInfo; |
| 103 | |
| 104 | struct _LogInfo |
| 105 | { |
| 106 | LogEventType |
| 107 | event_mask; |
| 108 | |
| 109 | LogHandlerType |
| 110 | handler_mask; |
| 111 | |
| 112 | char |
| 113 | *path, |
| 114 | *name, |
| 115 | *filename, |
| 116 | *format; |
| 117 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 118 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 119 | generations, |
| 120 | limit; |
| 121 | |
| 122 | FILE |
| 123 | *file; |
| 124 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 125 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 126 | generation; |
| 127 | |
| 128 | MagickBooleanType |
| 129 | append, |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 130 | exempt, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 131 | stealth; |
| 132 | |
| 133 | TimerInfo |
| 134 | timer; |
| 135 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 136 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 137 | signature; |
| 138 | }; |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 139 | |
| 140 | typedef struct _LogMapInfo |
| 141 | { |
| 142 | const LogEventType |
| 143 | event_mask; |
| 144 | |
| 145 | const LogHandlerType |
| 146 | handler_mask; |
| 147 | |
| 148 | const char |
| 149 | *filename, |
| 150 | *format; |
| 151 | } LogMapInfo; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 152 | |
| 153 | /* |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 154 | Static declarations. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 155 | */ |
| 156 | static const HandlerInfo |
| 157 | LogHandlers[] = |
| 158 | { |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 159 | { "Console", ConsoleHandler }, |
| 160 | { "Debug", DebugHandler }, |
| 161 | { "Event", EventHandler }, |
| 162 | { "File", FileHandler }, |
| 163 | { "None", NoHandler }, |
| 164 | { "Stderr", StderrHandler }, |
| 165 | { "Stdout", StdoutHandler }, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 166 | { (char *) NULL, UndefinedHandler } |
| 167 | }; |
| 168 | |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 169 | static const LogMapInfo |
| 170 | LogMap[] = |
| 171 | { |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 172 | { NoEvents, ConsoleHandler, "Magick-%g.log", |
| 173 | "%t %r %u %v %d %c[%p]: %m/%f/%l/%d\\n %e" } |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 174 | }; |
| 175 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 176 | static char |
| 177 | log_name[MaxTextExtent] = "Magick"; |
| 178 | |
| 179 | static LinkedListInfo |
| 180 | *log_list = (LinkedListInfo *) NULL; |
| 181 | |
| 182 | static SemaphoreInfo |
| 183 | *log_semaphore = (SemaphoreInfo *) NULL; |
| 184 | |
| 185 | static volatile MagickBooleanType |
| 186 | instantiate_log = MagickFalse; |
| 187 | |
| 188 | /* |
| 189 | Forward declarations. |
| 190 | */ |
| 191 | static LogHandlerType |
| 192 | ParseLogHandlers(const char *); |
| 193 | |
| 194 | static LogInfo |
| 195 | *GetLogInfo(const char *,ExceptionInfo *); |
| 196 | |
| 197 | static MagickBooleanType |
| 198 | InitializeLogList(ExceptionInfo *), |
| 199 | LoadLogLists(const char *,ExceptionInfo *); |
| 200 | |
| 201 | /* |
| 202 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 203 | % % |
| 204 | % % |
| 205 | % % |
| 206 | % C l o s e M a g i c k L o g % |
| 207 | % % |
| 208 | % % |
| 209 | % % |
| 210 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 211 | % |
| 212 | % CloseMagickLog() closes the Magick log. |
| 213 | % |
| 214 | % The format of the CloseMagickLog method is: |
| 215 | % |
| 216 | % CloseMagickLog(void) |
| 217 | % |
| 218 | */ |
| 219 | MagickExport void CloseMagickLog(void) |
| 220 | { |
| 221 | ExceptionInfo |
| 222 | *exception; |
| 223 | |
| 224 | LogInfo |
| 225 | *log_info; |
| 226 | |
| 227 | if (IsEventLogging() == MagickFalse) |
| 228 | return; |
| 229 | exception=AcquireExceptionInfo(); |
| 230 | log_info=GetLogInfo("*",exception); |
| 231 | exception=DestroyExceptionInfo(exception); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 232 | LockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 233 | if (log_info->file != (FILE *) NULL) |
| 234 | { |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 235 | (void) FormatLocaleFile(log_info->file,"</log>\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 236 | (void) fclose(log_info->file); |
| 237 | log_info->file=(FILE *) NULL; |
| 238 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 239 | UnlockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | /* |
| 243 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 244 | % % |
| 245 | % % |
| 246 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 247 | + G e t L o g I n f o % |
| 248 | % % |
| 249 | % % |
| 250 | % % |
| 251 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 252 | % |
| 253 | % GetLogInfo() searches the log list for the specified name and if found |
| 254 | % returns attributes for that log. |
| 255 | % |
| 256 | % The format of the GetLogInfo method is: |
| 257 | % |
| 258 | % LogInfo *GetLogInfo(const char *name,ExceptionInfo *exception) |
| 259 | % |
| 260 | % A description of each parameter follows: |
| 261 | % |
| 262 | % o name: the log name. |
| 263 | % |
| 264 | % o exception: return any errors or warnings in this structure. |
| 265 | % |
| 266 | */ |
| 267 | static LogInfo *GetLogInfo(const char *name,ExceptionInfo *exception) |
| 268 | { |
| 269 | register LogInfo |
| 270 | *p; |
| 271 | |
| 272 | assert(exception != (ExceptionInfo *) NULL); |
| 273 | if ((log_list == (LinkedListInfo *) NULL) || (instantiate_log == MagickFalse)) |
| 274 | if (InitializeLogList(exception) == MagickFalse) |
| 275 | return((LogInfo *) NULL); |
| 276 | if ((log_list == (LinkedListInfo *) NULL) || |
| 277 | (IsLinkedListEmpty(log_list) != MagickFalse)) |
| 278 | return((LogInfo *) NULL); |
| 279 | if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) |
| 280 | return((LogInfo *) GetValueFromLinkedList(log_list,0)); |
| 281 | /* |
| 282 | Search for log tag. |
| 283 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 284 | LockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 285 | ResetLinkedListIterator(log_list); |
| 286 | p=(LogInfo *) GetNextValueInLinkedList(log_list); |
| 287 | while (p != (LogInfo *) NULL) |
| 288 | { |
| 289 | if (LocaleCompare(name,p->name) == 0) |
| 290 | break; |
| 291 | p=(LogInfo *) GetNextValueInLinkedList(log_list); |
| 292 | } |
| 293 | if (p != (LogInfo *) NULL) |
| 294 | (void) InsertValueInLinkedList(log_list,0, |
| 295 | RemoveElementByValueFromLinkedList(log_list,p)); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 296 | UnlockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 297 | return(p); |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 302 | % % |
| 303 | % % |
| 304 | % % |
| 305 | % G e t L o g I n f o L i s t % |
| 306 | % % |
| 307 | % % |
| 308 | % % |
| 309 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 310 | % |
| 311 | % GetLogInfoList() returns any logs that match the specified pattern. |
| 312 | % |
| 313 | % The format of the GetLogInfoList function is: |
| 314 | % |
| 315 | % const LogInfo **GetLogInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 316 | % size_t *number_preferences,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 317 | % |
| 318 | % A description of each parameter follows: |
| 319 | % |
| 320 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 321 | % |
| 322 | % o number_preferences: This integer returns the number of logs in the list. |
| 323 | % |
| 324 | % o exception: return any errors or warnings in this structure. |
| 325 | % |
| 326 | */ |
| 327 | #if defined(__cplusplus) || defined(c_plusplus) |
| 328 | extern "C" { |
| 329 | #endif |
| 330 | |
| 331 | static int LogInfoCompare(const void *x,const void *y) |
| 332 | { |
| 333 | const LogInfo |
| 334 | **p, |
| 335 | **q; |
| 336 | |
| 337 | p=(const LogInfo **) x, |
| 338 | q=(const LogInfo **) y; |
| 339 | if (LocaleCompare((*p)->path,(*q)->path) == 0) |
| 340 | return(LocaleCompare((*p)->name,(*q)->name)); |
| 341 | return(LocaleCompare((*p)->path,(*q)->path)); |
| 342 | } |
| 343 | |
| 344 | #if defined(__cplusplus) || defined(c_plusplus) |
| 345 | } |
| 346 | #endif |
| 347 | |
| 348 | MagickExport const LogInfo **GetLogInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 349 | size_t *number_preferences,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 350 | { |
| 351 | const LogInfo |
| 352 | **preferences; |
| 353 | |
| 354 | register const LogInfo |
| 355 | *p; |
| 356 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 357 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 358 | i; |
| 359 | |
| 360 | /* |
| 361 | Allocate log list. |
| 362 | */ |
| 363 | assert(pattern != (char *) NULL); |
| 364 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 365 | assert(number_preferences != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 366 | *number_preferences=0; |
| 367 | p=GetLogInfo("*",exception); |
| 368 | if (p == (const LogInfo *) NULL) |
| 369 | return((const LogInfo **) NULL); |
| 370 | preferences=(const LogInfo **) AcquireQuantumMemory((size_t) |
| 371 | GetNumberOfElementsInLinkedList(log_list)+1UL,sizeof(*preferences)); |
| 372 | if (preferences == (const LogInfo **) NULL) |
| 373 | return((const LogInfo **) NULL); |
| 374 | /* |
| 375 | Generate log list. |
| 376 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 377 | LockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 378 | ResetLinkedListIterator(log_list); |
| 379 | p=(const LogInfo *) GetNextValueInLinkedList(log_list); |
| 380 | for (i=0; p != (const LogInfo *) NULL; ) |
| 381 | { |
| 382 | if ((p->stealth == MagickFalse) && |
| 383 | (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) |
| 384 | preferences[i++]=p; |
| 385 | p=(const LogInfo *) GetNextValueInLinkedList(log_list); |
| 386 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 387 | UnlockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 388 | qsort((void *) preferences,(size_t) i,sizeof(*preferences),LogInfoCompare); |
| 389 | preferences[i]=(LogInfo *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 390 | *number_preferences=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 391 | return(preferences); |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 396 | % % |
| 397 | % % |
| 398 | % % |
| 399 | % G e t L o g L i s t % |
| 400 | % % |
| 401 | % % |
| 402 | % % |
| 403 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 404 | % |
| 405 | % GetLogList() returns any logs that match the specified pattern. |
| 406 | % |
| 407 | % The format of the GetLogList function is: |
| 408 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 409 | % char **GetLogList(const char *pattern,size_t *number_preferences, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 410 | % ExceptionInfo *exception) |
| 411 | % |
| 412 | % A description of each parameter follows: |
| 413 | % |
| 414 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 415 | % |
| 416 | % o number_preferences: This integer returns the number of logs in the list. |
| 417 | % |
| 418 | % o exception: return any errors or warnings in this structure. |
| 419 | % |
| 420 | */ |
| 421 | |
| 422 | #if defined(__cplusplus) || defined(c_plusplus) |
| 423 | extern "C" { |
| 424 | #endif |
| 425 | |
| 426 | static int LogCompare(const void *x,const void *y) |
| 427 | { |
| 428 | register const char |
| 429 | **p, |
| 430 | **q; |
| 431 | |
| 432 | p=(const char **) x; |
| 433 | q=(const char **) y; |
| 434 | return(LocaleCompare(*p,*q)); |
| 435 | } |
| 436 | |
| 437 | #if defined(__cplusplus) || defined(c_plusplus) |
| 438 | } |
| 439 | #endif |
| 440 | |
| 441 | MagickExport char **GetLogList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 442 | size_t *number_preferences,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 443 | { |
| 444 | char |
| 445 | **preferences; |
| 446 | |
| 447 | register const LogInfo |
| 448 | *p; |
| 449 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 450 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 451 | i; |
| 452 | |
| 453 | /* |
| 454 | Allocate log list. |
| 455 | */ |
| 456 | assert(pattern != (char *) NULL); |
| 457 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 458 | assert(number_preferences != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 459 | *number_preferences=0; |
| 460 | p=GetLogInfo("*",exception); |
| 461 | if (p == (const LogInfo *) NULL) |
| 462 | return((char **) NULL); |
| 463 | preferences=(char **) AcquireQuantumMemory((size_t) |
| 464 | GetNumberOfElementsInLinkedList(log_list)+1UL,sizeof(*preferences)); |
| 465 | if (preferences == (char **) NULL) |
| 466 | return((char **) NULL); |
| 467 | /* |
| 468 | Generate log list. |
| 469 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 470 | LockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 471 | ResetLinkedListIterator(log_list); |
| 472 | p=(const LogInfo *) GetNextValueInLinkedList(log_list); |
| 473 | for (i=0; p != (const LogInfo *) NULL; ) |
| 474 | { |
| 475 | if ((p->stealth == MagickFalse) && |
| 476 | (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) |
| 477 | preferences[i++]=ConstantString(p->name); |
| 478 | p=(const LogInfo *) GetNextValueInLinkedList(log_list); |
| 479 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 480 | UnlockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 481 | qsort((void *) preferences,(size_t) i,sizeof(*preferences),LogCompare); |
| 482 | preferences[i]=(char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 483 | *number_preferences=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 484 | return(preferences); |
| 485 | } |
| 486 | |
| 487 | /* |
| 488 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 489 | % % |
| 490 | % % |
| 491 | % % |
| 492 | % G e t L o g N a m e % |
| 493 | % % |
| 494 | % % |
| 495 | % % |
| 496 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 497 | % |
| 498 | % GetLogName() returns the current log name. |
| 499 | % |
| 500 | % The format of the GetLogName method is: |
| 501 | % |
| 502 | % const char *GetLogName(void) |
| 503 | % |
| 504 | */ |
| 505 | MagickExport const char *GetLogName(void) |
| 506 | { |
| 507 | return(log_name); |
| 508 | } |
| 509 | |
| 510 | /* |
| 511 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 512 | % % |
| 513 | % % |
| 514 | % % |
| 515 | + I n i t i a l i z e L o g L i s t % |
| 516 | % % |
| 517 | % % |
| 518 | % % |
| 519 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 520 | % |
| 521 | % InitializeLogList() initialize the log list. |
| 522 | % |
| 523 | % The format of the InitializeLogList method is: |
| 524 | % |
| 525 | % MagickBooleanType InitializeLogList(ExceptionInfo *exception) |
| 526 | % |
| 527 | % A description of each parameter follows. |
| 528 | % |
| 529 | % o exception: return any errors or warnings in this structure. |
| 530 | % |
| 531 | */ |
| 532 | static MagickBooleanType InitializeLogList(ExceptionInfo *exception) |
| 533 | { |
| 534 | if ((log_list == (LinkedListInfo *) NULL) && (instantiate_log == MagickFalse)) |
| 535 | { |
cristy | 4e1dff6 | 2009-10-25 20:36:03 +0000 | [diff] [blame] | 536 | if (log_semaphore == (SemaphoreInfo *) NULL) |
| 537 | AcquireSemaphoreInfo(&log_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 538 | LockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 539 | if ((log_list == (LinkedListInfo *) NULL) && |
| 540 | (instantiate_log == MagickFalse)) |
| 541 | { |
| 542 | (void) LoadLogLists(LogFilename,exception); |
| 543 | instantiate_log=MagickTrue; |
| 544 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 545 | UnlockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 546 | } |
| 547 | return(log_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); |
| 548 | } |
| 549 | |
| 550 | /* |
| 551 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 552 | % % |
| 553 | % % |
| 554 | % % |
| 555 | % I s E v e n t L o g g i n g % |
| 556 | % % |
| 557 | % % |
| 558 | % % |
| 559 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 560 | % |
| 561 | % IsEventLogging() returns MagickTrue if debug of events is enabled otherwise |
| 562 | % MagickFalse. |
| 563 | % |
| 564 | % The format of the IsEventLogging method is: |
| 565 | % |
| 566 | % MagickBooleanType IsEventLogging(void) |
| 567 | % |
| 568 | */ |
| 569 | MagickExport MagickBooleanType IsEventLogging(void) |
| 570 | { |
| 571 | const LogInfo |
| 572 | *log_info; |
| 573 | |
| 574 | ExceptionInfo |
| 575 | *exception; |
| 576 | |
| 577 | if ((log_list == (LinkedListInfo *) NULL) || |
| 578 | (IsLinkedListEmpty(log_list) != MagickFalse)) |
| 579 | return(MagickFalse); |
| 580 | exception=AcquireExceptionInfo(); |
| 581 | log_info=GetLogInfo("*",exception); |
| 582 | exception=DestroyExceptionInfo(exception); |
| 583 | return(log_info->event_mask != NoEvents ? MagickTrue : MagickFalse); |
| 584 | } |
| 585 | /* |
| 586 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 587 | % % |
| 588 | % % |
| 589 | % % |
| 590 | % L i s t L o g I n f o % |
| 591 | % % |
| 592 | % % |
| 593 | % % |
| 594 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 595 | % |
| 596 | % ListLogInfo() lists the log info to a file. |
| 597 | % |
| 598 | % The format of the ListLogInfo method is: |
| 599 | % |
| 600 | % MagickBooleanType ListLogInfo(FILE *file,ExceptionInfo *exception) |
| 601 | % |
| 602 | % A description of each parameter follows. |
| 603 | % |
| 604 | % o file: An pointer to a FILE. |
| 605 | % |
| 606 | % o exception: return any errors or warnings in this structure. |
| 607 | % |
| 608 | */ |
| 609 | MagickExport MagickBooleanType ListLogInfo(FILE *file,ExceptionInfo *exception) |
| 610 | { |
| 611 | #define MegabytesToBytes(value) ((MagickSizeType) (value)*1024*1024) |
| 612 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 613 | const char |
| 614 | *path; |
| 615 | |
| 616 | const LogInfo |
| 617 | **log_info; |
| 618 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 619 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 620 | i; |
| 621 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 622 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 623 | number_aliases; |
| 624 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 625 | ssize_t |
| 626 | j; |
| 627 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 628 | if (file == (const FILE *) NULL) |
| 629 | file=stdout; |
| 630 | log_info=GetLogInfoList("*",&number_aliases,exception); |
| 631 | if (log_info == (const LogInfo **) NULL) |
| 632 | return(MagickFalse); |
| 633 | j=0; |
| 634 | path=(const char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 635 | for (i=0; i < (ssize_t) number_aliases; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 636 | { |
| 637 | if (log_info[i]->stealth != MagickFalse) |
| 638 | continue; |
| 639 | if ((path == (const char *) NULL) || |
| 640 | (LocaleCompare(path,log_info[i]->path) != 0)) |
| 641 | { |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 642 | size_t |
| 643 | length; |
| 644 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 645 | if (log_info[i]->path != (char *) NULL) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 646 | (void) FormatLocaleFile(file,"\nPath: %s\n\n",log_info[i]->path); |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 647 | length=0; |
| 648 | for (j=0; j < (ssize_t) (8*sizeof(LogHandlerType)); j++) |
| 649 | { |
| 650 | size_t |
| 651 | mask; |
| 652 | |
cristy | fb8f6e1 | 2013-07-10 12:35:27 +0000 | [diff] [blame] | 653 | mask=1; |
| 654 | mask<<=j; |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 655 | if ((log_info[i]->handler_mask & mask) != 0) |
| 656 | { |
| 657 | (void) FormatLocaleFile(file,"%s ",LogHandlers[j].name); |
| 658 | length+=strlen(LogHandlers[j].name); |
| 659 | } |
| 660 | } |
| 661 | for (j=(ssize_t) length; j <= 12; j++) |
| 662 | (void) FormatLocaleFile(file," "); |
| 663 | (void) FormatLocaleFile(file," Generations Limit Format\n"); |
| 664 | (void) FormatLocaleFile(file,"-----------------------------------------" |
| 665 | "--------------------------------------\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 666 | } |
| 667 | path=log_info[i]->path; |
| 668 | if (log_info[i]->filename != (char *) NULL) |
| 669 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 670 | (void) FormatLocaleFile(file,"%s",log_info[i]->filename); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 671 | for (j=(ssize_t) strlen(log_info[i]->filename); j <= 16; j++) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 672 | (void) FormatLocaleFile(file," "); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 673 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 674 | (void) FormatLocaleFile(file,"%9g ",(double) log_info[i]->generations); |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 675 | (void) FormatLocaleFile(file,"%8g ",(double) log_info[i]->limit); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 676 | if (log_info[i]->format != (char *) NULL) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 677 | (void) FormatLocaleFile(file,"%s",log_info[i]->format); |
| 678 | (void) FormatLocaleFile(file,"\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 679 | } |
| 680 | (void) fflush(file); |
| 681 | log_info=(const LogInfo **) RelinquishMagickMemory((void *) log_info); |
| 682 | return(MagickTrue); |
| 683 | } |
| 684 | |
| 685 | /* |
| 686 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 687 | % % |
| 688 | % % |
| 689 | % % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 690 | + L o g C o m p o n e n t G e n e s i s % |
| 691 | % % |
| 692 | % % |
| 693 | % % |
| 694 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 695 | % |
| 696 | % LogComponentGenesis() instantiates the log component. |
| 697 | % |
| 698 | % The format of the LogComponentGenesis method is: |
| 699 | % |
| 700 | % MagickBooleanType LogComponentGenesis(void) |
| 701 | % |
| 702 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 703 | MagickPrivate MagickBooleanType LogComponentGenesis(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 704 | { |
cristy | 85dfbbb | 2013-08-02 16:02:35 +0000 | [diff] [blame^] | 705 | ExceptionInfo |
| 706 | *exception; |
| 707 | |
cristy | 165b609 | 2009-10-26 13:52:10 +0000 | [diff] [blame] | 708 | AcquireSemaphoreInfo(&log_semaphore); |
cristy | 85dfbbb | 2013-08-02 16:02:35 +0000 | [diff] [blame^] | 709 | exception=AcquireExceptionInfo(); |
| 710 | (void) GetLogInfo("*",exception); |
| 711 | exception=DestroyExceptionInfo(exception); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 712 | return(MagickTrue); |
| 713 | } |
| 714 | |
| 715 | /* |
| 716 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 717 | % % |
| 718 | % % |
| 719 | % % |
| 720 | + L o g C o m p o n e n t T e r m i n u s % |
| 721 | % % |
| 722 | % % |
| 723 | % % |
| 724 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 725 | % |
| 726 | % LogComponentTerminus() destroys the logging component. |
| 727 | % |
| 728 | % The format of the LogComponentTerminus method is: |
| 729 | % |
| 730 | % LogComponentTerminus(void) |
| 731 | % |
| 732 | */ |
| 733 | |
| 734 | static void *DestroyLogElement(void *log_info) |
| 735 | { |
| 736 | register LogInfo |
| 737 | *p; |
| 738 | |
| 739 | p=(LogInfo *) log_info; |
| 740 | if (p->file != (FILE *) NULL) |
| 741 | { |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 742 | (void) FormatLocaleFile(p->file,"</log>\n"); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 743 | (void) fclose(p->file); |
| 744 | p->file=(FILE *) NULL; |
| 745 | } |
| 746 | if (p->exempt == MagickFalse) |
| 747 | { |
| 748 | if (p->format != (char *) NULL) |
| 749 | p->format=DestroyString(p->format); |
| 750 | if (p->path != (char *) NULL) |
| 751 | p->path=DestroyString(p->path); |
| 752 | if (p->filename != (char *) NULL) |
| 753 | p->filename=DestroyString(p->filename); |
| 754 | } |
| 755 | p=(LogInfo *) RelinquishMagickMemory(p); |
| 756 | return((void *) NULL); |
| 757 | } |
| 758 | |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 759 | MagickPrivate void LogComponentTerminus(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 760 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 761 | if (log_semaphore == (SemaphoreInfo *) NULL) |
| 762 | AcquireSemaphoreInfo(&log_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 763 | LockSemaphoreInfo(log_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 764 | if (log_list != (LinkedListInfo *) NULL) |
| 765 | log_list=DestroyLinkedList(log_list,DestroyLogElement); |
| 766 | instantiate_log=MagickFalse; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 767 | UnlockSemaphoreInfo(log_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 768 | DestroySemaphoreInfo(&log_semaphore); |
| 769 | } |
| 770 | |
| 771 | /* |
| 772 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 773 | % % |
| 774 | % % |
| 775 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 776 | % L o g M a g i c k E v e n t % |
| 777 | % % |
| 778 | % % |
| 779 | % % |
| 780 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 781 | % |
| 782 | % LogMagickEvent() logs an event as determined by the log configuration file. |
| 783 | % If an error occurs, MagickFalse is returned otherwise MagickTrue. |
| 784 | % |
| 785 | % The format of the LogMagickEvent method is: |
| 786 | % |
| 787 | % MagickBooleanType LogMagickEvent(const LogEventType type, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 788 | % const char *module,const char *function,const size_t line, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 789 | % const char *format,...) |
| 790 | % |
| 791 | % A description of each parameter follows: |
| 792 | % |
| 793 | % o type: the event type. |
| 794 | % |
| 795 | % o filename: the source module filename. |
| 796 | % |
| 797 | % o function: the function name. |
| 798 | % |
| 799 | % o line: the line number of the source module. |
| 800 | % |
| 801 | % o format: the output format. |
| 802 | % |
| 803 | */ |
| 804 | static char *TranslateEvent(const LogEventType magick_unused(type), |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 805 | const char *module,const char *function,const size_t line, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 806 | const char *domain,const char *event) |
| 807 | { |
| 808 | char |
| 809 | *text; |
| 810 | |
| 811 | double |
| 812 | elapsed_time, |
| 813 | user_time; |
| 814 | |
| 815 | ExceptionInfo |
| 816 | *exception; |
| 817 | |
| 818 | LogInfo |
| 819 | *log_info; |
| 820 | |
| 821 | register char |
| 822 | *q; |
| 823 | |
| 824 | register const char |
| 825 | *p; |
| 826 | |
| 827 | size_t |
| 828 | extent; |
| 829 | |
| 830 | time_t |
| 831 | seconds; |
| 832 | |
| 833 | exception=AcquireExceptionInfo(); |
| 834 | log_info=(LogInfo *) GetLogInfo("*",exception); |
| 835 | exception=DestroyExceptionInfo(exception); |
| 836 | seconds=time((time_t *) NULL); |
| 837 | elapsed_time=GetElapsedTime(&log_info->timer); |
| 838 | user_time=GetUserTime(&log_info->timer); |
| 839 | text=AcquireString(event); |
| 840 | if (log_info->format == (char *) NULL) |
| 841 | return(text); |
| 842 | extent=strlen(event)+MaxTextExtent; |
| 843 | if (LocaleCompare(log_info->format,"xml") == 0) |
| 844 | { |
| 845 | char |
| 846 | timestamp[MaxTextExtent]; |
| 847 | |
| 848 | /* |
| 849 | Translate event in "XML" format. |
| 850 | */ |
| 851 | (void) FormatMagickTime(seconds,extent,timestamp); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 852 | (void) FormatLocaleString(text,extent, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 853 | "<entry>\n" |
| 854 | " <timestamp>%s</timestamp>\n" |
cristy | 91f905a | 2010-06-03 01:01:32 +0000 | [diff] [blame] | 855 | " <elapsed-time>%lu:%02lu.%03lu</elapsed-time>\n" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 856 | " <user-time>%0.3f</user-time>\n" |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 857 | " <process-id>%.20g</process-id>\n" |
| 858 | " <thread-id>%.20g</thread-id>\n" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 859 | " <module>%s</module>\n" |
| 860 | " <function>%s</function>\n" |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 861 | " <line>%.20g</line>\n" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 862 | " <domain>%s</domain>\n" |
| 863 | " <event>%s</event>\n" |
cristy | 91f905a | 2010-06-03 01:01:32 +0000 | [diff] [blame] | 864 | "</entry>",timestamp,(unsigned long) (elapsed_time/60.0), |
| 865 | (unsigned long) floor(fmod(elapsed_time,60.0)),(unsigned long) |
| 866 | (1000.0*(elapsed_time-floor(elapsed_time))+0.5),user_time, |
| 867 | (double) getpid(),(double) GetMagickThreadSignature(),module,function, |
| 868 | (double) line,domain,event); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 869 | return(text); |
| 870 | } |
| 871 | /* |
| 872 | Translate event in "human readable" format. |
| 873 | */ |
| 874 | q=text; |
| 875 | for (p=log_info->format; *p != '\0'; p++) |
| 876 | { |
| 877 | *q='\0'; |
| 878 | if ((size_t) (q-text+MaxTextExtent) >= extent) |
| 879 | { |
| 880 | extent+=MaxTextExtent; |
| 881 | text=(char *) ResizeQuantumMemory(text,extent+MaxTextExtent, |
| 882 | sizeof(*text)); |
| 883 | if (text == (char *) NULL) |
| 884 | return((char *) NULL); |
| 885 | q=text+strlen(text); |
| 886 | } |
| 887 | /* |
| 888 | The format of the log is defined by embedding special format characters: |
| 889 | |
| 890 | %c client name |
| 891 | %d domain |
| 892 | %e event |
| 893 | %f function |
| 894 | %g generation |
| 895 | %l line |
| 896 | %m module |
| 897 | %n log name |
| 898 | %p process id |
| 899 | %r real CPU time |
| 900 | %t wall clock time |
| 901 | %u user CPU time |
| 902 | %v version |
| 903 | %% percent sign |
| 904 | \n newline |
| 905 | \r carriage return |
| 906 | */ |
| 907 | if ((*p == '\\') && (*(p+1) == 'r')) |
| 908 | { |
| 909 | *q++='\r'; |
| 910 | p++; |
| 911 | continue; |
| 912 | } |
| 913 | if ((*p == '\\') && (*(p+1) == 'n')) |
| 914 | { |
| 915 | *q++='\n'; |
| 916 | p++; |
| 917 | continue; |
| 918 | } |
| 919 | if (*p != '%') |
| 920 | { |
| 921 | *q++=(*p); |
| 922 | continue; |
| 923 | } |
| 924 | p++; |
| 925 | switch (*p) |
| 926 | { |
| 927 | case 'c': |
| 928 | { |
| 929 | q+=CopyMagickString(q,GetClientName(),extent); |
| 930 | break; |
| 931 | } |
| 932 | case 'd': |
| 933 | { |
| 934 | q+=CopyMagickString(q,domain,extent); |
| 935 | break; |
| 936 | } |
| 937 | case 'e': |
| 938 | { |
| 939 | q+=CopyMagickString(q,event,extent); |
| 940 | break; |
| 941 | } |
| 942 | case 'f': |
| 943 | { |
| 944 | q+=CopyMagickString(q,function,extent); |
| 945 | break; |
| 946 | } |
| 947 | case 'g': |
| 948 | { |
| 949 | if (log_info->generations == 0) |
| 950 | { |
| 951 | (void) CopyMagickString(q,"0",extent); |
| 952 | q++; |
| 953 | break; |
| 954 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 955 | q+=FormatLocaleString(q,extent,"%.20g",(double) (log_info->generation % |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 956 | log_info->generations)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 957 | break; |
| 958 | } |
| 959 | case 'l': |
| 960 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 961 | q+=FormatLocaleString(q,extent,"%.20g",(double) line); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 962 | break; |
| 963 | } |
| 964 | case 'm': |
| 965 | { |
| 966 | register const char |
| 967 | *p; |
| 968 | |
| 969 | for (p=module+strlen(module)-1; p > module; p--) |
| 970 | if (*p == *DirectorySeparator) |
| 971 | { |
| 972 | p++; |
| 973 | break; |
| 974 | } |
| 975 | q+=CopyMagickString(q,p,extent); |
| 976 | break; |
| 977 | } |
| 978 | case 'n': |
| 979 | { |
| 980 | q+=CopyMagickString(q,GetLogName(),extent); |
| 981 | break; |
| 982 | } |
| 983 | case 'p': |
| 984 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 985 | q+=FormatLocaleString(q,extent,"%.20g",(double) getpid()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 986 | break; |
| 987 | } |
| 988 | case 'r': |
| 989 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 990 | q+=FormatLocaleString(q,extent,"%lu:%02lu.%03lu",(unsigned long) |
cristy | 91f905a | 2010-06-03 01:01:32 +0000 | [diff] [blame] | 991 | (elapsed_time/60.0),(unsigned long) floor(fmod(elapsed_time,60.0)), |
| 992 | (unsigned long) (1000.0*(elapsed_time-floor(elapsed_time))+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 993 | break; |
| 994 | } |
| 995 | case 't': |
| 996 | { |
| 997 | q+=FormatMagickTime(seconds,extent,q); |
| 998 | break; |
| 999 | } |
| 1000 | case 'u': |
| 1001 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1002 | q+=FormatLocaleString(q,extent,"%0.3fu",user_time); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1003 | break; |
| 1004 | } |
| 1005 | case 'v': |
| 1006 | { |
| 1007 | q+=CopyMagickString(q,MagickLibVersionText,extent); |
| 1008 | break; |
| 1009 | } |
| 1010 | case '%': |
| 1011 | { |
| 1012 | *q++=(*p); |
| 1013 | break; |
| 1014 | } |
| 1015 | default: |
| 1016 | { |
| 1017 | *q++='%'; |
| 1018 | *q++=(*p); |
| 1019 | break; |
| 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | *q='\0'; |
| 1024 | return(text); |
| 1025 | } |
| 1026 | |
| 1027 | static char *TranslateFilename(const LogInfo *log_info) |
| 1028 | { |
| 1029 | char |
| 1030 | *filename; |
| 1031 | |
| 1032 | register char |
| 1033 | *q; |
| 1034 | |
| 1035 | register const char |
| 1036 | *p; |
| 1037 | |
| 1038 | size_t |
| 1039 | extent; |
| 1040 | |
| 1041 | /* |
| 1042 | Translate event in "human readable" format. |
| 1043 | */ |
| 1044 | assert(log_info != (LogInfo *) NULL); |
| 1045 | assert(log_info->filename != (char *) NULL); |
| 1046 | filename=AcquireString((char *) NULL); |
| 1047 | extent=MaxTextExtent; |
| 1048 | q=filename; |
| 1049 | for (p=log_info->filename; *p != '\0'; p++) |
| 1050 | { |
| 1051 | *q='\0'; |
| 1052 | if ((size_t) (q-filename+MaxTextExtent) >= extent) |
| 1053 | { |
| 1054 | extent+=MaxTextExtent; |
| 1055 | filename=(char *) ResizeQuantumMemory(filename,extent+MaxTextExtent, |
| 1056 | sizeof(*filename)); |
| 1057 | if (filename == (char *) NULL) |
| 1058 | return((char *) NULL); |
| 1059 | q=filename+strlen(filename); |
| 1060 | } |
| 1061 | /* |
| 1062 | The format of the filename is defined by embedding special format |
| 1063 | characters: |
| 1064 | |
| 1065 | %c client name |
| 1066 | %n log name |
| 1067 | %p process id |
| 1068 | %v version |
| 1069 | %% percent sign |
| 1070 | */ |
| 1071 | if (*p != '%') |
| 1072 | { |
| 1073 | *q++=(*p); |
| 1074 | continue; |
| 1075 | } |
| 1076 | p++; |
| 1077 | switch (*p) |
| 1078 | { |
| 1079 | case 'c': |
| 1080 | { |
| 1081 | q+=CopyMagickString(q,GetClientName(),extent); |
| 1082 | break; |
| 1083 | } |
| 1084 | case 'g': |
| 1085 | { |
| 1086 | if (log_info->generations == 0) |
| 1087 | { |
| 1088 | (void) CopyMagickString(q,"0",extent); |
| 1089 | q++; |
| 1090 | break; |
| 1091 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1092 | q+=FormatLocaleString(q,extent,"%.20g",(double) (log_info->generation % |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1093 | log_info->generations)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1094 | break; |
| 1095 | } |
| 1096 | case 'n': |
| 1097 | { |
| 1098 | q+=CopyMagickString(q,GetLogName(),extent); |
| 1099 | break; |
| 1100 | } |
| 1101 | case 'p': |
| 1102 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1103 | q+=FormatLocaleString(q,extent,"%.20g",(double) getpid()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1104 | break; |
| 1105 | } |
| 1106 | case 'v': |
| 1107 | { |
| 1108 | q+=CopyMagickString(q,MagickLibVersionText,extent); |
| 1109 | break; |
| 1110 | } |
| 1111 | case '%': |
| 1112 | { |
| 1113 | *q++=(*p); |
| 1114 | break; |
| 1115 | } |
| 1116 | default: |
| 1117 | { |
| 1118 | *q++='%'; |
| 1119 | *q++=(*p); |
| 1120 | break; |
| 1121 | } |
| 1122 | } |
| 1123 | } |
| 1124 | *q='\0'; |
| 1125 | return(filename); |
| 1126 | } |
| 1127 | |
| 1128 | MagickBooleanType LogMagickEventList(const LogEventType type,const char *module, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1129 | const char *function,const size_t line,const char *format, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1130 | va_list operands) |
| 1131 | { |
| 1132 | char |
| 1133 | event[MaxTextExtent], |
| 1134 | *text; |
| 1135 | |
| 1136 | const char |
| 1137 | *domain; |
| 1138 | |
| 1139 | ExceptionInfo |
| 1140 | *exception; |
| 1141 | |
| 1142 | int |
| 1143 | n; |
| 1144 | |
| 1145 | LogInfo |
| 1146 | *log_info; |
| 1147 | |
| 1148 | if (IsEventLogging() == MagickFalse) |
| 1149 | return(MagickFalse); |
| 1150 | exception=AcquireExceptionInfo(); |
| 1151 | log_info=(LogInfo *) GetLogInfo("*",exception); |
| 1152 | exception=DestroyExceptionInfo(exception); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1153 | LockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1154 | if ((log_info->event_mask & type) == 0) |
| 1155 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1156 | UnlockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1157 | return(MagickTrue); |
| 1158 | } |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1159 | domain=CommandOptionToMnemonic(MagickLogEventOptions,type); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1160 | #if defined(MAGICKCORE_HAVE_VSNPRINTF) |
| 1161 | n=vsnprintf(event,MaxTextExtent,format,operands); |
| 1162 | #else |
| 1163 | n=vsprintf(event,format,operands); |
| 1164 | #endif |
| 1165 | if (n < 0) |
| 1166 | event[MaxTextExtent-1]='\0'; |
| 1167 | text=TranslateEvent(type,module,function,line,domain,event); |
| 1168 | if (text == (char *) NULL) |
| 1169 | { |
| 1170 | (void) ContinueTimer((TimerInfo *) &log_info->timer); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1171 | UnlockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1172 | return(MagickFalse); |
| 1173 | } |
| 1174 | if ((log_info->handler_mask & ConsoleHandler) != 0) |
| 1175 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1176 | (void) FormatLocaleFile(stderr,"%s\n",text); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1177 | (void) fflush(stderr); |
| 1178 | } |
| 1179 | if ((log_info->handler_mask & DebugHandler) != 0) |
| 1180 | { |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 1181 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1182 | OutputDebugString(text); |
cristy | 690a0eb | 2013-07-24 16:43:22 +0000 | [diff] [blame] | 1183 | OutputDebugString("\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1184 | #endif |
| 1185 | } |
| 1186 | if ((log_info->handler_mask & EventHandler) != 0) |
| 1187 | { |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 1188 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1189 | (void) NTReportEvent(text,MagickFalse); |
| 1190 | #endif |
| 1191 | } |
| 1192 | if ((log_info->handler_mask & FileHandler) != 0) |
| 1193 | { |
| 1194 | struct stat |
| 1195 | file_info; |
| 1196 | |
| 1197 | file_info.st_size=0; |
| 1198 | if (log_info->file != (FILE *) NULL) |
| 1199 | (void) fstat(fileno(log_info->file),&file_info); |
cristy | 94b1183 | 2011-09-08 19:46:03 +0000 | [diff] [blame] | 1200 | if (file_info.st_size > (ssize_t) (1024*1024*log_info->limit)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1201 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1202 | (void) FormatLocaleFile(log_info->file,"</log>\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1203 | (void) fclose(log_info->file); |
| 1204 | log_info->file=(FILE *) NULL; |
| 1205 | } |
| 1206 | if (log_info->file == (FILE *) NULL) |
| 1207 | { |
| 1208 | char |
| 1209 | *filename; |
| 1210 | |
| 1211 | filename=TranslateFilename(log_info); |
| 1212 | if (filename == (char *) NULL) |
| 1213 | { |
| 1214 | (void) ContinueTimer((TimerInfo *) &log_info->timer); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1215 | UnlockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1216 | return(MagickFalse); |
| 1217 | } |
| 1218 | log_info->append=IsPathAccessible(filename); |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 1219 | log_info->file=fopen_utf8(filename,"ab"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1220 | filename=(char *) RelinquishMagickMemory(filename); |
| 1221 | if (log_info->file == (FILE *) NULL) |
| 1222 | { |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1223 | UnlockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1224 | return(MagickFalse); |
| 1225 | } |
| 1226 | log_info->generation++; |
| 1227 | if (log_info->append == MagickFalse) |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 1228 | (void) FormatLocaleFile(log_info->file,"<?xml version=\"1.0\" " |
| 1229 | "encoding=\"UTF-8\" standalone=\"yes\"?>\n"); |
| 1230 | (void) FormatLocaleFile(log_info->file,"<log>\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1231 | } |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 1232 | (void) FormatLocaleFile(log_info->file," <event>%s</event>\n",text); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1233 | (void) fflush(log_info->file); |
| 1234 | } |
| 1235 | if ((log_info->handler_mask & StdoutHandler) != 0) |
| 1236 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1237 | (void) FormatLocaleFile(stdout,"%s\n",text); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1238 | (void) fflush(stdout); |
| 1239 | } |
| 1240 | if ((log_info->handler_mask & StderrHandler) != 0) |
| 1241 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1242 | (void) FormatLocaleFile(stderr,"%s\n",text); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1243 | (void) fflush(stderr); |
| 1244 | } |
| 1245 | text=(char *) RelinquishMagickMemory(text); |
| 1246 | (void) ContinueTimer((TimerInfo *) &log_info->timer); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1247 | UnlockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1248 | return(MagickTrue); |
| 1249 | } |
| 1250 | |
| 1251 | MagickBooleanType LogMagickEvent(const LogEventType type,const char *module, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1252 | const char *function,const size_t line,const char *format,...) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1253 | { |
| 1254 | va_list |
| 1255 | operands; |
| 1256 | |
| 1257 | MagickBooleanType |
| 1258 | status; |
| 1259 | |
| 1260 | va_start(operands,format); |
| 1261 | status=LogMagickEventList(type,module,function,line,format,operands); |
| 1262 | va_end(operands); |
| 1263 | return(status); |
| 1264 | } |
| 1265 | |
| 1266 | /* |
| 1267 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1268 | % % |
| 1269 | % % |
| 1270 | % % |
| 1271 | + L o a d L o g L i s t % |
| 1272 | % % |
| 1273 | % % |
| 1274 | % % |
| 1275 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1276 | % |
| 1277 | % LoadLogList() loads the log configuration file which provides a |
| 1278 | % mapping between log attributes and log name. |
| 1279 | % |
| 1280 | % The format of the LoadLogList method is: |
| 1281 | % |
| 1282 | % MagickBooleanType LoadLogList(const char *xml,const char *filename, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1283 | % const size_t depth,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1284 | % |
| 1285 | % A description of each parameter follows: |
| 1286 | % |
| 1287 | % o xml: The log list in XML format. |
| 1288 | % |
| 1289 | % o filename: The log list filename. |
| 1290 | % |
| 1291 | % o depth: depth of <include /> statements. |
| 1292 | % |
| 1293 | % o exception: return any errors or warnings in this structure. |
| 1294 | % |
| 1295 | */ |
| 1296 | static MagickBooleanType LoadLogList(const char *xml,const char *filename, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1297 | const size_t depth,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1298 | { |
| 1299 | char |
| 1300 | keyword[MaxTextExtent], |
| 1301 | *token; |
| 1302 | |
| 1303 | const char |
| 1304 | *q; |
| 1305 | |
| 1306 | LogInfo |
| 1307 | *log_info = (LogInfo *) NULL; |
| 1308 | |
| 1309 | MagickStatusType |
| 1310 | status; |
| 1311 | |
| 1312 | /* |
| 1313 | Load the log map file. |
| 1314 | */ |
| 1315 | if (xml == (const char *) NULL) |
| 1316 | return(MagickFalse); |
| 1317 | if (log_list == (LinkedListInfo *) NULL) |
| 1318 | { |
| 1319 | log_list=NewLinkedList(0); |
| 1320 | if (log_list == (LinkedListInfo *) NULL) |
| 1321 | { |
| 1322 | ThrowFileException(exception,ResourceLimitError, |
| 1323 | "MemoryAllocationFailed",filename); |
| 1324 | return(MagickFalse); |
| 1325 | } |
| 1326 | } |
| 1327 | status=MagickTrue; |
| 1328 | token=AcquireString((const char *) xml); |
| 1329 | for (q=(const char *) xml; *q != '\0'; ) |
| 1330 | { |
| 1331 | /* |
| 1332 | Interpret XML. |
| 1333 | */ |
| 1334 | GetMagickToken(q,&q,token); |
| 1335 | if (*token == '\0') |
| 1336 | break; |
| 1337 | (void) CopyMagickString(keyword,token,MaxTextExtent); |
| 1338 | if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) |
| 1339 | { |
| 1340 | /* |
| 1341 | Doctype element. |
| 1342 | */ |
| 1343 | while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) |
| 1344 | GetMagickToken(q,&q,token); |
| 1345 | continue; |
| 1346 | } |
| 1347 | if (LocaleNCompare(keyword,"<!--",4) == 0) |
| 1348 | { |
| 1349 | /* |
| 1350 | Comment element. |
| 1351 | */ |
| 1352 | while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) |
| 1353 | GetMagickToken(q,&q,token); |
| 1354 | continue; |
| 1355 | } |
| 1356 | if (LocaleCompare(keyword,"<include") == 0) |
| 1357 | { |
| 1358 | /* |
| 1359 | Include element. |
| 1360 | */ |
| 1361 | while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) |
| 1362 | { |
| 1363 | (void) CopyMagickString(keyword,token,MaxTextExtent); |
| 1364 | GetMagickToken(q,&q,token); |
| 1365 | if (*token != '=') |
| 1366 | continue; |
| 1367 | GetMagickToken(q,&q,token); |
| 1368 | if (LocaleCompare(keyword,"file") == 0) |
| 1369 | { |
| 1370 | if (depth > 200) |
| 1371 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1372 | ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1373 | else |
| 1374 | { |
| 1375 | char |
| 1376 | path[MaxTextExtent], |
| 1377 | *xml; |
| 1378 | |
| 1379 | GetPathComponent(filename,HeadPath,path); |
| 1380 | if (*path != '\0') |
| 1381 | (void) ConcatenateMagickString(path,DirectorySeparator, |
| 1382 | MaxTextExtent); |
| 1383 | if (*token == *DirectorySeparator) |
| 1384 | (void) CopyMagickString(path,token,MaxTextExtent); |
| 1385 | else |
| 1386 | (void) ConcatenateMagickString(path,token,MaxTextExtent); |
| 1387 | xml=FileToString(path,~0,exception); |
| 1388 | if (xml != (char *) NULL) |
| 1389 | { |
| 1390 | status|=LoadLogList(xml,path,depth+1,exception); |
| 1391 | xml=DestroyString(xml); |
| 1392 | } |
| 1393 | } |
| 1394 | } |
| 1395 | } |
| 1396 | continue; |
| 1397 | } |
| 1398 | if (LocaleCompare(keyword,"<logmap>") == 0) |
| 1399 | { |
| 1400 | /* |
| 1401 | Allocate memory for the log list. |
| 1402 | */ |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 1403 | log_info=(LogInfo *) AcquireMagickMemory(sizeof(*log_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1404 | if (log_info == (LogInfo *) NULL) |
| 1405 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 1406 | (void) ResetMagickMemory(log_info,0,sizeof(*log_info)); |
| 1407 | log_info->path=ConstantString(filename); |
| 1408 | GetTimerInfo((TimerInfo *) &log_info->timer); |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 1409 | log_info->exempt=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1410 | log_info->signature=MagickSignature; |
| 1411 | continue; |
| 1412 | } |
| 1413 | if (log_info == (LogInfo *) NULL) |
| 1414 | continue; |
| 1415 | if (LocaleCompare(keyword,"</logmap>") == 0) |
| 1416 | { |
| 1417 | status=AppendValueToLinkedList(log_list,log_info); |
| 1418 | if (status == MagickFalse) |
| 1419 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1420 | ResourceLimitError,"MemoryAllocationFailed","`%s'",filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1421 | log_info=(LogInfo *) NULL; |
| 1422 | } |
| 1423 | GetMagickToken(q,(const char **) NULL,token); |
| 1424 | if (*token != '=') |
| 1425 | continue; |
| 1426 | GetMagickToken(q,&q,token); |
| 1427 | GetMagickToken(q,&q,token); |
| 1428 | switch (*keyword) |
| 1429 | { |
| 1430 | case 'E': |
| 1431 | case 'e': |
| 1432 | { |
| 1433 | if (LocaleCompare((char *) keyword,"events") == 0) |
| 1434 | { |
| 1435 | log_info->event_mask=(LogEventType) (log_info->event_mask | |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1436 | ParseCommandOption(MagickLogEventOptions,MagickTrue,token)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1437 | break; |
| 1438 | } |
| 1439 | break; |
| 1440 | } |
| 1441 | case 'F': |
| 1442 | case 'f': |
| 1443 | { |
| 1444 | if (LocaleCompare((char *) keyword,"filename") == 0) |
| 1445 | { |
| 1446 | if (log_info->filename != (char *) NULL) |
| 1447 | log_info->filename=(char *) |
| 1448 | RelinquishMagickMemory(log_info->filename); |
| 1449 | log_info->filename=ConstantString(token); |
| 1450 | break; |
| 1451 | } |
| 1452 | if (LocaleCompare((char *) keyword,"format") == 0) |
| 1453 | { |
| 1454 | if (log_info->format != (char *) NULL) |
| 1455 | log_info->format=(char *) |
| 1456 | RelinquishMagickMemory(log_info->format); |
| 1457 | log_info->format=ConstantString(token); |
| 1458 | break; |
| 1459 | } |
| 1460 | break; |
| 1461 | } |
| 1462 | case 'G': |
| 1463 | case 'g': |
| 1464 | { |
| 1465 | if (LocaleCompare((char *) keyword,"generations") == 0) |
| 1466 | { |
| 1467 | if (LocaleCompare(token,"unlimited") == 0) |
| 1468 | { |
| 1469 | log_info->generations=(~0UL); |
| 1470 | break; |
| 1471 | } |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 1472 | log_info->generations=StringToUnsignedLong(token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1473 | break; |
| 1474 | } |
| 1475 | break; |
| 1476 | } |
| 1477 | case 'L': |
| 1478 | case 'l': |
| 1479 | { |
| 1480 | if (LocaleCompare((char *) keyword,"limit") == 0) |
| 1481 | { |
| 1482 | if (LocaleCompare(token,"unlimited") == 0) |
| 1483 | { |
| 1484 | log_info->limit=(~0UL); |
| 1485 | break; |
| 1486 | } |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 1487 | log_info->limit=StringToUnsignedLong(token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1488 | break; |
| 1489 | } |
| 1490 | break; |
| 1491 | } |
| 1492 | case 'O': |
| 1493 | case 'o': |
| 1494 | { |
| 1495 | if (LocaleCompare((char *) keyword,"output") == 0) |
| 1496 | { |
| 1497 | log_info->handler_mask=(LogHandlerType) |
| 1498 | (log_info->handler_mask | ParseLogHandlers(token)); |
| 1499 | break; |
| 1500 | } |
| 1501 | break; |
| 1502 | } |
| 1503 | default: |
| 1504 | break; |
| 1505 | } |
| 1506 | } |
| 1507 | token=DestroyString(token); |
| 1508 | if (log_list == (LinkedListInfo *) NULL) |
| 1509 | return(MagickFalse); |
| 1510 | return(status != 0 ? MagickTrue : MagickFalse); |
| 1511 | } |
| 1512 | |
| 1513 | /* |
| 1514 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1515 | % % |
| 1516 | % % |
| 1517 | % % |
| 1518 | % L o a d L o g L i s t s % |
| 1519 | % % |
| 1520 | % % |
| 1521 | % % |
| 1522 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1523 | % |
| 1524 | % LoadLogLists() loads one or more log configuration file which provides a |
| 1525 | % mapping between log attributes and log name. |
| 1526 | % |
| 1527 | % The format of the LoadLogLists method is: |
| 1528 | % |
| 1529 | % MagickBooleanType LoadLogLists(const char *filename, |
| 1530 | % ExceptionInfo *exception) |
| 1531 | % |
| 1532 | % A description of each parameter follows: |
| 1533 | % |
| 1534 | % o filename: the log configuration filename. |
| 1535 | % |
| 1536 | % o exception: return any errors or warnings in this structure. |
| 1537 | % |
| 1538 | */ |
| 1539 | static MagickBooleanType LoadLogLists(const char *filename, |
| 1540 | ExceptionInfo *exception) |
| 1541 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1542 | const StringInfo |
| 1543 | *option; |
| 1544 | |
| 1545 | LinkedListInfo |
| 1546 | *options; |
| 1547 | |
| 1548 | MagickStatusType |
| 1549 | status; |
| 1550 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1551 | register ssize_t |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 1552 | i; |
| 1553 | |
| 1554 | /* |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 1555 | Load external log map. |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 1556 | */ |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 1557 | if (log_list == (LinkedListInfo *) NULL) |
| 1558 | { |
| 1559 | log_list=NewLinkedList(0); |
| 1560 | if (log_list == (LinkedListInfo *) NULL) |
| 1561 | { |
| 1562 | ThrowFileException(exception,ResourceLimitError, |
| 1563 | "MemoryAllocationFailed",filename); |
| 1564 | return(MagickFalse); |
| 1565 | } |
| 1566 | } |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 1567 | status=MagickTrue; |
| 1568 | options=GetConfigureOptions(filename,exception); |
| 1569 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 1570 | while (option != (const StringInfo *) NULL) |
| 1571 | { |
| 1572 | status|=LoadLogList((const char *) GetStringInfoDatum(option), |
| 1573 | GetStringInfoPath(option),0,exception); |
| 1574 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 1575 | } |
| 1576 | options=DestroyConfigureOptions(options); |
| 1577 | /* |
| 1578 | Load built-in log map. |
| 1579 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1580 | for (i=0; i < (ssize_t) (sizeof(LogMap)/sizeof(*LogMap)); i++) |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 1581 | { |
| 1582 | LogInfo |
| 1583 | *log_info; |
| 1584 | |
| 1585 | register const LogMapInfo |
| 1586 | *p; |
| 1587 | |
| 1588 | p=LogMap+i; |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 1589 | log_info=(LogInfo *) AcquireMagickMemory(sizeof(*log_info)); |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 1590 | if (log_info == (LogInfo *) NULL) |
| 1591 | { |
| 1592 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1593 | ResourceLimitError,"MemoryAllocationFailed","`%s'",log_info->name); |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 1594 | continue; |
| 1595 | } |
| 1596 | (void) ResetMagickMemory(log_info,0,sizeof(*log_info)); |
| 1597 | log_info->path=(char *) "[built-in]"; |
| 1598 | GetTimerInfo((TimerInfo *) &log_info->timer); |
| 1599 | log_info->event_mask=p->event_mask; |
| 1600 | log_info->handler_mask=p->handler_mask; |
cristy | 5aaf574 | 2009-11-22 00:56:44 +0000 | [diff] [blame] | 1601 | log_info->filename=ConstantString(p->filename); |
| 1602 | log_info->format=ConstantString(p->format); |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 1603 | log_info->exempt=MagickTrue; |
| 1604 | log_info->signature=MagickSignature; |
cristy | 398fd02 | 2013-06-26 23:08:33 +0000 | [diff] [blame] | 1605 | status|=AppendValueToLinkedList(log_list,log_info); |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 1606 | if (status == MagickFalse) |
| 1607 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1608 | ResourceLimitError,"MemoryAllocationFailed","`%s'",log_info->name); |
cristy | 8534029 | 2009-10-21 19:32:19 +0000 | [diff] [blame] | 1609 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1610 | return(status != 0 ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | /* |
| 1614 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1615 | % % |
| 1616 | % % |
| 1617 | % % |
| 1618 | + P a r s e L o g H a n d l e r s % |
| 1619 | % % |
| 1620 | % % |
| 1621 | % % |
| 1622 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1623 | % |
| 1624 | % ParseLogHandlers() parses a string defining which handlers takes a log |
| 1625 | % message and exports them. |
| 1626 | % |
| 1627 | % The format of the ParseLogHandlers method is: |
| 1628 | % |
| 1629 | % LogHandlerType ParseLogHandlers(const char *handlers) |
| 1630 | % |
| 1631 | % A description of each parameter follows: |
| 1632 | % |
| 1633 | % o handlers: one or more handlers separated by commas. |
| 1634 | % |
| 1635 | */ |
| 1636 | static LogHandlerType ParseLogHandlers(const char *handlers) |
| 1637 | { |
| 1638 | LogHandlerType |
| 1639 | handler_mask; |
| 1640 | |
| 1641 | register const char |
| 1642 | *p; |
| 1643 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1644 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1645 | i; |
| 1646 | |
| 1647 | size_t |
| 1648 | length; |
| 1649 | |
| 1650 | handler_mask=NoHandler; |
| 1651 | for (p=handlers; p != (char *) NULL; p=strchr(p,',')) |
| 1652 | { |
| 1653 | while ((*p != '\0') && ((isspace((int) ((unsigned char) *p)) != 0) || |
| 1654 | (*p == ','))) |
| 1655 | p++; |
| 1656 | for (i=0; LogHandlers[i].name != (char *) NULL; i++) |
| 1657 | { |
| 1658 | length=strlen(LogHandlers[i].name); |
| 1659 | if (LocaleNCompare(p,LogHandlers[i].name,length) == 0) |
| 1660 | { |
| 1661 | handler_mask=(LogHandlerType) (handler_mask | LogHandlers[i].handler); |
| 1662 | break; |
| 1663 | } |
| 1664 | } |
| 1665 | if (LogHandlers[i].name == (char *) NULL) |
| 1666 | return(UndefinedHandler); |
| 1667 | } |
| 1668 | return(handler_mask); |
| 1669 | } |
| 1670 | |
| 1671 | /* |
| 1672 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1673 | % % |
| 1674 | % % |
| 1675 | % % |
| 1676 | % S e t L o g E v e n t M a s k % |
| 1677 | % % |
| 1678 | % % |
| 1679 | % % |
| 1680 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1681 | % |
| 1682 | % SetLogEventMask() accepts a list that determines which events to log. All |
| 1683 | % other events are ignored. By default, no debug is enabled. This method |
| 1684 | % returns the previous log event mask. |
| 1685 | % |
| 1686 | % The format of the SetLogEventMask method is: |
| 1687 | % |
| 1688 | % LogEventType SetLogEventMask(const char *events) |
| 1689 | % |
| 1690 | % A description of each parameter follows: |
| 1691 | % |
| 1692 | % o events: log these events. |
| 1693 | % |
| 1694 | */ |
| 1695 | MagickExport LogEventType SetLogEventMask(const char *events) |
| 1696 | { |
| 1697 | ExceptionInfo |
| 1698 | *exception; |
| 1699 | |
| 1700 | LogInfo |
| 1701 | *log_info; |
| 1702 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1703 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1704 | option; |
| 1705 | |
| 1706 | exception=AcquireExceptionInfo(); |
| 1707 | log_info=(LogInfo *) GetLogInfo("*",exception); |
| 1708 | exception=DestroyExceptionInfo(exception); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1709 | option=ParseCommandOption(MagickLogEventOptions,MagickTrue,events); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1710 | LockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1711 | log_info=(LogInfo *) GetValueFromLinkedList(log_list,0); |
| 1712 | log_info->event_mask=(LogEventType) option; |
| 1713 | if (option == -1) |
| 1714 | log_info->event_mask=UndefinedEvents; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1715 | UnlockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1716 | return(log_info->event_mask); |
| 1717 | } |
| 1718 | |
| 1719 | /* |
| 1720 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1721 | % % |
| 1722 | % % |
| 1723 | % % |
| 1724 | % S e t L o g F o r m a t % |
| 1725 | % % |
| 1726 | % % |
| 1727 | % % |
| 1728 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1729 | % |
| 1730 | % SetLogFormat() sets the format for the "human readable" log record. |
| 1731 | % |
| 1732 | % The format of the LogMagickFormat method is: |
| 1733 | % |
| 1734 | % SetLogFormat(const char *format) |
| 1735 | % |
| 1736 | % A description of each parameter follows: |
| 1737 | % |
| 1738 | % o format: the log record format. |
| 1739 | % |
| 1740 | */ |
| 1741 | MagickExport void SetLogFormat(const char *format) |
| 1742 | { |
| 1743 | LogInfo |
| 1744 | *log_info; |
| 1745 | |
| 1746 | ExceptionInfo |
| 1747 | *exception; |
| 1748 | |
| 1749 | exception=AcquireExceptionInfo(); |
| 1750 | log_info=(LogInfo *) GetLogInfo("*",exception); |
| 1751 | exception=DestroyExceptionInfo(exception); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1752 | LockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1753 | if (log_info->format != (char *) NULL) |
| 1754 | log_info->format=DestroyString(log_info->format); |
| 1755 | log_info->format=ConstantString(format); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1756 | UnlockSemaphoreInfo(log_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | /* |
| 1760 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1761 | % % |
| 1762 | % % |
| 1763 | % % |
| 1764 | % S e t L o g N a m e % |
| 1765 | % % |
| 1766 | % % |
| 1767 | % % |
| 1768 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1769 | % |
| 1770 | % SetLogName() sets the log name and returns it. |
| 1771 | % |
| 1772 | % The format of the SetLogName method is: |
| 1773 | % |
| 1774 | % const char *SetLogName(const char *name) |
| 1775 | % |
| 1776 | % A description of each parameter follows: |
| 1777 | % |
| 1778 | % o log_name: SetLogName() returns the current client name. |
| 1779 | % |
| 1780 | % o name: Specifies the new client name. |
| 1781 | % |
| 1782 | */ |
| 1783 | MagickExport const char *SetLogName(const char *name) |
| 1784 | { |
| 1785 | if ((name != (char *) NULL) && (*name != '\0')) |
| 1786 | (void) CopyMagickString(log_name,name,MaxTextExtent); |
| 1787 | return(log_name); |
| 1788 | } |