Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Log_Msg.h
blobebbac05573a039b9282dbbb1cd1b2e5f6692f5be
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Log_Msg.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 */
9 //=============================================================================
11 #ifndef ACE_LOG_MSG_H
12 #define ACE_LOG_MSG_H
13 #include /**/ "ace/pre.h"
15 // This stuff must come first to avoid problems with circular
16 // headers...
17 // ... but ACE_NDEBUG and ACE_NLOGGING can come from the config.h file, so
18 // pull that one early.
19 #include /**/ "ace/config-all.h"
20 #include /**/ "ace/ACE_export.h"
21 #include "ace/Global_Macros.h"
22 #include "ace/Default_Constants.h"
23 #include "ace/Log_Priority.h"
24 #include "ace/os_include/os_limits.h"
25 #include "ace/Synch_Traits.h"
26 #include "ace/Basic_Types.h"
28 // The ACE_ASSERT macro used to be defined here, include ace/Assert.h
29 // for backwards compatibility.
30 #include "ace/Assert.h"
32 #if defined (ACE_NLOGGING)
33 #if !defined (ACE_HEX_DUMP)
34 # define ACE_HEX_DUMP(X) do {} while (0)
35 #endif
36 #if !defined (ACE_RETURN)
37 # define ACE_RETURN(Y) do { return (Y); } while (0)
38 #endif
39 #if !defined (ACE_ERROR_RETURN)
40 # define ACE_ERROR_RETURN(X, Y) return (Y)
41 #endif
42 #if !defined (ACE_ERROR_BREAK)
43 # define ACE_ERROR_BREAK(X) { break; }
44 #endif
45 #if !defined (ACE_ERROR)
46 # define ACE_ERROR(X) do {} while (0)
47 #endif
48 #if !defined (ACE_DEBUG)
49 # define ACE_DEBUG(X) do {} while (0)
50 #endif
51 #if !defined (ACE_ERROR_INIT)
52 # define ACE_ERROR_INIT(VALUE, FLAGS)
53 #endif
54 #else
55 #if !defined (ACE_HEX_DUMP)
56 #define ACE_HEX_DUMP(X) \
57 do { \
58 int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
59 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
60 ace___->conditional_set (__FILE__, __LINE__, 0, __ace_error); \
61 ace___->log_hexdump X; \
62 } while (0)
63 #endif
64 #if !defined (ACE_RETURN)
65 #define ACE_RETURN(Y) \
66 do { \
67 int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
68 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
69 ace___->set (__FILE__, __LINE__, Y, __ace_error, ace___->restart (), \
70 ace___->msg_ostream (), ace___->msg_callback ()); \
71 return Y; \
72 } while (0)
73 #endif
74 #if !defined (ACE_ERROR_RETURN)
75 # ifdef ACE_LACKS_VA_FUNCTIONS
76 # define ACE_ERROR_RETURN(X, Y) \
77 do { \
78 int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
79 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
80 ace___->conditional_set (__FILE__, __LINE__, Y, __ace_error); \
81 ace___->log (X); \
82 return Y; \
83 } while (0)
84 # else /* ACE_LACKS_VA_FUNCTIONS */
85 # define ACE_ERROR_RETURN(X, Y) \
86 do { \
87 int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
88 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
89 ace___->conditional_set (__FILE__, __LINE__, Y, __ace_error); \
90 ace___->log X; \
91 return Y; \
92 } while (0)
93 # endif /* ACE_LACKS_VA_FUNCTIONS */
94 #endif
95 #if !defined (ACE_ERROR)
96 # ifdef ACE_LACKS_VA_FUNCTIONS
97 # define ACE_ERROR(X) \
98 do { \
99 int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
100 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
101 ace___->conditional_set (__FILE__, __LINE__, -1, __ace_error); \
102 ace___->log (X); \
103 } while (0)
104 # else /* ACE_LACKS_VA_FUNCTIONS */
105 # define ACE_ERROR(X) \
106 do { \
107 int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
108 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
109 ace___->conditional_set (__FILE__, __LINE__, -1, __ace_error); \
110 ace___->log X; \
111 } while (0)
112 # endif /* ACE_LACKS_VA_FUNCTIONS */
113 #endif
114 #if !defined (ACE_DEBUG)
115 # ifdef ACE_LACKS_VA_FUNCTIONS
116 # define ACE_DEBUG(X) \
117 do { \
118 int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
119 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
120 ace___->conditional_set (__FILE__, __LINE__, 0, __ace_error); \
121 ace___->log (X); \
122 } while (0)
123 # else /* ACE_LACKS_VA_FUNCTIONS */
124 # define ACE_DEBUG(X) \
125 do { \
126 int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
127 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
128 ace___->conditional_set (__FILE__, __LINE__, 0, __ace_error); \
129 ace___->log X; \
130 } while (0)
131 # endif /* ACE_LACKS_VA_FUNCTIONS */
132 #endif
133 #if !defined (ACE_ERROR_INIT)
134 #define ACE_ERROR_INIT(VALUE, FLAGS) \
135 do { \
136 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \
137 ace___->set_flags (FLAGS); \
138 ace___->op_status (VALUE); \
139 } while (0)
140 #endif
141 #if !defined (ACE_ERROR_BREAK)
142 #define ACE_ERROR_BREAK(X) { ACE_ERROR (X); break; }
143 #endif
144 #endif /* ACE_NLOGGING */
146 #include "ace/OS_Log_Msg_Attributes.h"
148 #if !defined (ACE_LACKS_PRAGMA_ONCE)
149 # pragma once
150 #endif /* ACE_LACKS_PRAGMA_ONCE */
152 // These workarounds are necessary for nasty libraries or platforms
153 // that #define STDERR or THREAD (e.g. LynxOS). We simply #undef
154 // these macros as there is no way to save the macro definition using
155 // the pre-processor. See Bugzilla Bug #299 for more info.
156 #if defined (STDERR)
157 # undef STDERR
158 #endif /* STDERR */
160 #if defined (THREAD)
161 # undef THREAD
162 #endif /* THREAD */
164 #ifndef ACE_DEFAULT_LOG_FLAGS
165 # ifdef ACE_ANDROID
166 # define ACE_DEFAULT_LOG_FLAGS ACE_Log_Msg::STDERR | ACE_Log_Msg::SYSLOG
167 # else
168 # define ACE_DEFAULT_LOG_FLAGS ACE_Log_Msg::STDERR
169 # endif
170 #endif
172 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
174 class ACE_Log_Msg_Callback;
175 class ACE_Log_Msg_Backend;
177 // ****************************************************************
179 #define ACE_LOG_MSG ACE_Log_Msg::instance ()
181 // Forward declaration
182 class ACE_Thread_Descriptor;
183 class ACE_Log_Record;
184 class ACE_Log_Category_TSS;
185 template<typename M, typename T> class ACE_Atomic_Op;
186 class ACE_Log_Formatter;
189 * @class ACE_Log_Msg
191 * @brief Provides a variable length argument message logging
192 * abstraction.
194 * This class is very flexible since it allows formatted error
195 * messages to be printed in a thread-safe manner to various
196 * locations, such as stderr, cerr, a distributed logger, etc. The
197 * current message is also kept in a thread-specific storage location
198 * (threads spawned using ACE_Thread_Manager automatically get an
199 * ACE_Log_Msg object that inherits the spawning thread's settings),
200 * which can be used to communicate errors between framework methods
201 * and callers. A message is logged by the log() method, only if the
202 * message priority is currently enabled. Moreover, only the current
203 * log message is stored here -- it will be overwritten by the
204 * subsequent call to log().
206 * The ACE_Log_Msg class uses two priority masks to control its
207 * logging behavior. The @c priority_mask_ object attribute is
208 * thread- specific and specifies the priority levels logged by the
209 * thread. The @c process_priority_mask_ class attribute is not
210 * thread-specific and specifies the priority levels that will be
211 * logged by all threads in the process. By default, all levels are
212 * disabled for @c priority_mask_ and all levels are enabled for @c
213 * process_priority_mask_ (i.e. the process-wide mask controls the
214 * settings, and each instance can expand on it if desired). Both
215 * priority masks can be modified using the priority_mask() method of
216 * this class.
218 class ACE_Export ACE_Log_Msg
220 public:
221 // Logger Flags.
222 enum
224 /// Write messages to stderr.
225 STDERR = 1,
226 /// Write messages to the local client logger daemon.
227 LOGGER = 2,
228 /// Write messages to the ostream * stored in thread-specific
229 /// storage.
230 OSTREAM = 4,
231 /// Write messages to the callback object.
232 MSG_CALLBACK = 8,
233 /// Display messages in a verbose manner.
234 VERBOSE = 16,
235 /// Display messages in a less verbose manner (i.e., only print
236 /// information that can change between calls).
237 VERBOSE_LITE = 32,
238 /// Do not print messages at all (just leave in thread-specific
239 /// storage for later inspection).
240 SILENT = 64,
241 /// Write messages to the system's event log.
242 SYSLOG = 128,
243 /// Write messages to the user provided backend
244 CUSTOM = 256
247 /// Returns a pointer to the Singleton.
248 static ACE_Log_Msg *instance ();
250 /// Returns last error.
251 static int last_error_adapter ();
253 /// Returns non-null if an ACE_Log_Msg exists for the calling thread.
254 static int exists ();
256 /// Returns the current program name used for logging.
257 static const ACE_TCHAR * program_name ();
259 /// Clears the flag from the default priority mask used to
260 /// initialize ACE_Log_Msg instances.
261 static void disable_debug_messages (ACE_Log_Priority priority = LM_DEBUG);
263 /// Sets the flag in the default priority mask used to initialize
264 /// ACE_Log_Msg instances.
265 static void enable_debug_messages (ACE_Log_Priority priority = LM_DEBUG);
267 /// Initialize logger.
268 ACE_Log_Msg ();
270 /// cleanup logger.
271 ~ACE_Log_Msg ();
273 /// Initialize the ACE logging facility.
275 * Initialize the ACE logging facility. Supplies the program name
276 * that is available to each logging message call. Default arguments
277 * set up logging to STDERR only.
279 * @param prog_name The name of the calling program.
280 * @param options_flags A bitwise-or of options flags used to set the
281 * initial behavior and logging sink(s). (see the
282 * enum above for the valid values).
283 * @param logger_key The name of ACE_FIFO rendezvous point where the
284 * local client logger daemon is listening for logging
285 * messages if the LOGGER bit is set in the @a flags
286 * argument. If the SYSLOG bit is set in @a flags,
287 * @a logger_key is the source/program name specified
288 * in the syslog facility (UNIX/Linux) or the Windows
289 * event log (Windows). In the SYSLOG case, if
290 * @a logger_key is 0, @a prog_name is used.
292 int open (const ACE_TCHAR *prog_name,
293 u_long options_flags = ACE_DEFAULT_LOG_FLAGS,
294 const ACE_TCHAR *logger_key = 0);
296 // = Set/get the options flags.
299 * Enable the bits in the logger's options flags.
301 void set_flags (u_long f);
304 * Disable the bits in the logger's options flags.
306 void clr_flags (u_long f);
309 * Return the bits in the logger's options flags.
311 u_long flags ();
313 /** @name Allow apps to acquire and release internal synchronization
314 * lock
316 * This lock is used internally by the ACE_Log_Msg
317 * implementation. By exporting the lock, applications can hold the
318 * lock atomically over a number of calls to ACE_Log_Msg.
320 //@{
321 /// Acquire the internal lock.
322 int acquire ();
324 /// Release the internal lock.
325 int release ();
326 //@}
328 /// Call after doing a @c fork() to resynchronize the process id and
329 /// @c program_name_ variables.
330 void sync (const ACE_TCHAR *program_name);
332 // = Set/get methods. Note that these are non-static and thus will
333 // be thread-specific.
335 /// Set the result of the operation status (by convention, -1 means
336 /// error).
337 void op_status (int status);
339 /// Get the result of the operation status (by convention, -1 means
340 /// error).
341 int op_status () const;
343 /// Set the value of the errnum (by convention this corresponds to
344 /// errno).
345 void errnum (int);
347 /// Get the value of the errnum (by convention this corresponds to
348 /// errno).
349 int errnum () const;
351 /// Set the line number where an error occurred.
352 void linenum (int);
354 /// Get the line number where an error occurred.
355 int linenum () const;
357 /// Set the file name where an error occurred.
358 void file (const char *);
360 /// Get the file name where an error occurred.
361 const char *file ();
363 /// Set the message that describes what type of error occurred.
364 void msg (const ACE_TCHAR *);
366 /// Get the message that describes what type of error occurred.
367 const ACE_TCHAR *msg ();
369 /// Set the field that indicates whether interrupted calls should be
370 /// restarted.
371 void restart (bool r);
373 /// Get the field that indicates whether interrupted calls should be
374 /// restarted.
375 bool restart () const;
377 /// Update the ostream without overwriting the delete_ostream_ flag.
378 void msg_ostream (ACE_OSTREAM_TYPE *);
381 * delete_stream == true, forces Log_Msg.h to delete the stream in
382 * its own ~dtor (assumes control of the stream)
383 * use only with proper ostream (eg: fstream), not (cout, cerr)
385 void msg_ostream (ACE_OSTREAM_TYPE *, bool delete_ostream);
387 /// Get the ostream that is used to print error messages.
388 ACE_OSTREAM_TYPE *msg_ostream () const;
391 * Set a new callback object and return the existing callback to
392 * allow "chaining". Note that ACE_Log_Msg_Callback objects are not
393 * inherited when spawning a new thread, so you'll need to reset
394 * them in each thread.
396 ACE_Log_Msg_Callback *msg_callback (ACE_Log_Msg_Callback *c);
397 ACE_Log_Msg_Callback *msg_callback () const;
400 * Set a new backend object and return the existing backend to
401 * allow "chaining". Note that as opposed to ACE_Log_Msg_Callback,
402 * ACE_Log_Msg_Backend is a per-process entity.
404 * @note Be aware that because of the current architecture there is
405 * no guarantee that open (), reset () and close () will be called
406 * on a backend object.
408 static ACE_Log_Msg_Backend *msg_backend (ACE_Log_Msg_Backend *b);
409 static ACE_Log_Msg_Backend *msg_backend ();
411 /// Nesting depth increment.
412 int inc ();
414 /// Nesting depth decrement.
415 int dec ();
417 /// Get trace depth.
418 int trace_depth () const;
420 /// Set trace depth.
421 void trace_depth (int);
423 /// Get trace active status.
424 bool trace_active () const;
426 /// Set trace active status.
427 void trace_active (bool value);
429 /// Get the TSS thread descriptor.
430 ACE_Thread_Descriptor *thr_desc () const;
433 * Set the TSS thread descriptor. This method will call
434 * td->acquire_release to block execution until this call
435 * return.
437 void thr_desc (ACE_Thread_Descriptor *td);
439 /// Stop tracing status on a per-thread basis...
440 void stop_tracing ();
442 /// Start tracing status on a per-thread basis...
443 void start_tracing ();
445 /// Query tracing status on a per-thread basis...
446 bool tracing_enabled () const;
448 typedef enum
450 PROCESS = 0,
451 THREAD = 1
452 } MASK_TYPE;
454 // = Get/set the priority mask.
455 /// Get the current ACE_Log_Priority mask.
456 u_long priority_mask (MASK_TYPE = THREAD);
458 /// Set the ACE_Log_Priority mask, returns original mask.
459 u_long priority_mask (u_long, MASK_TYPE = THREAD);
461 /// Return true if the requested priority is enabled.
462 int log_priority_enabled (ACE_Log_Priority log_priority);
464 #ifndef ACE_LACKS_VA_FUNCTIONS
465 /// Return true if the requested priority is enabled.
466 int log_priority_enabled (ACE_Log_Priority log_priority,
467 const char *,
468 ...);
469 #endif
471 #if defined (ACE_USES_WCHAR) && !defined ACE_LACKS_VA_FUNCTIONS
472 // We are not using ACE_TCHAR for this since ACE_HEX_DUMP
473 // doesn't take in a ACE_TCHAR. log_hexdump takes in a char
474 // string, so this must be able to take in a char string even
475 // when using ACE_USES_WCHAR.
476 /// Return true if the requested priority is enabled.
477 int log_priority_enabled (ACE_Log_Priority log_priority,
478 const wchar_t *,
479 ...);
480 #endif /* ACE_USES_WCHAR */
482 /// Optimize reading of the pid (avoids a system call if the value is
483 /// cached...).
484 pid_t getpid () const;
486 /// Get the name of the local host.
487 const ACE_TCHAR *local_host () const;
489 /// Set the name of the local host.
490 void local_host (const ACE_TCHAR *);
493 * Set the line number, file name, operational status, error number,
494 * restart flag, ostream, and the callback object. This combines
495 * all the other set methods into a single method.
497 void set (const char *file,
498 int line,
499 int op_status = -1,
500 int errnum = 0,
501 bool restart = true,
502 ACE_OSTREAM_TYPE *os = 0,
503 ACE_Log_Msg_Callback *c = 0);
505 /// These values are only actually set if the requested priority is
506 /// enabled.
507 void conditional_set (const char *file,
508 int line,
509 int op_status,
510 int errnum);
512 #ifndef ACE_LACKS_VA_FUNCTIONS
514 * Format a message to the thread-safe ACE logging mechanism. Valid
515 * options (prefixed by '%', as in printf format strings) include:
516 * - 'A': print an ACE_timer_t value (which could be either double
517 * or ACE_UINT32.)
518 * - 'a': abort the program at this point abruptly.
519 * - 'b': print a ssize_t value
520 * - 'B': print a size_t value
521 * - 'c': print a character
522 * - 'C': print a char* character string (also see s and W)
523 * - 'i', 'd': print a decimal number
524 * - 'I': indent according to nesting depth (obtained from
525 * ACE_Trace::get_nesting_indent()).
526 * - 'e', 'E', 'f', 'F', 'g', 'G': print a double
527 * - 'l': print line number where an error occurred.
528 * - 'M': print the name of the priority of the message.
529 * - 'm': return the message corresponding to errno value, e.g., as
530 * done by strerror()
531 * - 'N': print file name where the error occurred.
532 * - 'n': print the name of the program (or "<unknown>" if not set)
533 * - 'o': print as an octal number
534 * - 'P': print out the current process id
535 * - 'p': print out the appropriate errno message from sys_errlist,
536 * e.g., as done by perror()
537 * - 'Q': print out the uint64 number
538 * - 'q': print out the int64 number
539 * - '@': print a void* pointer (in hexadecimal)
540 * - 'r': call the function pointed to by the corresponding argument
541 * - 'R': print return status
542 * - 'S': print out the appropriate signal message corresponding
543 * to var-argument, e.g., as done by strsignal()
544 * - 's': prints a ACE_TCHAR* character string (also see C and W)
545 * - 'T': print timestamp in hour:minute:sec:usec format (plain option,
546 * i.e. without any flags, prints system supplied timestamp;
547 * with '#' flag added expects ACE_Time_Value* in argument list)
548 * - 'D': print timestamp as Weekday Month day year hour:minute:sec.usec
549 * (plain option, i.e. without any flags, prints system supplied
550 * timestamp; with '#' flag added expects ACE_Time_Value* in
551 * argument list)
552 * - 't': print thread id (1 if single-threaded)
553 * - 'u': print as unsigned int
554 * - 'w': prints a wide character
555 * - 'W': prints a wchar_t* character string (also see C and s)
556 * - 'x': print as a hex number
557 * - 'X': print as a hex number
558 * - 'z': print an ACE_OS::WChar character
559 * - 'Z': print an ACE_OS::WChar character string
560 * - ':': print a time_t value as an integral number
561 * - '%': print out a single percent sign, '%'
562 * - '?': print out stack trace (see Stack_Trace.h header comments)
564 ssize_t log (ACE_Log_Priority priority, const ACE_TCHAR *format, ...);
566 #if defined (ACE_HAS_WCHAR)
567 ssize_t log (ACE_Log_Priority priority, const ACE_ANTI_TCHAR *format, ...);
568 #endif /* ACE_HAS_WCHAR */
570 #else /* ACE_LACKS_VA_FUNCTIONS */
571 friend class ACE_Log_Formatter;
573 ssize_t log (const ACE_Log_Formatter &formatter);
575 #endif /* ACE_LACKS_VA_FUNCTIONS */
578 * An alternative logging mechanism that makes it possible to
579 * integrate variable argument lists from other logging mechanisms
580 * into the ACE mechanism.
582 ssize_t log (const ACE_TCHAR *format,
583 ACE_Log_Priority priority,
584 va_list argp,
585 ACE_Log_Category_TSS* category=0);
587 /// Log a custom built log record to the currently enabled logging
588 /// sinks.
589 ssize_t log (ACE_Log_Record &log_record,
590 int suppress_stderr = 0);
593 * Method to log hex dump. This is useful for debugging. Calls
594 * log() to do the actual print, but formats first to make the chars
595 * printable.
597 int log_hexdump (ACE_Log_Priority log_priority,
598 const char *buffer,
599 size_t size,
600 const ACE_TCHAR *text = 0,
601 ACE_Log_Category_TSS* category=0);
604 * Init hook, create a Log_Msg_Attribute object, initialize its
605 * attributes from the TSS Log_Msg and save the object in the
606 * @a attributes argument
608 static void init_hook (ACE_OS_Log_Msg_Attributes &attributes
609 # if defined (ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS)
610 , ACE_SEH_EXCEPT_HANDLER selector = 0
611 , ACE_SEH_EXCEPT_HANDLER handler = 0
612 # endif /* ACE_HAS_WIN32_STRUCTURED_EXCEPTIONS */
616 * Inherit hook, the @a attributes field is a ACE_OS_Log_Msg_Attributes
617 * object, invoke the inherit_log_msg() method on it, then destroy
618 * it and set the @a attribute argument to 0.
620 static void inherit_hook (ACE_OS_Thread_Descriptor *thr_desc,
621 ACE_OS_Log_Msg_Attributes &attributes);
623 /// Dump the state of an object.
624 void dump () const;
626 /// Declare the dynamic allocation hooks.
627 ACE_ALLOC_HOOK_DECLARE;
629 private:
630 void cleanup_ostream ();
632 /// Status of operation (-1 means failure, >= 0 means success).
633 int status_;
635 /// Type of error that occurred (see <sys/errno.h>).
636 int errnum_;
638 /// Line number where the error occurred.
639 int linenum_;
641 /// File where the error occurred.
642 char file_[MAXPATHLEN + 1];
644 /// The log message, which resides in thread-specific storage. Note
645 /// that only the current log message is stored here -- it will be
646 /// overwritten by the subsequent call to log().
647 ACE_TCHAR* msg_; // Add one for NUL-terminator.
649 /// Indicates whether we should restart system calls that are
650 /// interrupted.
651 bool restart_;
653 /// The ostream where logging messages can be written.
654 ACE_OSTREAM_TYPE *ostream_;
656 /// This pointer is 0 if we are not reference counting (the user has not
657 /// passed "true" for the delete_ostream argument to msg_ostream).
658 /// If we are reference counting, this points to a shared count that will
659 /// be deleted when it reaches zero. Since we want optional but shared
660 /// ownership neither std::unique_ptr nor ACE_Strong_Bound_Ptr have the right
661 /// semantics. *Bound_Ptr also doesn't take advantage of Atomic_Op.
662 typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, unsigned long> Atomic_ULong;
663 Atomic_ULong *ostream_refcount_;
665 /// The callback object.
666 ACE_Log_Msg_Callback *msg_callback_;
668 /// Depth of the nesting for printing traces.
669 int trace_depth_;
671 /// Are we already within an ACE_Trace constructor call?
672 bool trace_active_;
674 /// Are we allowing tracing in this thread?
675 bool tracing_enabled_;
678 * If we're running in the context of an ACE_Thread_Manager this
679 * will point to the thread descriptor adapter which holds the
680 * thread descriptor of the thread. This can be used to rapidly
681 * access all thread data kept in ACE_Thread_Descriptor.
683 ACE_Thread_Descriptor *thr_desc_;
686 * Keeps track of all the per-thread ACE_Log_Priority values that
687 * are currently enabled. Default is for all logging priorities to
688 * be disabled.
690 u_long priority_mask_;
692 /// Always timestamp?
693 int timestamp_;
695 // = The following fields are *not* kept in thread-specific storage.
697 // We only want one instance for the entire process!
700 * Keeps track of all the per-process ACE_Log_Priority values that
701 * are currently enabled. Default is for all logging priorities to
702 * be enabled.
704 static u_long process_priority_mask_;
706 /// Records the program name.
707 static const ACE_TCHAR *program_name_;
709 /// Name of the local host (used when printing messages).
710 static const ACE_TCHAR *local_host_;
712 /// Options flags used to hold the logger flag options, e.g.,
713 /// STDERR, LOGGER, OSTREAM, MSG_CALLBACK, etc.
714 static u_long flags_;
716 /// Offset of msg_[].
717 static ptrdiff_t msg_off_;
720 * Number of existing ACE_Log_Msg instances; when 0, delete program/host
721 * names
723 static int instance_count_;
726 * Priority mask to use for each new instance
728 static u_long default_priority_mask_;
730 /// Anonymous struct since there will only be one instance. This
731 /// struct keeps information stored away in case we actually end up
732 /// calling log() if the log priority is correct.
733 struct
735 bool is_set_;
736 const char *file_;
737 int line_;
738 int op_status_;
739 int errnum_;
740 } conditional_values_;
742 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
743 static bool key_created_;
744 #endif /* ACE_MT_SAFE */
746 /// For cleanup, at program termination.
747 static void close ();
749 /// Decouple the OS layer from the ACE_Log_Msg layer.
750 static void sync_hook (const ACE_TCHAR *prg_name);
752 /// Return the TSS singleton thread descriptor
753 static ACE_OS_Thread_Descriptor *thr_desc_hook ();
755 //friend void ACE_OS::cleanup_tss (const u_int);
757 // = Disallow these operations.
758 ACE_Log_Msg &operator= (const ACE_Log_Msg &);
759 ACE_Log_Msg (const ACE_Log_Msg &);
762 #ifdef ACE_LACKS_VA_FUNCTIONS
763 class ACE_Time_Value;
764 /// Alternative to varargs for formatting log messages.
765 /// When this implementation is enabled, the logging macros (ACE_DEBUG, etc.)
766 /// are modified to change from logger->log(LM_FOO, "fmt_str", arg1, arg2) to
767 /// logger->log((LM_FOO, "fmt_str", arg1, arg2)). Due to the extra set of
768 /// parens, the various overloaded comma operators below take the place of the
769 /// varargs function. The first operator called is the non-member
770 /// operator,(ACE_Log_Priority, const char*) which returns an ACE_Log_Formatter
771 /// object. The subsequent comma operators (for the actual variable args) are
772 /// members of the ACE_Log_Formatter class.
773 class ACE_Export ACE_Log_Formatter
775 public:
776 ACE_Log_Formatter (ACE_Log_Priority prio, const char *fmt);
778 // Notes:
779 // - ACE_OS::snprintf() is assumed to work. The fallback to ACE_OS::sprintf()
780 /// is not implemented.
781 // - Other than special cases (listed below), the names of the parameters
782 // indicate which formatters they are used for (pct_c => %c).
783 // - size_t (%B), ssize_t (%b), and time_t (%:) will use one of the
784 // other overloads (int, INT64, UINT64) depending on the platform.
785 // - %*s (etc) uses the int or uint overloads for the size argument.
786 // - No support for ACE_USES_WCHAR has been attempted.
787 // - Not all platform-specific features from the varargs implementation have
788 // been ported over to this implementation.
790 ACE_Log_Formatter &operator, (int pct_adiRS);
792 ACE_Log_Formatter &operator, (unsigned int pct_ouxX);
794 ACE_Log_Formatter &operator, (double pct_AeEfFgG);
796 ACE_Log_Formatter &operator, (long double pct_AeEfFgG);
798 ACE_Log_Formatter &operator, (char pct_c);
800 ACE_Log_Formatter &operator, (const char *pct_Cps);
802 ACE_Log_Formatter &operator, (ACE_INT64 pct_q);
804 ACE_Log_Formatter &operator, (ACE_UINT64 pct_Q);
806 ACE_Log_Formatter &operator, (void (*pct_r) ());
808 ACE_Log_Formatter &operator, (ACE_WCHAR_T pct_wz);
810 ACE_Log_Formatter &operator, (const ACE_WCHAR_T *pct_WZ);
812 ACE_Log_Formatter &operator, (const void *pct_at);
814 ACE_Log_Formatter &operator, (const ACE_Time_Value *pct_DT);
816 #if ACE_SIZEOF_LONG == 4
817 ACE_Log_Formatter &operator, (long pct_Lmodifier);
819 ACE_Log_Formatter &operator, (unsigned long pct_Lmodifier);
820 #endif
822 bool abort () const { return this->abort_; }
824 int saved_errno () const { return this->saved_errno_; }
826 bool to_record (ACE_Log_Record &record);
828 ACE_Log_Priority priority () const { return this->priority_; }
830 private:
831 /// Parse the format_ string up to the point where an argument is needed.
832 /// Set up fmt_out_ as a format string that goes out to snprintf.
833 void prepare_format ();
835 /// Helper function for prepare_format. Processes as much of one conversion
836 /// specification as possible. Returns true if prepare_format can continue
837 /// parsing, false if prepare_format needs to return to get more input.
838 bool process_conversion ();
840 /// Copy up to 'limit' characters of 'str' to the resulting buffer (bp_).
841 /// Returns the number of characters copied.
842 int copy_trunc (const char *str, int limit);
844 /// Insert one argument into the formatted buffer.
845 /// arg is not a pointer (pointers use the overload below).
846 /// If allow_star is true, the argument can be the length for a conversion
847 /// that uses the '*' for width or precision.
848 template <typename ArgT>
849 void insert_arg (ArgT arg, bool allow_star = false);
851 /// Insert one pointer-typed argument into the formatted buffer.
852 /// These could be strings (so ArgT is const char or const wchar_t) or void*.
853 template <typename ArgT>
854 void insert_arg (ArgT *arg);
856 /// Core functionality common to both insert_arg overloads.
857 template <typename ArgT>
858 void insert_arg_i (ArgT arg);
860 /// Insert the %S (signal name) conversion specification into the buffer.
861 void insert_pct_S (int sig);
863 /// Save errno at the start of the log formatting so it can be restored later.
864 const int saved_errno_;
866 /// Priority of this message.
867 const ACE_Log_Priority priority_;
869 /// Remaining format string (from user) that's left to process.
870 const char *format_;
872 /// The ACE_Log_Msg object that this formatter works with.
873 ACE_Log_Msg *const logger_;
875 /// Saved state of the %a (abort) processing.
876 enum { ABRT_NONE, ABRT_AFTER_FORMAT, ABRT_NEED_ARG } abort_;
878 /// The current log priority is enabled on the logger object.
879 bool enabled_;
881 /// Which specifier is currently being processed (' ' for none).
882 char in_prog_;
884 /// The value last read in from the "varargs" for '*' in width or precision.
885 int last_star_;
887 /// Buffer pointer into ACE_Log_Msg's resulting buffer.
888 char *bp_;
890 /// Buffer space available for bp_ to advance.
891 size_t bspace_;
893 /// Local buffer for outgoing (given to snprintf) format strings.
894 char fmt_out_[128];
896 /// Format pointer: current position in fmt_out_.
897 char *fp_;
899 /// Saved value of ACE_Log_Msg::msg_off_ in case of reentrant logging (%r).
900 ptrdiff_t offset_;
903 ACE_Export
904 ACE_Log_Formatter operator, (ACE_Log_Priority prio, const char *fmt);
906 #endif /* ACE_LACKS_VA_FUNCTIONS */
908 ACE_END_VERSIONED_NAMESPACE_DECL
910 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
911 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || \
912 defined (ACE_HAS_TSS_EMULATION)
913 /* static */
914 # if defined (ACE_HAS_THR_C_DEST)
915 # define LOCAL_EXTERN_PREFIX extern "C"
916 # else
917 # define LOCAL_EXTERN_PREFIX
918 # endif /* ACE_HAS_THR_C_DEST */
920 #if (defined (ACE_HAS_VERSIONED_NAMESPACE) && ACE_HAS_VERSIONED_NAMESPACE == 1)
921 # define ACE_TSS_CLEANUP_NAME ACE_PREPROC_CONCATENATE(ACE_,ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _TSS_cleanup))
922 #else
923 # define ACE_TSS_CLEANUP_NAME ACE_TSS_cleanup
924 #endif /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
926 LOCAL_EXTERN_PREFIX
927 void
928 ACE_TSS_CLEANUP_NAME (void *ptr);
929 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION */
930 #endif /* ACE_MT_SAFE */
932 #if defined (__ACE_INLINE__)
933 #include "ace/Log_Msg.inl"
934 #endif /* __ACE_INLINE__ */
936 #include /**/ "ace/post.h"
937 #endif /* ACE_LOG_MSG_H */