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