00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Log_Msg.h 00006 * 00007 * $Id: Log_Msg.h 87250 2009-10-28 11:57:17Z olli $ 00008 * 00009 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef ACE_LOG_MSG_H 00014 #define ACE_LOG_MSG_H 00015 #include /**/ "ace/pre.h" 00016 00017 // This stuff must come first to avoid problems with circular 00018 // headers... 00019 // ... but ACE_NDEBUG and ACE_NLOGGING can come from the config.h file, so 00020 // pull that one early. 00021 #include /**/ "ace/config-all.h" 00022 #include /**/ "ace/ACE_export.h" 00023 #include "ace/Global_Macros.h" 00024 #include "ace/Default_Constants.h" 00025 #include "ace/Log_Priority.h" 00026 #include "ace/os_include/os_limits.h" 00027 #include "ace/Atomic_Op.h" 00028 #include "ace/Synch_Traits.h" 00029 00030 // The ACE_ASSERT macro used to be defined here, include ace/Assert.h 00031 // for backwards compatibility. 00032 #include "ace/Assert.h" 00033 00034 #if defined (ACE_NLOGGING) 00035 #if !defined (ACE_HEX_DUMP) 00036 # define ACE_HEX_DUMP(X) do {} while (0) 00037 #endif 00038 #if !defined (ACE_RETURN) 00039 # define ACE_RETURN(Y) do { return (Y); } while (0) 00040 #endif 00041 #if !defined (ACE_ERROR_RETURN) 00042 # define ACE_ERROR_RETURN(X, Y) return (Y) 00043 #endif 00044 #if !defined (ACE_ERROR_BREAK) 00045 # define ACE_ERROR_BREAK(X) { break; } 00046 #endif 00047 #if !defined (ACE_ERROR) 00048 # define ACE_ERROR(X) do {} while (0) 00049 #endif 00050 #if !defined (ACE_DEBUG) 00051 # define ACE_DEBUG(X) do {} while (0) 00052 #endif 00053 #if !defined (ACE_ERROR_INIT) 00054 # define ACE_ERROR_INIT(VALUE, FLAGS) 00055 #endif 00056 #else 00057 #if !defined (ACE_HEX_DUMP) 00058 #define ACE_HEX_DUMP(X) \ 00059 do { \ 00060 int __ace_error = ACE_Log_Msg::last_error_adapter (); \ 00061 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \ 00062 ace___->conditional_set (__FILE__, __LINE__, 0, __ace_error); \ 00063 ace___->log_hexdump X; \ 00064 } while (0) 00065 #endif 00066 #if !defined (ACE_RETURN) 00067 #define ACE_RETURN(Y) \ 00068 do { \ 00069 int __ace_error = ACE_Log_Msg::last_error_adapter (); \ 00070 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \ 00071 ace___->set (__FILE__, __LINE__, Y, __ace_error, ace___->restart (), \ 00072 ace___->msg_ostream (), ace___->msg_callback ()); \ 00073 return Y; \ 00074 } while (0) 00075 #endif 00076 #if !defined (ACE_ERROR_RETURN) 00077 #define ACE_ERROR_RETURN(X, Y) \ 00078 do { \ 00079 int __ace_error = ACE_Log_Msg::last_error_adapter (); \ 00080 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \ 00081 ace___->conditional_set (__FILE__, __LINE__, Y, __ace_error); \ 00082 ace___->log X; \ 00083 return Y; \ 00084 } while (0) 00085 #endif 00086 #if !defined (ACE_ERROR) 00087 #define ACE_ERROR(X) \ 00088 do { \ 00089 int __ace_error = ACE_Log_Msg::last_error_adapter (); \ 00090 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \ 00091 ace___->conditional_set (__FILE__, __LINE__, -1, __ace_error); \ 00092 ace___->log X; \ 00093 } while (0) 00094 #endif 00095 #if !defined (ACE_DEBUG) 00096 #define ACE_DEBUG(X) \ 00097 do { \ 00098 int __ace_error = ACE_Log_Msg::last_error_adapter (); \ 00099 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \ 00100 ace___->conditional_set (__FILE__, __LINE__, 0, __ace_error); \ 00101 ace___->log X; \ 00102 } while (0) 00103 #endif 00104 #if !defined (ACE_ERROR_INIT) 00105 #define ACE_ERROR_INIT(VALUE, FLAGS) \ 00106 do { \ 00107 ACE_Log_Msg *ace___ = ACE_Log_Msg::instance (); \ 00108 ace___->set_flags (FLAGS); ace___->op_status (VALUE); \ 00109 } while (0) 00110 #endif 00111 #if !defined (ACE_ERROR_BREAK) 00112 #define ACE_ERROR_BREAK(X) { ACE_ERROR (X); break; } 00113 #endif 00114 #endif /* ACE_NLOGGING */ 00115 00116 #include "ace/OS_Log_Msg_Attributes.h" 00117 00118 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00119 # pragma once 00120 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00121 00122 // These workarounds are necessary for nasty libraries or platforms 00123 // that #define STDERR or THREAD (e.g. LynxOS). We simply #undef 00124 // these macros as there is no way to save the macro definition using 00125 // the pre-processor. See Bugzilla Bug #299 for more info. 00126 00127 #if defined (STDERR) 00128 # undef STDERR 00129 #endif /* STDERR */ 00130 00131 #if defined (THREAD) 00132 # undef THREAD 00133 #endif /* THREAD */ 00134 00135 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00136 00137 class ACE_Log_Msg_Callback; 00138 class ACE_Log_Msg_Backend; 00139 00140 // **************************************************************** 00141 00142 #define ACE_LOG_MSG ACE_Log_Msg::instance () 00143 00144 // Forward declaration 00145 class ACE_Thread_Descriptor; 00146 class ACE_Log_Record; 00147 00148 /** 00149 * @class ACE_Log_Msg 00150 * 00151 * @brief Provides a variable length argument message logging 00152 * abstraction. 00153 * 00154 * This class is very flexible since it allows formatted error 00155 * messages to be printed in a thread-safe manner to various 00156 * locations, such as stderr, cerr, a distributed logger, etc. The 00157 * current message is also kept in a thread-specific storage location 00158 * (threads spawned using ACE_Thread_Manager automatically get an 00159 * ACE_Log_Msg object that inherits the spawning thread's settings), 00160 * which can be used to communicate errors between framework methods 00161 * and callers. A message is logged by the log() method, only if the 00162 * message priority is currently enabled. Moreover, only the current 00163 * log message is stored here -- it will be overwritten by the 00164 * subsequent call to log(). 00165 * 00166 * The ACE_Log_Msg class uses two priority masks to control its 00167 * logging behavior. The @c priority_mask_ object attribute is 00168 * thread- specific and specifies the priority levels logged by the 00169 * thread. The @c process_priority_mask_ class attribute is not 00170 * thread-specific and specifies the priority levels that will be 00171 * logged by all threads in the process. By default, all levels are 00172 * disabled for @c priority_mask_ and all levels are enabled for @c 00173 * process_priority_mask_ (i.e. the process-wide mask controls the 00174 * settings, and each instance can expand on it if desired). Both 00175 * priority masks can be modified using the priority_mask() method of 00176 * this class. 00177 */ 00178 class ACE_Export ACE_Log_Msg 00179 { 00180 public: 00181 // Logger Flags. 00182 enum 00183 { 00184 /// Write messages to stderr. 00185 STDERR = 1, 00186 /// Write messages to the local client logger deamon. 00187 LOGGER = 2, 00188 /// Write messages to the ostream * stored in thread-specific 00189 /// storage. 00190 OSTREAM = 4, 00191 /// Write messages to the callback object. 00192 MSG_CALLBACK = 8, 00193 /// Display messages in a verbose manner. 00194 VERBOSE = 16, 00195 /// Display messages in a less verbose manner (i.e., only print 00196 /// information that can change between calls). 00197 VERBOSE_LITE = 32, 00198 /// Do not print messages at all (just leave in thread-specific 00199 /// storage for later inspection). 00200 SILENT = 64, 00201 /// Write messages to the system's event log. 00202 SYSLOG = 128, 00203 /// Write messages to the user provided backend 00204 CUSTOM = 256 00205 }; 00206 00207 // = Initialization and termination routines. 00208 00209 /// Returns a pointer to the Singleton. 00210 static ACE_Log_Msg *instance (void); 00211 00212 /// Returns last error. 00213 static int last_error_adapter (void); 00214 00215 /// Returns non-null if an ACE_Log_Msg exists for the calling thread. 00216 static int exists (void); 00217 00218 /// Returns the current program name used for logging. 00219 static const ACE_TCHAR * program_name (void); 00220 00221 /// Clears the flag from the default priority mask used to 00222 /// initialize ACE_Log_Msg instances. 00223 static void disable_debug_messages (ACE_Log_Priority priority = LM_DEBUG); 00224 00225 /// Sets the flag in the default priority mask used to initialize 00226 /// ACE_Log_Msg instances. 00227 static void enable_debug_messages (ACE_Log_Priority priority = LM_DEBUG); 00228 00229 /// Initialize logger. 00230 ACE_Log_Msg (void); 00231 00232 /// cleanup logger. 00233 ~ACE_Log_Msg (void); 00234 00235 /// Initialize the ACE logging facility. 00236 /** 00237 * Initialize the ACE logging facility. Supplies the program name 00238 * that is available to each logging message call. Default arguments 00239 * set up logging to STDERR only. 00240 * 00241 * @param prog_name The name of the calling program. 00242 * @param options_flags A bitwise-or of options flags used to set the 00243 * initial behavior and logging sink(s). (see the 00244 * enum above for the valid values). 00245 * @param logger_key The name of ACE_FIFO rendezvous point where the 00246 * local client logger daemon is listening for logging 00247 * messages if the LOGGER bit is set in the @a flags 00248 * argument. If the SYSLOG bit is set in @a flags, 00249 * @a logger_key is the source/program name specified 00250 * in the syslog facility (UNIX/Linux) or the Windows 00251 * event log (Windows). In the SYSLOG case, if 00252 * @a logger_key is 0, @a prog_name is used. 00253 */ 00254 int open (const ACE_TCHAR *prog_name, 00255 u_long options_flags = ACE_Log_Msg::STDERR, 00256 const ACE_TCHAR *logger_key = 0); 00257 00258 // = Set/get the options flags. 00259 00260 /** 00261 * Enable the bits in the logger's options flags. 00262 */ 00263 void set_flags (u_long f); 00264 00265 /** 00266 * Disable the bits in the logger's options flags. 00267 */ 00268 void clr_flags (u_long f); 00269 00270 /** 00271 * Return the bits in the logger's options flags. 00272 */ 00273 u_long flags (void); 00274 00275 /** @name Allow apps to acquire and release internal synchronization 00276 * lock 00277 * 00278 * This lock is used internally by the ACE_Log_Msg 00279 * implementation. By exporting the lock, applications can hold the 00280 * lock atomically over a number of calls to ACE_Log_Msg. 00281 */ 00282 //@{ 00283 00284 /// Acquire the internal lock. 00285 int acquire (void); 00286 00287 /// Release the internal lock. 00288 int release (void); 00289 //@} 00290 00291 /// Call after doing a @c fork() to resynchronize the process id and 00292 /// @c program_name_ variables. 00293 void sync (const ACE_TCHAR *program_name); 00294 00295 // = Set/get methods. Note that these are non-static and thus will 00296 // be thread-specific. 00297 00298 /// Set the result of the operation status (by convention, -1 means 00299 /// error). 00300 void op_status (int status); 00301 00302 /// Get the result of the operation status (by convention, -1 means 00303 /// error). 00304 int op_status (void) const; 00305 00306 /// Set the value of the errnum (by convention this corresponds to 00307 /// errno). 00308 void errnum (int); 00309 00310 /// Get the value of the errnum (by convention this corresponds to 00311 /// errno). 00312 int errnum (void) const; 00313 00314 /// Set the line number where an error occurred. 00315 void linenum (int); 00316 00317 /// Get the line number where an error occurred. 00318 int linenum (void) const; 00319 00320 /// Set the file name where an error occurred. 00321 void file (const char *); 00322 00323 /// Get the file name where an error occurred. 00324 const char *file (void); 00325 00326 /// Set the message that describes what type of error occurred. 00327 void msg (const ACE_TCHAR *); 00328 00329 /// Get the message that describes what type of error occurred. 00330 const ACE_TCHAR *msg (void); 00331 00332 /// Set the field that indicates whether interrupted calls should be 00333 /// restarted. 00334 void restart (bool r); 00335 00336 /// Get the field that indicates whether interrupted calls should be 00337 /// restarted. 00338 bool restart (void) const; 00339 00340 // = Notice that the following two function is equivalent to 00341 // "void msg_ostream (HANDLE)" and "HANDLE msg_ostream (void)" 00342 // on Windows CE. There is no <iostream.h> support on CE. 00343 00344 /// Update the ostream without overwriting the delete_ostream_ flag. 00345 void msg_ostream (ACE_OSTREAM_TYPE *); 00346 00347 /** 00348 * delete_stream == true, forces Log_Msg.h to delete the stream in 00349 * its own ~dtor (assumes control of the stream) 00350 * use only with proper ostream (eg: fstream), not (cout, cerr) 00351 */ 00352 void msg_ostream (ACE_OSTREAM_TYPE *, bool delete_ostream); 00353 00354 /// Get the ostream that is used to print error messages. 00355 ACE_OSTREAM_TYPE *msg_ostream (void) const; 00356 00357 /** 00358 * Set a new callback object and return the existing callback to 00359 * allow "chaining". Note that ACE_Log_Msg_Callback objects are not 00360 * inherited when spawning a new thread, so you'll need to reset 00361 * them in each thread. 00362 */ 00363 ACE_Log_Msg_Callback *msg_callback (ACE_Log_Msg_Callback *c); 00364 ACE_Log_Msg_Callback *msg_callback (void) const; 00365 00366 /** 00367 * Set a new backend object and return the existing backend to 00368 * allow "chaining". Note that as opposed to ACE_Log_Msg_Callback, 00369 * ACE_Log_Msg_Backend is a per-process entity. 00370 * 00371 * @note Be aware that because of the current architecture there is 00372 * no guarantee that open (), reset () and close () will be called 00373 * on a backend object. 00374 * 00375 */ 00376 static ACE_Log_Msg_Backend *msg_backend (ACE_Log_Msg_Backend *b); 00377 static ACE_Log_Msg_Backend *msg_backend (void); 00378 00379 /// Nesting depth increment. 00380 int inc (void); 00381 00382 /// Nesting depth decrement. 00383 int dec (void); 00384 00385 /// Get trace depth. 00386 int trace_depth (void) const; 00387 00388 /// Set trace depth. 00389 void trace_depth (int); 00390 00391 /// Get trace active status. 00392 bool trace_active (void) const; 00393 00394 /// Set trace active status. 00395 void trace_active (bool value); 00396 00397 /// Get the TSS thread descriptor. 00398 ACE_Thread_Descriptor *thr_desc (void) const; 00399 00400 /** 00401 * Set the TSS thread descriptor. This method will call 00402 * td->acquire_release to block execution until this call 00403 * return. 00404 */ 00405 void thr_desc (ACE_Thread_Descriptor *td); 00406 00407 #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS) && defined(ACE_LEGACY_MODE) 00408 // These functions are disabled without ACE_LEGACY_MODE 00409 // because the *semantics* have changed (the objects are no longer 00410 // TSS). 00411 /// Get TSS exception action. 00412 /// @note The action is no longer TSS, they are global! 00413 ACE_SEH_EXCEPT_HANDLER seh_except_selector (void); 00414 00415 /// Set TSS exception action. 00416 /// @note The action is no longer TSS, they are global! 00417 ACE_SEH_EXCEPT_HANDLER seh_except_selector (ACE_SEH_EXCEPT_HANDLER); 00418 00419 /// Get TSS exception handler. 00420 /// @note The handler is no longer TSS, they are global! 00421 ACE_SEH_EXCEPT_HANDLER seh_except_handler (void); 00422 00423 /// Set TSS exception handler. 00424 /// @note The handler is no longer TSS, they are global! 00425 ACE_SEH_EXCEPT_HANDLER seh_except_handler (ACE_SEH_EXCEPT_HANDLER); 00426 #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS && ACE_LEGACY_MODE */ 00427 00428 /// Stop tracing status on a per-thread basis... 00429 void stop_tracing (void); 00430 00431 /// Start tracing status on a per-thread basis... 00432 void start_tracing (void); 00433 00434 /// Query tracing status on a per-thread basis... 00435 bool tracing_enabled (void) const; 00436 00437 typedef enum 00438 { 00439 PROCESS = 0, 00440 THREAD = 1 00441 } MASK_TYPE; 00442 00443 // = Get/set the priority mask. 00444 /// Get the current ACE_Log_Priority mask. 00445 u_long priority_mask (MASK_TYPE = THREAD); 00446 00447 /// Set the ACE_Log_Priority mask, returns original mask. 00448 u_long priority_mask (u_long, MASK_TYPE = THREAD); 00449 00450 /// Return true if the requested priority is enabled. 00451 int log_priority_enabled (ACE_Log_Priority log_priority); 00452 00453 /// Return true if the requested priority is enabled. 00454 int log_priority_enabled (ACE_Log_Priority log_priority, 00455 const char *, 00456 ...); 00457 00458 #if defined (ACE_USES_WCHAR) 00459 // We are not using ACE_TCHAR for this since ACE_HEX_DUMP 00460 // doesn't take in a ACE_TCHAR. log_hexdump takes in a char 00461 // string, so this must be able to take in a char string even 00462 // when using ACE_USES_WCHAR. 00463 /// Return true if the requested priority is enabled. 00464 int log_priority_enabled (ACE_Log_Priority log_priority, 00465 const wchar_t *, 00466 ...); 00467 #endif /* ACE_USES_WCHAR */ 00468 00469 /// Optimize reading of the pid (avoids a system call if the value is 00470 /// cached...). 00471 pid_t getpid (void) const; 00472 00473 /// Get the name of the local host. 00474 const ACE_TCHAR *local_host (void) const; 00475 00476 /// Set the name of the local host. 00477 void local_host (const ACE_TCHAR *); 00478 00479 /** 00480 * Set the line number, file name, operational status, error number, 00481 * restart flag, ostream, and the callback object. This combines 00482 * all the other set methods into a single method. 00483 */ 00484 void set (const char *file, 00485 int line, 00486 int op_status = -1, 00487 int errnum = 0, 00488 bool restart = true, 00489 ACE_OSTREAM_TYPE *os = 0, 00490 ACE_Log_Msg_Callback *c = 0); 00491 00492 /// These values are only actually set if the requested priority is 00493 /// enabled. 00494 void conditional_set (const char *file, 00495 int line, 00496 int op_status, 00497 int errnum); 00498 00499 /** 00500 * Format a message to the thread-safe ACE logging mechanism. Valid 00501 * options (prefixed by '%', as in printf format strings) include: 00502 * - 'A': print an ACE_timer_t value (which could be either double 00503 * or ACE_UINT32.) 00504 * - 'a': abort the program at this point abruptly. 00505 * - 'b': print a ssize_t value 00506 * - 'B': print a size_t value 00507 * - 'c': print a character 00508 * - 'C': print a char* character string (also see s and W) 00509 * - 'i', 'd': print a decimal number 00510 * - 'I': indent according to nesting depth (obtained from 00511 * ACE_Trace::get_nesting_indent()). 00512 * - 'e', 'E', 'f', 'F', 'g', 'G': print a double 00513 * - 'l': print line number where an error occurred. 00514 * - 'M': print the name of the priority of the message. 00515 * - 'm': return the message corresponding to errno value, e.g., as 00516 * done by strerror() 00517 * - 'N': print file name where the error occurred. 00518 * - 'n': print the name of the program (or "<unknown>" if not set) 00519 * - 'o': print as an octal number 00520 * - 'P': print out the current process id 00521 * - 'p': print out the appropriate errno message from sys_errlist, 00522 * e.g., as done by perror() 00523 * - 'Q': print out the uint64 number 00524 * - 'q': print out the int64 number 00525 * - '@': print a void* pointer (in hexadecimal) 00526 * - 'r': call the function pointed to by the corresponding argument 00527 * - 'R': print return status 00528 * - 'S': print out the appropriate signal message corresponding 00529 * to var-argument, e.g., as done by strsignal() 00530 * - 's': prints a ACE_TCHAR* character string (also see C and W) 00531 * - 'T': print timestamp in hour:minute:sec:usec format. 00532 * - 'D': print timestamp as Weekday Month day year hour:minute:sec.usec 00533 * - 't': print thread id (1 if single-threaded) 00534 * - 'u': print as unsigned int 00535 * - 'w': prints a wide character 00536 * - 'W': prints a wchar_t* character string (also see C and s) 00537 * - 'x': print as a hex number 00538 * - 'X': print as a hex number 00539 * - 'z': print an ACE_OS::WChar character 00540 * - 'Z': print an ACE_OS::WChar character string 00541 * - ':': print a time_t value as an integral number 00542 * - '%': print out a single percent sign, '%' 00543 * - '?': print out stack trace (see Stack_Trace.h header comments) 00544 */ 00545 ssize_t log (ACE_Log_Priority priority, const ACE_TCHAR *format, ...); 00546 00547 #if defined (ACE_HAS_WCHAR) 00548 ssize_t log (ACE_Log_Priority priority, const ACE_ANTI_TCHAR *format, ...); 00549 #endif /* ACE_HAS_WCHAR */ 00550 00551 /** 00552 * An alternative logging mechanism that makes it possible to 00553 * integrate variable argument lists from other logging mechanisms 00554 * into the ACE mechanism. 00555 */ 00556 ssize_t log (const ACE_TCHAR *format, 00557 ACE_Log_Priority priority, 00558 va_list argp); 00559 00560 /// Log a custom built log record to the currently enabled logging 00561 /// sinks. 00562 ssize_t log (ACE_Log_Record &log_record, 00563 int suppress_stderr = 0); 00564 00565 /** 00566 * Method to log hex dump. This is useful for debugging. Calls 00567 * log() to do the actual print, but formats first to make the chars 00568 * printable. 00569 */ 00570 int log_hexdump (ACE_Log_Priority log_priority, 00571 const char *buffer, 00572 size_t size, 00573 const ACE_TCHAR *text = 0); 00574 00575 static void init_hook (ACE_OS_Log_Msg_Attributes &attributes 00576 # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS) 00577 , ACE_SEH_EXCEPT_HANDLER selector = 0 00578 , ACE_SEH_EXCEPT_HANDLER handler = 0 00579 # endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */ 00580 /** 00581 * Init hook, create a Log_Msg_Attribute object, initialize its 00582 * attributes from the TSS Log_Msg and save the object in the 00583 * @a attributes argument 00584 */ 00585 ); 00586 00587 /** 00588 * Inherit hook, the @a attributes field is a ACE_OS_Log_Msg_Attributes 00589 * object, invoke the inherit_log_msg() method on it, then destroy 00590 * it and set the @a attribute argument to 0. 00591 */ 00592 static void inherit_hook (ACE_OS_Thread_Descriptor *thr_desc, 00593 ACE_OS_Log_Msg_Attributes &attributes); 00594 00595 /// Dump the state of an object. 00596 void dump (void) const; 00597 00598 /// Declare the dynamic allocation hooks. 00599 ACE_ALLOC_HOOK_DECLARE; 00600 00601 private: 00602 void cleanup_ostream (); 00603 00604 /// Status of operation (-1 means failure, >= 0 means success). 00605 int status_; 00606 00607 /// Type of error that occurred (see <sys/errno.h>). 00608 int errnum_; 00609 00610 /// Line number where the error occurred. 00611 int linenum_; 00612 00613 /// File where the error occurred. 00614 char file_[MAXPATHLEN + 1]; 00615 00616 /// The log message, which resides in thread-specific storage. Note 00617 /// that only the current log message is stored here -- it will be 00618 /// overwritten by the subsequent call to log(). 00619 ACE_TCHAR* msg_; // Add one for NUL-terminator. 00620 00621 /// Indicates whether we should restart system calls that are 00622 /// interrupted. 00623 bool restart_; 00624 00625 /// The ostream where logging messages can be written. 00626 ACE_OSTREAM_TYPE *ostream_; 00627 00628 /// This pointer is 0 if we are not reference counting (the user has not 00629 /// passed "true" for the delete_ostream argument to msg_ostream). 00630 /// If we are reference counting, this points to a shared count that will 00631 /// be deleted when it reaches zero. Since we want optional but shared 00632 /// ownership neither std::auto_ptr nor ACE_Strong_Bound_Ptr have the right 00633 /// semantics. *Bound_Ptr also doesn't take advantage of Atomic_Op. 00634 typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, unsigned long> Atomic_ULong; 00635 Atomic_ULong *ostream_refcount_; 00636 00637 /// The callback object. 00638 ACE_Log_Msg_Callback *msg_callback_; 00639 00640 /// Depth of the nesting for printing traces. 00641 int trace_depth_; 00642 00643 /// Are we already within an ACE_Trace constructor call? 00644 bool trace_active_; 00645 00646 /// Are we allowing tracing in this thread? 00647 bool tracing_enabled_; 00648 00649 /** 00650 * If we're running in the context of an ACE_Thread_Manager this 00651 * will point to the thread descriptor adapter which holds the 00652 * thread descriptor of the thread. This can be used to repidly 00653 * access all thread data kept in ACE_Thread_Descriptor. 00654 */ 00655 ACE_Thread_Descriptor *thr_desc_; 00656 00657 /** 00658 * Keeps track of all the per-thread ACE_Log_Priority values that 00659 * are currently enabled. Default is for all logging priorities to 00660 * be disabled. 00661 */ 00662 u_long priority_mask_; 00663 00664 /// Always timestamp? 00665 int timestamp_; 00666 00667 // = The following fields are *not* kept in thread-specific storage. 00668 00669 // We only want one instance for the entire process! 00670 00671 /** 00672 * Keeps track of all the per-process ACE_Log_Priority values that 00673 * are currently enabled. Default is for all logging priorities to 00674 * be enabled. 00675 */ 00676 static u_long process_priority_mask_; 00677 00678 /// Records the program name. 00679 static const ACE_TCHAR *program_name_; 00680 00681 /// Name of the local host (used when printing messages). 00682 static const ACE_TCHAR *local_host_; 00683 00684 /// Process id of the current process. 00685 static pid_t pid_; 00686 00687 /// Options flags used to hold the logger flag options, e.g., 00688 /// STDERR, LOGGER, OSTREAM, MSG_CALLBACK, etc. 00689 static u_long flags_; 00690 00691 /// Offset of msg_[]. 00692 static ptrdiff_t msg_off_; 00693 00694 /** 00695 * Number of existing ACE_Log_Msg instances; when 0, delete program/host 00696 * names 00697 */ 00698 static int instance_count_; 00699 00700 /** 00701 * Priority mask to use for each new instance 00702 */ 00703 static u_long default_priority_mask_; 00704 00705 /// Anonymous struct since there will only be one instance. This 00706 /// struct keeps information stored away in case we actually end up 00707 /// calling log() if the log priority is correct. 00708 struct 00709 { 00710 bool is_set_; 00711 const char *file_; 00712 int line_; 00713 int op_status_; 00714 int errnum_; 00715 } conditional_values_; 00716 00717 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00718 static bool key_created_; 00719 #endif /* ACE_MT_SAFE */ 00720 00721 /// For cleanup, at program termination. 00722 static void close (void); 00723 00724 /// Decouple the OS layer from the ACE_Log_Msg layer. 00725 static void sync_hook (const ACE_TCHAR *prg_name); 00726 00727 /// Return the TSS singleton thread descriptor 00728 static ACE_OS_Thread_Descriptor *thr_desc_hook (void); 00729 00730 //friend void ACE_OS::cleanup_tss (const u_int); 00731 00732 // = Disallow these operations. 00733 ACE_Log_Msg &operator= (const ACE_Log_Msg &); 00734 ACE_Log_Msg (const ACE_Log_Msg &); 00735 }; 00736 00737 ACE_END_VERSIONED_NAMESPACE_DECL 00738 00739 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00740 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || \ 00741 defined (ACE_HAS_TSS_EMULATION) 00742 /* static */ 00743 # if defined (ACE_HAS_THR_C_DEST) 00744 # define LOCAL_EXTERN_PREFIX extern "C" 00745 # else 00746 # define LOCAL_EXTERN_PREFIX 00747 # endif /* ACE_HAS_THR_C_DEST */ 00748 00749 #if (defined (ACE_HAS_VERSIONED_NAMESPACE) && ACE_HAS_VERSIONED_NAMESPACE == 1) 00750 # define ACE_TSS_CLEANUP_NAME ACE_PREPROC_CONCATENATE(ACE_,ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _TSS_cleanup)) 00751 #else 00752 # define ACE_TSS_CLEANUP_NAME ACE_TSS_cleanup 00753 #endif /* ACE_HAS_VERSIONED_NAMESPACE == 1 */ 00754 00755 00756 LOCAL_EXTERN_PREFIX 00757 void 00758 ACE_TSS_CLEANUP_NAME (void *ptr); 00759 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION */ 00760 #endif /* ACE_MT_SAFE */ 00761 00762 #if defined(ACE_LEGACY_MODE) 00763 #include "ace/Log_Msg_Callback.h" 00764 #endif /* ACE_LEGACY_MODE */ 00765 00766 #if defined (__ACE_INLINE__) 00767 #include "ace/Log_Msg.inl" 00768 #endif /* __ACE_INLINE__ */ 00769 00770 #include /**/ "ace/post.h" 00771 #endif /* ACE_LOG_MSG_H */
1.6.1