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