Provides a variable length argument message logging abstraction. More...
#include <Log_Msg.h>
Public Types | |
enum | { STDERR = 1, LOGGER = 2, OSTREAM = 4, MSG_CALLBACK = 8, VERBOSE = 16, VERBOSE_LITE = 32, SILENT = 64, SYSLOG = 128, CUSTOM = 256 } |
enum | MASK_TYPE { PROCESS = 0, THREAD = 1 } |
Public Member Functions | |
ACE_Log_Msg (void) | |
Initialize logger. | |
~ACE_Log_Msg (void) | |
cleanup logger. | |
int | open (const ACE_TCHAR *prog_name, u_long options_flags=ACE_Log_Msg::STDERR, const ACE_TCHAR *logger_key=0) |
Initialize the ACE logging facility. | |
void | set_flags (u_long f) |
void | clr_flags (u_long f) |
u_long | flags (void) |
void | sync (const ACE_TCHAR *program_name) |
void | op_status (int status) |
int | op_status (void) const |
void | errnum (int) |
int | errnum (void) const |
void | linenum (int) |
Set the line number where an error occurred. | |
int | linenum (void) const |
Get the line number where an error occurred. | |
void | file (const char *) |
Set the file name where an error occurred. | |
const char * | file (void) |
Get the file name where an error occurred. | |
void | msg (const ACE_TCHAR *) |
Set the message that describes what type of error occurred. | |
const ACE_TCHAR * | msg (void) |
Get the message that describes what type of error occurred. | |
void | restart (bool r) |
bool | restart (void) const |
void | msg_ostream (ACE_OSTREAM_TYPE *) |
Update the ostream without overwriting the delete_ostream_ flag. | |
void | msg_ostream (ACE_OSTREAM_TYPE *, bool delete_ostream) |
ACE_OSTREAM_TYPE * | msg_ostream (void) const |
Get the ostream that is used to print error messages. | |
ACE_Log_Msg_Callback * | msg_callback (ACE_Log_Msg_Callback *c) |
ACE_Log_Msg_Callback * | msg_callback (void) const |
int | inc (void) |
Nesting depth increment. | |
int | dec (void) |
Nesting depth decrement. | |
int | trace_depth (void) const |
Get trace depth. | |
void | trace_depth (int) |
Set trace depth. | |
bool | trace_active (void) const |
Get trace active status. | |
void | trace_active (bool value) |
Set trace active status. | |
ACE_Thread_Descriptor * | thr_desc (void) const |
Get the TSS thread descriptor. | |
void | thr_desc (ACE_Thread_Descriptor *td) |
void | stop_tracing (void) |
Stop tracing status on a per-thread basis... | |
void | start_tracing (void) |
Start tracing status on a per-thread basis... | |
bool | tracing_enabled (void) const |
Query tracing status on a per-thread basis... | |
u_long | priority_mask (MASK_TYPE=THREAD) |
Get the current ACE_Log_Priority mask. | |
u_long | priority_mask (u_long, MASK_TYPE=THREAD) |
Set the ACE_Log_Priority mask, returns original mask. | |
int | log_priority_enabled (ACE_Log_Priority log_priority) |
Return true if the requested priority is enabled. | |
int | log_priority_enabled (ACE_Log_Priority log_priority, const char *,...) |
Return true if the requested priority is enabled. | |
int | log_priority_enabled (ACE_Log_Priority log_priority, const wchar_t *,...) |
Return true if the requested priority is enabled. | |
pid_t | getpid (void) const |
const ACE_TCHAR * | local_host (void) const |
Get the name of the local host. | |
void | local_host (const ACE_TCHAR *) |
Set the name of the local host. | |
void | set (const char *file, int line, int op_status=-1, int errnum=0, bool restart=true, ACE_OSTREAM_TYPE *os=0, ACE_Log_Msg_Callback *c=0) |
void | conditional_set (const char *file, int line, int op_status, int errnum) |
ssize_t | log (ACE_Log_Priority priority, const ACE_TCHAR *format,...) |
ssize_t | log (ACE_Log_Priority priority, const ACE_ANTI_TCHAR *format,...) |
ssize_t | log (const ACE_Log_Formatter &formatter) |
ssize_t | log (const ACE_TCHAR *format, ACE_Log_Priority priority, va_list argp, ACE_Log_Category_TSS *category=0) |
ssize_t | log (ACE_Log_Record &log_record, int suppress_stderr=0) |
int | log_hexdump (ACE_Log_Priority log_priority, const char *buffer, size_t size, const ACE_TCHAR *text=0, ACE_Log_Category_TSS *category=0) |
void | dump (void) const |
Dump the state of an object. | |
Allow apps to acquire and release internal synchronization | |
This lock is used internally by the ACE_Log_Msg implementation. By exporting the lock, applications can hold the lock atomically over a number of calls to ACE_Log_Msg. | |
int | acquire (void) |
Acquire the internal lock. | |
int | release (void) |
Release the internal lock. | |
Static Public Member Functions | |
static ACE_Log_Msg * | instance (void) |
Returns a pointer to the Singleton. | |
static int | last_error_adapter (void) |
Returns last error. | |
static int | exists (void) |
Returns non-null if an ACE_Log_Msg exists for the calling thread. | |
static const ACE_TCHAR * | program_name (void) |
Returns the current program name used for logging. | |
static void | disable_debug_messages (ACE_Log_Priority priority=LM_DEBUG) |
static void | enable_debug_messages (ACE_Log_Priority priority=LM_DEBUG) |
static ACE_Log_Msg_Backend * | msg_backend (ACE_Log_Msg_Backend *b) |
static ACE_Log_Msg_Backend * | msg_backend (void) |
static void | init_hook (ACE_OS_Log_Msg_Attributes &attributes#if defined(ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS), ACE_SEH_EXCEPT_HANDLER selector=0, ACE_SEH_EXCEPT_HANDLER handler=0#endif) |
static void | inherit_hook (ACE_OS_Thread_Descriptor *thr_desc, ACE_OS_Log_Msg_Attributes &attributes) |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
bool | is_set_ |
const char * | file_ |
int | line_ |
int | op_status_ |
Private Types | |
typedef ACE_Atomic_Op < ACE_SYNCH_MUTEX, unsigned long > | Atomic_ULong |
Private Member Functions | |
void | cleanup_ostream () |
ACE_Log_Msg & | operator= (const ACE_Log_Msg &) |
ACE_Log_Msg (const ACE_Log_Msg &) | |
Static Private Member Functions | |
static void | close (void) |
For cleanup, at program termination. | |
static void | sync_hook (const ACE_TCHAR *prg_name) |
Decouple the OS layer from the ACE_Log_Msg layer. | |
static ACE_OS_Thread_Descriptor * | thr_desc_hook (void) |
Return the TSS singleton thread descriptor. | |
Private Attributes | |
int | status_ |
Status of operation (-1 means failure, >= 0 means success). | |
int | errnum_ |
Type of error that occurred (see <sys/errno.h>). | |
int | linenum_ |
Line number where the error occurred. | |
char | file_ [MAXPATHLEN+1] |
File where the error occurred. | |
ACE_TCHAR * | msg_ |
bool | restart_ |
ACE_OSTREAM_TYPE * | ostream_ |
The ostream where logging messages can be written. | |
Atomic_ULong * | ostream_refcount_ |
ACE_Log_Msg_Callback * | msg_callback_ |
The callback object. | |
int | trace_depth_ |
Depth of the nesting for printing traces. | |
bool | trace_active_ |
Are we already within an ACE_Trace constructor call? | |
bool | tracing_enabled_ |
Are we allowing tracing in this thread? | |
ACE_Thread_Descriptor * | thr_desc_ |
u_long | priority_mask_ |
int | timestamp_ |
Always timestamp? | |
struct { | |
bool is_set_ | |
const char * file_ | |
int line_ | |
int op_status_ | |
int errnum_ | |
} | conditional_values_ |
Static Private Attributes | |
static u_long | process_priority_mask_ |
static const ACE_TCHAR * | program_name_ = 0 |
Records the program name. | |
static const ACE_TCHAR * | local_host_ = 0 |
Name of the local host (used when printing messages). | |
static u_long | flags_ = ACE_Log_Msg::STDERR |
Default is to use stderr. | |
static ptrdiff_t | msg_off_ = 0 |
Offset of msg_[]. | |
static int | instance_count_ = 0 |
static u_long | default_priority_mask_ = 0 |
static bool | key_created_ |
Friends | |
class | ACE_Log_Formatter |
Provides a variable length argument message logging abstraction.
This class is very flexible since it allows formatted error messages to be printed in a thread-safe manner to various locations, such as stderr, cerr, a distributed logger, etc. The current message is also kept in a thread-specific storage location (threads spawned using ACE_Thread_Manager automatically get an ACE_Log_Msg object that inherits the spawning thread's settings), which can be used to communicate errors between framework methods and callers. A message is logged by the log() method, only if the message priority is currently enabled. Moreover, only the current log message is stored here -- it will be overwritten by the subsequent call to log().
The ACE_Log_Msg class uses two priority masks to control its logging behavior. The priority_mask_
object attribute is thread- specific and specifies the priority levels logged by the thread. The process_priority_mask_
class attribute is not thread-specific and specifies the priority levels that will be logged by all threads in the process. By default, all levels are disabled for priority_mask_
and all levels are enabled for process_priority_mask_
(i.e. the process-wide mask controls the settings, and each instance can expand on it if desired). Both priority masks can be modified using the priority_mask() method of this class.
Definition at line 210 of file Log_Msg.h.
typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, unsigned long> ACE_Log_Msg::Atomic_ULong [private] |
This pointer is 0 if we are not reference counting (the user has not passed "true" for the delete_ostream argument to msg_ostream). If we are reference counting, this points to a shared count that will be deleted when it reaches zero. Since we want optional but shared ownership neither std::auto_ptr nor ACE_Strong_Bound_Ptr have the right semantics. *Bound_Ptr also doesn't take advantage of Atomic_Op.
anonymous enum |
Definition at line 214 of file Log_Msg.h.
00215 { 00216 /// Write messages to stderr. 00217 STDERR = 1, 00218 /// Write messages to the local client logger daemon. 00219 LOGGER = 2, 00220 /// Write messages to the ostream * stored in thread-specific 00221 /// storage. 00222 OSTREAM = 4, 00223 /// Write messages to the callback object. 00224 MSG_CALLBACK = 8, 00225 /// Display messages in a verbose manner. 00226 VERBOSE = 16, 00227 /// Display messages in a less verbose manner (i.e., only print 00228 /// information that can change between calls). 00229 VERBOSE_LITE = 32, 00230 /// Do not print messages at all (just leave in thread-specific 00231 /// storage for later inspection). 00232 SILENT = 64, 00233 /// Write messages to the system's event log. 00234 SYSLOG = 128, 00235 /// Write messages to the user provided backend 00236 CUSTOM = 256 00237 };
ACE_Log_Msg::ACE_Log_Msg | ( | void | ) |
Initialize logger.
Definition at line 638 of file Log_Msg.cpp.
00639 : status_ (0), 00640 errnum_ (0), 00641 linenum_ (0), 00642 msg_ (0), 00643 restart_ (1), // Restart by default... 00644 ostream_ (0), 00645 ostream_refcount_ (0), 00646 msg_callback_ (0), 00647 trace_depth_ (0), 00648 trace_active_ (false), 00649 tracing_enabled_ (true), // On by default? 00650 thr_desc_ (0), 00651 priority_mask_ (default_priority_mask_), 00652 timestamp_ (0) 00653 { 00654 // ACE_TRACE ("ACE_Log_Msg::ACE_Log_Msg"); 00655 00656 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, 00657 *ACE_Log_Msg_Manager::get_lock ())); 00658 ++instance_count_; 00659 00660 if (this->instance_count_ == 1) 00661 ACE_Base_Thread_Adapter::set_log_msg_hooks (ACE_Log_Msg::init_hook, 00662 ACE_Log_Msg::inherit_hook, 00663 ACE_Log_Msg::close, 00664 ACE_Log_Msg::sync_hook, 00665 ACE_Log_Msg::thr_desc_hook); 00666 00667 this->conditional_values_.is_set_ = false; 00668 00669 char *timestamp = ACE_OS::getenv ("ACE_LOG_TIMESTAMP"); 00670 if (timestamp != 0) 00671 { 00672 // If variable is set or is set to date tag so we print date and time. 00673 if (ACE_OS::strcmp (timestamp, "TIME") == 0) 00674 { 00675 this->timestamp_ = 1; 00676 } 00677 else if (ACE_OS::strcmp (timestamp, "DATE") == 0) 00678 { 00679 this->timestamp_ = 2; 00680 } 00681 } 00682 00683 #if defined (ACE_HAS_ALLOC_HOOKS) 00684 ACE_ALLOCATOR_NORETURN (this->msg_, static_cast<ACE_TCHAR *>(ACE_Allocator::instance()->malloc(sizeof(ACE_TCHAR) * (ACE_MAXLOGMSGLEN+1)))); 00685 #else 00686 ACE_NEW_NORETURN (this->msg_, ACE_TCHAR[ACE_MAXLOGMSGLEN+1]); 00687 #endif /* ACE_HAS_ALLOC_HOOKS */ 00688 }
ACE_Log_Msg::~ACE_Log_Msg | ( | void | ) |
cleanup logger.
Definition at line 690 of file Log_Msg.cpp.
00691 { 00692 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00693 00694 int instance_count = 0; 00695 00696 // Only hold the guard while updating the instance_count_. 00697 // If ACE_Log_Msg_Manager::close () is called, the lock will 00698 // be deleted. 00699 { 00700 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, 00701 *ACE_Log_Msg_Manager::get_lock ())); 00702 instance_count = --instance_count_; 00703 } 00704 // Release the guard. 00705 00706 #else /* ! ACE_MT_SAFE */ 00707 int instance_count = --instance_count_; 00708 #endif /* ! ACE_MT_SAFE */ 00709 00710 // If this is the last instance then cleanup. Only the last 00711 // thread to destroy its ACE_Log_Msg instance should execute 00712 // this block. 00713 if (instance_count == 0) 00714 { 00715 // Destroy the message queue instance. 00716 if (ACE_Log_Msg_Manager::log_backend_ != 0) 00717 ACE_Log_Msg_Manager::log_backend_->close (); 00718 00719 // Close down custom backend 00720 if (ACE_Log_Msg_Manager::custom_backend_ != 0) 00721 ACE_Log_Msg_Manager::custom_backend_->close (); 00722 00723 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00724 # if defined (ACE_HAS_TSS_EMULATION) 00725 ACE_Log_Msg_Manager::close (); 00726 # endif /* ACE_HAS_TSS_EMULATION */ 00727 # endif /* ACE_MT_SAFE */ 00728 00729 if (ACE_Log_Msg::program_name_) 00730 { 00731 #if defined (ACE_HAS_ALLOC_HOOKS) 00732 ACE_Allocator::instance()->free ((void *) ACE_Log_Msg::program_name_); 00733 #else 00734 ACE_OS::free ((void *) ACE_Log_Msg::program_name_); 00735 #endif /* ACE_HAS_ALLOC_HOOKS */ 00736 ACE_Log_Msg::program_name_ = 0; 00737 } 00738 00739 if (ACE_Log_Msg::local_host_) 00740 { 00741 #if defined (ACE_HAS_ALLOC_HOOKS) 00742 ACE_Allocator::instance()->free ((void *) ACE_Log_Msg::local_host_); 00743 #else 00744 ACE_OS::free ((void *) ACE_Log_Msg::local_host_); 00745 #endif /* ACE_HAS_ALLOC_HOOKS */ 00746 ACE_Log_Msg::local_host_ = 0; 00747 } 00748 } 00749 00750 this->cleanup_ostream (); 00751 00752 #if defined (ACE_HAS_ALLOC_HOOKS) 00753 ACE_Allocator::instance()->free(this->msg_); 00754 #else 00755 delete[] this->msg_; 00756 #endif /* ACE_HAS_ALLOC_HOOKS */ 00757 }
ACE_Log_Msg::ACE_Log_Msg | ( | const ACE_Log_Msg & | ) | [private] |
int ACE_Log_Msg::acquire | ( | void | ) |
Acquire the internal lock.
Definition at line 597 of file Log_Msg.cpp.
void ACE_Log_Msg::cleanup_ostream | ( | ) | [private] |
Definition at line 760 of file Log_Msg.cpp.
00761 { 00762 if (this->ostream_refcount_) 00763 { 00764 if (--*this->ostream_refcount_ == 0) 00765 { 00766 #if defined (ACE_HAS_ALLOC_HOOKS) 00767 this->ostream_refcount_->~Atomic_ULong(); 00768 ACE_Allocator::instance()->free(this->ostream_refcount_); 00769 #else 00770 delete this->ostream_refcount_; 00771 #endif /* ACE_HAS_ALLOC_HOOKS */ 00772 #if defined (ACE_LACKS_IOSTREAM_TOTALLY) 00773 ACE_OS::fclose (this->ostream_); 00774 #else 00775 delete this->ostream_; 00776 this->ostream_ = 0; 00777 #endif 00778 } 00779 this->ostream_refcount_ = 0; 00780 } 00781 }
void ACE_Log_Msg::close | ( | void | ) | [static, private] |
For cleanup, at program termination.
Definition at line 465 of file Log_Msg.cpp.
00466 { 00467 // This call needs to go here to avoid memory leaks. 00468 ACE_MT (ACE_Log_Msg_Manager::close ()); 00469 00470 // Please note that this will be called by a statement that is 00471 // harded coded into the ACE_Object_Manager's shutdown sequence, in 00472 // its destructor. 00473 00474 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) && \ 00475 (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || \ 00476 defined (ACE_HAS_TSS_EMULATION)) 00477 00478 if (ACE_Log_Msg::key_created_) 00479 { 00480 ACE_thread_mutex_t *lock = 00481 reinterpret_cast<ACE_thread_mutex_t *> 00482 (ACE_OS_Object_Manager::preallocated_object 00483 [ACE_OS_Object_Manager::ACE_LOG_MSG_INSTANCE_LOCK]); 00484 if (lock) 00485 ACE_OS::thread_mutex_lock (lock); 00486 00487 if (ACE_Log_Msg::key_created_) 00488 { 00489 // Clean up this ACE_Log_Msg instance and reset the TSS to 00490 // prevent any future cleanup attempts via TSS mechanisms at 00491 // thread exit. Otherwise in the event of a dynamic library 00492 // unload of libACE, by a program not linked with libACE, 00493 // ACE_TSS_cleanup will be invoked after libACE has been unloaded. 00494 // See Bugzilla 2980 for lots of details. 00495 ACE_Log_Msg *tss_log_msg = 0; 00496 void *temp = 0; 00497 00498 // Get the tss_log_msg from thread-specific storage. 00499 if (ACE_Thread::getspecific (*(log_msg_tss_key ()), &temp) != -1 00500 && temp) 00501 { 00502 tss_log_msg = static_cast <ACE_Log_Msg *> (temp); 00503 // we haven't been cleaned up 00504 ACE_TSS_CLEANUP_NAME(tss_log_msg); 00505 if (ACE_Thread::setspecific(*(log_msg_tss_key()), 00506 reinterpret_cast <void *>(0)) != 0) 00507 ACE_OS::printf ("ACE_Log_Msg::close failed to ACE_Thread::setspecific to 0\n"); 00508 } 00509 00510 // The key is not needed any longer; ACE_Log_Msg is closing 00511 // and will need to be reopened if this process wishes to use 00512 // logging again. So delete the key. 00513 ACE_Thread::keyfree (*(log_msg_tss_key())); 00514 ACE_Log_Msg::key_created_ = false; 00515 } 00516 00517 if (lock) 00518 ACE_OS::thread_mutex_unlock (lock); 00519 } 00520 #endif /* (ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION) && ACE_MT_SAFE */ 00521 }
void ACE_Log_Msg::clr_flags | ( | u_long | f | ) |
Disable the bits in the logger's options flags.
Definition at line 587 of file Log_Msg.cpp.
00588 { 00589 ACE_TRACE ("ACE_Log_Msg::clr_flags"); 00590 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, 00591 *ACE_Log_Msg_Manager::get_lock ())); 00592 00593 ACE_CLR_BITS (ACE_Log_Msg::flags_, flgs); 00594 }
void ACE_Log_Msg::conditional_set | ( | const char * | file, | |
int | line, | |||
int | op_status, | |||
int | errnum | |||
) |
These values are only actually set if the requested priority is enabled.
Definition at line 3053 of file Log_Msg.cpp.
03057 { 03058 this->conditional_values_.is_set_ = true; 03059 this->conditional_values_.file_ = filename; 03060 this->conditional_values_.line_ = line; 03061 this->conditional_values_.op_status_ = status; 03062 this->conditional_values_.errnum_ = err; 03063 }
int ACE_Log_Msg::dec | ( | void | ) | [inline] |
Nesting depth decrement.
Definition at line 90 of file Log_Msg.inl.
00091 { 00092 return this->trace_depth_ == 0 ? 0 : --this->trace_depth_; 00093 }
void ACE_Log_Msg::disable_debug_messages | ( | ACE_Log_Priority | priority = LM_DEBUG |
) | [static] |
Clears the flag from the default priority mask used to initialize ACE_Log_Msg instances.
Definition at line 421 of file Log_Msg.cpp.
00422 { 00423 ACE_CLR_BITS (ACE_Log_Msg::default_priority_mask_, priority); 00424 ACE_Log_Msg *i = ACE_Log_Msg::instance (); 00425 i->priority_mask (i->priority_mask () & ~priority); 00426 }
void ACE_Log_Msg::dump | ( | void | ) | const |
Dump the state of an object.
Definition at line 3066 of file Log_Msg.cpp.
03067 { 03068 #if defined (ACE_HAS_DUMP) 03069 ACE_TRACE ("ACE_Log_Msg::dump"); 03070 03071 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 03072 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("status_ = %d\n"), this->status_)); 03073 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nerrnum_ = %d\n"), this->errnum_)); 03074 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nlinenum_ = %d\n"), this->linenum_)); 03075 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nfile_ = %C\n"), this->file_)); 03076 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmsg_ = %s\n"), this->msg_)); 03077 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nrestart_ = %d\n"), this->restart_)); 03078 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nostream_ = %@\n"), this->ostream_)); 03079 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmsg_callback_ = %@\n"), 03080 this->msg_callback_)); 03081 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nprogram_name_ = %s\n"), 03082 this->program_name_ ? this->program_name_ 03083 : ACE_TEXT ("<unknown>"))); 03084 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nlocal_host_ = %s\n"), 03085 this->local_host_ ? this->local_host_ 03086 : ACE_TEXT ("<unknown>"))); 03087 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nflags_ = 0x%x\n"), this->flags_)); 03088 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntrace_depth_ = %d\n"), 03089 this->trace_depth_)); 03090 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntrace_active_ = %d\n"), 03091 this->trace_active_)); 03092 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntracing_enabled_ = %d\n"), 03093 this->tracing_enabled_)); 03094 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\npriority_mask_ = 0x%x\n"), 03095 this->priority_mask_)); 03096 if (this->thr_desc_ != 0 && this->thr_desc_->state () != 0) 03097 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nthr_state_ = %d\n"), 03098 this->thr_desc_->state ())); 03099 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmsg_off_ = %d\n"), this->msg_off_)); 03100 03101 // Be sure that there is a message_queue_, with multiple threads. 03102 ACE_MT (ACE_Log_Msg_Manager::init_backend ()); 03103 03104 ACE_MT (ACE_Log_Msg_Manager::get_lock ()->dump ()); 03105 // Synchronize output operations. 03106 03107 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 03108 #endif /* ACE_HAS_DUMP */ 03109 }
void ACE_Log_Msg::enable_debug_messages | ( | ACE_Log_Priority | priority = LM_DEBUG |
) | [static] |
Sets the flag in the default priority mask used to initialize ACE_Log_Msg instances.
Definition at line 410 of file Log_Msg.cpp.
00411 { 00412 ACE_SET_BITS (ACE_Log_Msg::default_priority_mask_, priority); 00413 ACE_Log_Msg *i = ACE_Log_Msg::instance (); 00414 i->priority_mask (i->priority_mask () | priority); 00415 }
int ACE_Log_Msg::errnum | ( | void | ) | const [inline] |
Get the value of the errnum (by convention this corresponds to errno).
Definition at line 55 of file Log_Msg.inl.
00056 { 00057 return this->errnum_; 00058 }
void ACE_Log_Msg::errnum | ( | int | e | ) | [inline] |
Set the value of the errnum (by convention this corresponds to errno).
Definition at line 62 of file Log_Msg.inl.
00063 { 00064 this->errnum_ = e; 00065 }
int ACE_Log_Msg::exists | ( | void | ) | [static] |
Returns non-null if an ACE_Log_Msg exists for the calling thread.
Definition at line 261 of file Log_Msg.cpp.
00262 { 00263 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00264 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || \ 00265 defined (ACE_HAS_TSS_EMULATION) 00266 void *tss_log_msg = 0; // The actual type is ACE_Log_Msg*, but we need this 00267 // void to keep G++ from complaining. 00268 00269 // Get the tss_log_msg from thread-specific storage. 00270 return ACE_Log_Msg::key_created_ 00271 && ACE_Thread::getspecific (*(log_msg_tss_key ()), &tss_log_msg) != -1 00272 && tss_log_msg != 0; 00273 # else 00274 # error "Platform must support thread-specific storage if threads are used." 00275 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION */ 00276 #else /* ! ACE_MT_SAFE */ 00277 return 1; 00278 #endif /* ! ACE_MT_SAFE */ 00279 }
const char * ACE_Log_Msg::file | ( | void | ) | [inline] |
Get the file name where an error occurred.
Definition at line 155 of file Log_Msg.inl.
00156 { 00157 return this->file_; 00158 }
void ACE_Log_Msg::file | ( | const char * | s | ) | [inline] |
Set the file name where an error occurred.
Definition at line 162 of file Log_Msg.inl.
00163 { 00164 ACE_OS::strsncpy (this->file_, s, sizeof this->file_); 00165 }
u_long ACE_Log_Msg::flags | ( | void | ) |
Return the bits in the logger's options flags.
Definition at line 565 of file Log_Msg.cpp.
00566 { 00567 ACE_TRACE ("ACE_Log_Msg::flags"); 00568 u_long result; 00569 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 00570 *ACE_Log_Msg_Manager::get_lock (), 0)); 00571 00572 result = ACE_Log_Msg::flags_; 00573 return result; 00574 }
pid_t ACE_Log_Msg::getpid | ( | void | ) | const [inline] |
Optimize reading of the pid (avoids a system call if the value is cached...).
Definition at line 221 of file Log_Msg.inl.
00222 { 00223 return ACE_OS::getpid (); 00224 }
int ACE_Log_Msg::inc | ( | void | ) | [inline] |
Nesting depth increment.
Definition at line 83 of file Log_Msg.inl.
00084 { 00085 return this->trace_depth_++; 00086 }
void ACE_Log_Msg::inherit_hook | ( | ACE_OS_Thread_Descriptor * | thr_desc, | |
ACE_OS_Log_Msg_Attributes & | attributes | |||
) | [static] |
Inherit hook, the attributes field is a ACE_OS_Log_Msg_Attributes object, invoke the inherit_log_msg() method on it, then destroy it and set the attribute argument to 0.
Definition at line 3262 of file Log_Msg.cpp.
03264 { 03265 #if !defined (ACE_THREADS_DONT_INHERIT_LOG_MSG) && \ 03266 !defined (ACE_HAS_MINIMAL_ACE_OS) 03267 // Inherit the logging features if the parent thread has an 03268 // <ACE_Log_Msg>. Note that all of the following operations occur 03269 // within thread-specific storage. 03270 ACE_Log_Msg *new_log = ACE_LOG_MSG; 03271 03272 // Note that we do not inherit the callback because this might have 03273 // been allocated off of the stack of the original thread, in which 03274 // case all hell would break loose... 03275 03276 if (attributes.ostream_) 03277 { 03278 new_log->ostream_ = attributes.ostream_; 03279 new_log->ostream_refcount_ = 03280 static_cast<Atomic_ULong *> (attributes.ostream_refcount_); 03281 03282 new_log->priority_mask (attributes.priority_mask_); 03283 03284 if (attributes.tracing_enabled_) 03285 new_log->start_tracing (); 03286 03287 new_log->restart (attributes.restart_); 03288 new_log->trace_depth (attributes.trace_depth_); 03289 } 03290 03291 // @@ Now the TSS Log_Msg has been created, cache my thread 03292 // descriptor in. 03293 03294 if (thr_desc != 0) 03295 // This downcast is safe. We do it to avoid having to #include 03296 // ace/Thread_Manager.h. 03297 new_log->thr_desc (static_cast<ACE_Thread_Descriptor *> (thr_desc)); 03298 // Block the thread from proceeding until 03299 // thread manager has thread descriptor ready. 03300 #endif /* ! ACE_THREADS_DONT_INHERIT_LOG_MSG && ! ACE_HAS_MINIMAL_ACE_OS */ 03301 }
static void ACE_Log_Msg::init_hook | ( | ACE_OS_Log_Msg_Attributes &attributes#if | definedACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS, | |
ACE_SEH_EXCEPT_HANDLER | selector = 0 , |
|||
ACE_SEH_EXCEPT_HANDLER | handler = 0#endif | |||
) | [static] |
Init hook, create a Log_Msg_Attribute object, initialize its attributes from the TSS Log_Msg and save the object in the attributes argument
ACE_Log_Msg * ACE_Log_Msg::instance | ( | void | ) | [static] |
Returns a pointer to the Singleton.
Definition at line 282 of file Log_Msg.cpp.
00283 { 00284 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00285 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || \ 00286 defined (ACE_HAS_TSS_EMULATION) 00287 // TSS Singleton implementation. 00288 00289 if (!ACE_Log_Msg::key_created_) 00290 { 00291 ACE_thread_mutex_t *lock = 00292 reinterpret_cast<ACE_thread_mutex_t *> ( 00293 ACE_OS_Object_Manager::preallocated_object 00294 [ACE_OS_Object_Manager::ACE_LOG_MSG_INSTANCE_LOCK]); 00295 00296 if (1 == ACE_OS_Object_Manager::starting_up()) 00297 //This function is called before ACE_OS_Object_Manager is 00298 //initialized. So the lock might not be valid. Assume it's 00299 //single threaded and so don't need the lock. 00300 ; 00301 else 00302 ACE_OS::thread_mutex_lock (lock); 00303 00304 if (!ACE_Log_Msg::key_created_) 00305 { 00306 // Allocate the Singleton lock. 00307 ACE_Log_Msg_Manager::get_lock (); 00308 00309 { 00310 ACE_NO_HEAP_CHECK; 00311 if (ACE_Thread::keycreate (log_msg_tss_key (), 00312 &ACE_TSS_CLEANUP_NAME) != 0) 00313 { 00314 if (1 == ACE_OS_Object_Manager::starting_up()) 00315 //This function is called before ACE_OS_Object_Manager is 00316 //initialized. So the lock might not be valid. Assume it's 00317 //single threaded and so don't need the lock. 00318 ; 00319 else 00320 ACE_OS::thread_mutex_unlock (lock); 00321 return 0; // Major problems, this should *never* happen! 00322 } 00323 } 00324 00325 ACE_Log_Msg::key_created_ = true; 00326 } 00327 00328 if (1 == ACE_OS_Object_Manager::starting_up()) 00329 //This function is called before ACE_OS_Object_Manager is 00330 //initialized. So the lock might not be valid. Assume it's 00331 //single threaded and so don't need the lock. 00332 ; 00333 else 00334 ACE_OS::thread_mutex_unlock (lock); 00335 } 00336 00337 ACE_Log_Msg *tss_log_msg = 0; 00338 void *temp = 0; 00339 00340 // Get the tss_log_msg from thread-specific storage. 00341 if (ACE_Thread::getspecific (*(log_msg_tss_key ()), &temp) == -1) 00342 return 0; // This should not happen! 00343 00344 tss_log_msg = static_cast <ACE_Log_Msg *> (temp); 00345 00346 // Check to see if this is the first time in for this thread. 00347 if (tss_log_msg == 0) 00348 { 00349 // Allocate memory off the heap and store it in a pointer in 00350 // thread-specific storage (on the stack...). Stop heap 00351 // checking, the memory will always be freed by the thread 00352 // rundown because of the TSS callback set up when the key was 00353 // created. This prevents from getting these blocks reported as 00354 // memory leaks. 00355 { 00356 ACE_NO_HEAP_CHECK; 00357 00358 ACE_NEW_RETURN (tss_log_msg, 00359 ACE_Log_Msg, 00360 0); 00361 // Store the dynamically allocated pointer in thread-specific 00362 // storage. It gets deleted via the ACE_TSS_cleanup function 00363 // when the thread terminates. 00364 00365 if (ACE_Thread::setspecific (*(log_msg_tss_key()), 00366 reinterpret_cast<void *> (tss_log_msg)) 00367 != 0) 00368 return 0; // Major problems, this should *never* happen! 00369 } 00370 } 00371 00372 return tss_log_msg; 00373 # else 00374 # error "Platform must support thread-specific storage if threads are used." 00375 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION */ 00376 #else /* ! ACE_MT_SAFE */ 00377 // We don't have threads, we cannot call 00378 // ACE_Log_Msg_Manager::get_lock () to initialize the logger 00379 // callback, so instead we do it here. 00380 if (ACE_Log_Msg_Manager::init_backend () == -1) 00381 return 0; 00382 00383 // Singleton implementation. 00384 00385 if (log_msg_cleanup == 0) 00386 { 00387 ACE_NEW_RETURN (log_msg_cleanup, ACE_Msg_Log_Cleanup, 0); 00388 // Register the instance for destruction at program termination. 00389 ACE_Object_Manager::at_exit (log_msg_cleanup, 00390 0, 00391 typeid (*log_msg_cleanup).name ()); 00392 } 00393 00394 return &log_msg_cleanup->object (); 00395 #endif /* ! ACE_MT_SAFE */ 00396 }
int ACE_Log_Msg::last_error_adapter | ( | void | ) | [static] |
Returns last error.
Definition at line 401 of file Log_Msg.cpp.
00402 { 00403 return ACE_OS::last_error (); 00404 }
int ACE_Log_Msg::linenum | ( | void | ) | const [inline] |
Get the line number where an error occurred.
Definition at line 69 of file Log_Msg.inl.
00070 { 00071 return this->linenum_; 00072 }
void ACE_Log_Msg::linenum | ( | int | l | ) | [inline] |
Set the line number where an error occurred.
Definition at line 76 of file Log_Msg.inl.
00077 { 00078 this->linenum_ = l; 00079 }
void ACE_Log_Msg::local_host | ( | const ACE_TCHAR * | s | ) |
Set the name of the local host.
Definition at line 3189 of file Log_Msg.cpp.
03190 { 03191 if (s) 03192 { 03193 #if defined (ACE_HAS_ALLOC_HOOKS) 03194 ACE_Allocator::instance()->free ((void *) ACE_Log_Msg::local_host_); 03195 #else 03196 ACE_OS::free ((void *) ACE_Log_Msg::local_host_); 03197 #endif /* ACE_HAS_ALLOC_HOOKS */ 03198 { 03199 ACE_NO_HEAP_CHECK; 03200 03201 ACE_ALLOCATOR (ACE_Log_Msg::local_host_, ACE_OS::strdup (s)); 03202 } 03203 } 03204 }
const ACE_TCHAR * ACE_Log_Msg::local_host | ( | void | ) | const [inline] |
Get the name of the local host.
Definition at line 214 of file Log_Msg.inl.
00215 { 00216 return ACE_Log_Msg::local_host_; 00217 }
ssize_t ACE_Log_Msg::log | ( | ACE_Log_Record & | log_record, | |
int | suppress_stderr = 0 | |||
) |
Log a custom built log record to the currently enabled logging sinks.
Definition at line 2865 of file Log_Msg.cpp.
02867 { 02868 ssize_t result = 0; 02869 02870 // Retrieve the flags in a local variable on the stack, it is 02871 // accessed by multiple threads and within this operation we 02872 // check it several times, so this way we only lock once 02873 u_long flags = this->flags (); 02874 02875 // Format the message and print it to stderr and/or ship it off to 02876 // the log_client daemon, and/or print it to the ostream. Of 02877 // course, only print the message if "SILENT" mode is disabled. 02878 if (ACE_BIT_DISABLED (flags, ACE_Log_Msg::SILENT)) 02879 { 02880 bool tracing = this->tracing_enabled (); 02881 this->stop_tracing (); 02882 02883 #if !defined (ACE_WIN32) 02884 // Make this block signal-safe. 02885 ACE_Log_Msg_Sig_Guard sb; 02886 #endif /* !ACE_WIN32 */ 02887 02888 // Do the callback, if needed, before acquiring the lock 02889 // to avoid holding the lock during the callback so we don't 02890 // have deadlock if the callback uses the logger. 02891 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::MSG_CALLBACK) 02892 && this->msg_callback () != 0) 02893 { 02894 this->msg_callback ()->log (log_record); 02895 } 02896 02897 // Make sure that the lock is held during all this. 02898 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 02899 *ACE_Log_Msg_Manager::get_lock (), 02900 -1)); 02901 02902 #if !defined ACE_LACKS_STDERR || defined ACE_FACE_DEV 02903 if (ACE_BIT_ENABLED (flags, 02904 ACE_Log_Msg::STDERR) 02905 && !suppress_stderr) // This is taken care of by our caller. 02906 log_record.print (ACE_Log_Msg::local_host_, 02907 flags, 02908 stderr); 02909 #else 02910 ACE_UNUSED_ARG (suppress_stderr); 02911 #endif 02912 02913 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::CUSTOM) || 02914 ACE_BIT_ENABLED (flags, ACE_Log_Msg::SYSLOG) || 02915 ACE_BIT_ENABLED (flags, ACE_Log_Msg::LOGGER)) 02916 { 02917 // Be sure that there is a message_queue_, with multiple threads. 02918 ACE_MT (ACE_Log_Msg_Manager::init_backend ()); 02919 } 02920 02921 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::LOGGER) || 02922 ACE_BIT_ENABLED (flags, ACE_Log_Msg::SYSLOG)) 02923 { 02924 result = 02925 ACE_Log_Msg_Manager::log_backend_->log (log_record); 02926 } 02927 02928 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::CUSTOM) && 02929 ACE_Log_Msg_Manager::custom_backend_ != 0) 02930 { 02931 result = 02932 ACE_Log_Msg_Manager::custom_backend_->log (log_record); 02933 } 02934 02935 // This must come last, after the other two print operations 02936 // (see the <ACE_Log_Record::print> method for details). 02937 if (ACE_BIT_ENABLED (flags, 02938 ACE_Log_Msg::OSTREAM) 02939 && this->msg_ostream () != 0) 02940 log_record.print (ACE_Log_Msg::local_host_, 02941 flags, 02942 #if defined (ACE_LACKS_IOSTREAM_TOTALLY) 02943 static_cast<FILE *> (this->msg_ostream ()) 02944 #else /* ! ACE_LACKS_IOSTREAM_TOTALLY */ 02945 *this->msg_ostream () 02946 #endif /* ! ACE_LACKS_IOSTREAM_TOTALLY */ 02947 ); 02948 02949 if (tracing) 02950 this->start_tracing (); 02951 } 02952 02953 return result; 02954 }
ssize_t ACE_Log_Msg::log | ( | const ACE_TCHAR * | format, | |
ACE_Log_Priority | priority, | |||
va_list | argp, | |||
ACE_Log_Category_TSS * | category = 0 | |||
) |
An alternative logging mechanism that makes it possible to integrate variable argument lists from other logging mechanisms into the ACE mechanism.
Definition at line 1006 of file Log_Msg.cpp.
01010 { 01011 ACE_TRACE ("ACE_Log_Msg::log"); 01012 #if defined (ACE_LACKS_VA_FUNCTIONS) 01013 ACE_UNUSED_ARG (log_priority); 01014 ACE_UNUSED_ARG (format_str); 01015 ACE_UNUSED_ARG (argp); 01016 ACE_UNUSED_ARG (category); 01017 ACE_NOTSUP_RETURN (-1); 01018 #else 01019 // External decls. 01020 01021 typedef void (*PTF)(...); 01022 01023 // Check if there were any conditional values set. 01024 bool const conditional_values = this->conditional_values_.is_set_; 01025 01026 // Reset conditional values. 01027 this->conditional_values_.is_set_ = false; 01028 01029 // Only print the message if <priority_mask_> hasn't been reset to 01030 // exclude this logging priority. 01031 if (this->log_priority_enabled (log_priority) == 0) 01032 return 0; 01033 01034 // If conditional values were set and the log priority is correct, 01035 // then the values are actually set. 01036 if (conditional_values) 01037 this->set (this->conditional_values_.file_, 01038 this->conditional_values_.line_, 01039 this->conditional_values_.op_status_, 01040 this->conditional_values_.errnum_, 01041 this->restart (), 01042 this->msg_ostream (), 01043 this->msg_callback ()); 01044 01045 // Logging is supposed to be a benign activity (i.e., not interfer 01046 // with normal application operations), so don't inadvertently smash 01047 // errno! 01048 ACE_Errno_Guard guard (errno); 01049 01050 ACE_Log_Record log_record (log_priority, 01051 ACE_OS::gettimeofday (), 01052 this->getpid ()); 01053 01054 log_record.category(category); 01055 01056 // bp is pointer to where to put next part of logged message. 01057 // bspace is the number of characters remaining in msg_. 01058 ACE_TCHAR *bp = const_cast<ACE_TCHAR *> (this->msg ()); 01059 size_t bspace = ACE_MAXLOGMSGLEN; // Leave room for Nul term. 01060 if (this->msg_off_ <= ACE_Log_Record::MAXLOGMSGLEN) 01061 bspace -= static_cast<size_t> (this->msg_off_); 01062 01063 // If this platform has snprintf() capability to prevent overrunning the 01064 // output buffer, use it. To avoid adding a maintenance-hassle compile- 01065 // time couple between here and OS.cpp, don't try to figure this out at 01066 // compile time. Instead, do a quick check now; if we get a -1 return, 01067 // the platform doesn't support the length-limiting capability. 01068 ACE_TCHAR test[2]; 01069 bool can_check = ACE_OS::snprintf (test, 1, ACE_TEXT ("x")) != -1; 01070 01071 bool abort_prog = false; 01072 int exit_value = 0; 01073 01074 // Retrieve the flags in a local variable on the stack, it is 01075 // accessed by multiple threads and within this operation we 01076 // check it several times, so this way we only lock once 01077 u_long flags = this->flags (); 01078 01079 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::VERBOSE)) 01080 { 01081 // Prepend the program name onto this message 01082 if (ACE_Log_Msg::program_name_ != 0) 01083 { 01084 for (const ACE_TCHAR *s = ACE_Log_Msg::program_name_; 01085 bspace > 1 && (*bp = *s) != '\0'; 01086 ++s, --bspace) 01087 bp++; 01088 01089 *bp++ = '|'; 01090 --bspace; 01091 } 01092 } 01093 01094 if (timestamp_ > 0) 01095 { 01096 ACE_TCHAR day_and_time[27]; 01097 const ACE_TCHAR *s = 0; 01098 if (timestamp_ == 1) 01099 { 01100 // Print just the time 01101 s = ACE::timestamp (day_and_time, 01102 sizeof (day_and_time) / sizeof (ACE_TCHAR), 01103 true); 01104 } 01105 else 01106 { 01107 // Print time and date 01108 ACE::timestamp (day_and_time, 01109 sizeof (day_and_time) / sizeof (ACE_TCHAR)); 01110 s = day_and_time; 01111 } 01112 01113 for (; bspace > 1 && (*bp = *s) != '\0'; ++s, --bspace) 01114 ++bp; 01115 01116 *bp++ = '|'; 01117 --bspace; 01118 } 01119 01120 while (*format_str != '\0' && bspace > 0) 01121 { 01122 // Copy input to output until we encounter a %, however a 01123 // % followed by another % is not a format specification. 01124 01125 if (*format_str != '%') 01126 { 01127 *bp++ = *format_str++; 01128 --bspace; 01129 } 01130 else if (format_str[1] == '%') // An "escaped" '%' (just print one '%'). 01131 { 01132 *bp++ = *format_str++; // Store first % 01133 ++format_str; // but skip second % 01134 --bspace; 01135 } 01136 else 01137 { 01138 // This is most likely a format specification that ends with 01139 // one of the valid options described previously. To enable full 01140 // use of all sprintf capabilities, save the format specifier 01141 // from the '%' up to the format letter in a new char array. 01142 // This allows the full sprintf capability for padding, field 01143 // widths, alignment, etc. Any width/precision requiring a 01144 // caller-supplied argument is extracted and placed as text 01145 // into the format array. Lastly, we convert the caller-supplied 01146 // format specifier from the ACE_Log_Msg-supported list to the 01147 // equivalent sprintf specifier, and run the new format spec 01148 // through sprintf, adding it to the bp string. 01149 01150 const ACE_TCHAR *abort_str = ACE_TEXT ("Aborting..."); 01151 const ACE_TCHAR *start_format = format_str; 01152 size_t fspace = 128; 01153 ACE_TCHAR format[128]; // Converted format string 01154 ACE_OS::memset (format, '\0', 128); // Set this string to known values. 01155 ACE_TCHAR *fp = 0; // Current format pointer 01156 int wp = 0; // Width/precision extracted from args 01157 bool done = false; 01158 bool skip_nul_locate = false; 01159 int this_len = 0; // How many chars s[n]printf wrote 01160 01161 #ifdef ACE_LOG_MSG_USE_STRERROR_R 01162 char strerror_buf[128]; // always narrow chars 01163 ACE_OS::strcpy (strerror_buf, "strerror_r failed"); 01164 #endif 01165 01166 fp = format; 01167 *fp++ = *format_str++; // Copy in the % 01168 --fspace; 01169 01170 // Initialization to satisfy VC6 01171 int tmp_indent = 0; 01172 // Work through the format string to copy in the format 01173 // from the caller. While it's going across, extract ints 01174 // for '*' width/precision values from the argument list. 01175 // When the real format specifier is located, change it to 01176 // one recognized by sprintf, if needed, and do the sprintf 01177 // call. 01178 01179 while (!done) 01180 { 01181 done = true; // Unless a conversion spec changes it 01182 01183 switch (*format_str) 01184 { 01185 // The initial set of cases are the conversion 01186 // specifiers. Copy them in to the format array. 01187 // Note we don't use 'l', a normal conversion spec, 01188 // as a conversion because it is a ACE_Log_Msg format 01189 // specifier. 01190 case '-': 01191 case '+': 01192 case '0': 01193 case ' ': 01194 case '#': 01195 case '1': 01196 case '2': 01197 case '3': 01198 case '4': 01199 case '5': 01200 case '6': 01201 case '7': 01202 case '8': 01203 case '9': 01204 case '.': 01205 case 'h': 01206 *fp++ = *format_str; 01207 --fspace; 01208 done = false; 01209 break; 01210 case 'L': 01211 *fp++ = 'l'; 01212 done = false; 01213 break; 01214 01215 case '*': 01216 wp = va_arg (argp, int); 01217 if (can_check) 01218 this_len = ACE_OS::snprintf (fp, fspace, 01219 ACE_TEXT ("%d"), wp); 01220 else 01221 this_len = ACE_OS::sprintf (fp, ACE_TEXT ("%d"), wp); 01222 ACE_UPDATE_COUNT (fspace, this_len); 01223 fp += ACE_OS::strlen (fp); 01224 done = false; 01225 break; 01226 01227 case 'A': // ACE_timer_t 01228 { 01229 ACE_OS::strcpy (fp, ACE_TEXT ("f")); 01230 --fspace; 01231 double const value = va_arg (argp, double); 01232 if (can_check) 01233 this_len = ACE_OS::snprintf (bp, bspace, format, value); 01234 else 01235 this_len = ACE_OS::sprintf (bp, format, value); 01236 ACE_UPDATE_COUNT (bspace, this_len); 01237 } 01238 break; 01239 01240 case 'a': // Abort program after handling all of format string. 01241 abort_prog = true; 01242 exit_value = va_arg (argp, int); 01243 ACE_OS::strsncpy (bp, abort_str, bspace); 01244 if (bspace > ACE_OS::strlen (abort_str)) 01245 bspace -= ACE_OS::strlen (abort_str); 01246 else 01247 bspace = 0; 01248 break; 01249 01250 case 'l': // Source file line number 01251 ACE_OS::strcpy (fp, ACE_TEXT ("d")); 01252 if (can_check) 01253 this_len = ACE_OS::snprintf (bp, 01254 bspace, 01255 format, 01256 this->linenum ()); 01257 else 01258 this_len = ACE_OS::sprintf (bp, format, this->linenum ()); 01259 ACE_UPDATE_COUNT (bspace, this_len); 01260 break; 01261 01262 case 'N': // Source file name 01263 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 01264 ACE_OS::strcpy (fp, ACE_TEXT ("ls")); 01265 #else 01266 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01267 #endif 01268 if (can_check) 01269 this_len = ACE_OS::snprintf (bp, bspace, format, 01270 this->file () ? 01271 ACE_TEXT_CHAR_TO_TCHAR (this->file ()) 01272 : ACE_TEXT ("<unknown file>")); 01273 else 01274 this_len = ACE_OS::sprintf (bp, format, 01275 this->file () ? 01276 ACE_TEXT_CHAR_TO_TCHAR (this->file ()) 01277 : ACE_TEXT ("<unknown file>")); 01278 ACE_UPDATE_COUNT (bspace, this_len); 01279 break; 01280 01281 case 'n': // Program name 01282 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 01283 ACE_OS::strcpy (fp, ACE_TEXT ("ls")); 01284 #else /* ACE_WIN32 && ACE_USES_WCHAR */ 01285 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01286 #endif 01287 if (can_check) 01288 this_len = ACE_OS::snprintf (bp, bspace, format, 01289 ACE_Log_Msg::program_name_ ? 01290 ACE_Log_Msg::program_name_ : 01291 ACE_TEXT ("<unknown>")); 01292 else 01293 this_len = ACE_OS::sprintf (bp, format, 01294 ACE_Log_Msg::program_name_ ? 01295 ACE_Log_Msg::program_name_ : 01296 ACE_TEXT ("<unknown>")); 01297 ACE_UPDATE_COUNT (bspace, this_len); 01298 break; 01299 01300 case 'P': // Process ID 01301 #if defined (ACE_OPENVMS) 01302 // Print the process id in hex on OpenVMS. 01303 ACE_OS::strcpy (fp, ACE_TEXT ("x")); 01304 #else 01305 ACE_OS::strcpy (fp, ACE_TEXT ("d")); 01306 #endif 01307 if (can_check) 01308 this_len = ACE_OS::snprintf 01309 (bp, bspace, format, 01310 static_cast<int> (this->getpid ())); 01311 else 01312 this_len = ACE_OS::sprintf 01313 (bp, format, static_cast<int> (this->getpid ())); 01314 ACE_UPDATE_COUNT (bspace, this_len); 01315 break; 01316 01317 case 'p': // <errno> string, ala perror() 01318 { 01319 errno = 0; 01320 const int mapped = ACE::map_errno (this->errnum ()); 01321 #ifdef ACE_LOG_MSG_USE_STRERROR_R 01322 char *msg = ACE_OS::strerror_r (mapped, strerror_buf, 01323 sizeof strerror_buf); 01324 #else 01325 char *msg = ACE_OS::strerror (mapped); 01326 #endif 01327 // Windows can try to translate the errnum using 01328 // system calls if strerror() doesn't get anything useful. 01329 #if defined (ACE_WIN32) 01330 if (errno == 0) 01331 { 01332 #endif 01333 01334 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 01335 ACE_OS::strcpy (fp, ACE_TEXT ("ls: %ls")); 01336 wchar_t *str = va_arg (argp, wchar_t *); 01337 #else 01338 ACE_OS::strcpy (fp, ACE_TEXT ("s: %s")); 01339 ACE_TCHAR *str = va_arg (argp, ACE_TCHAR *); 01340 #endif 01341 if (can_check) 01342 this_len = ACE_OS::snprintf 01343 (bp, bspace, format, 01344 str ? str : ACE_TEXT ("(null)"), 01345 ACE_TEXT_CHAR_TO_TCHAR (msg)); 01346 else 01347 this_len = ACE_OS::sprintf 01348 (bp, format, 01349 str ? str : ACE_TEXT ("(null)"), 01350 ACE_TEXT_CHAR_TO_TCHAR (msg)); 01351 #if defined (ACE_WIN32) 01352 } 01353 else 01354 { 01355 errno = ACE::map_errno (this->errnum ()); 01356 ACE_TCHAR *lpMsgBuf = 0; 01357 01358 // PharLap can't do FormatMessage, so try for socket 01359 // error. 01360 # if !defined (ACE_HAS_PHARLAP) 01361 ACE_TEXT_FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER 01362 | FORMAT_MESSAGE_MAX_WIDTH_MASK 01363 | FORMAT_MESSAGE_FROM_SYSTEM, 01364 0, 01365 errno, 01366 MAKELANGID (LANG_NEUTRAL, 01367 SUBLANG_DEFAULT), 01368 // Default language 01369 (ACE_TCHAR *) &lpMsgBuf, 01370 0, 01371 0); 01372 # endif /* ACE_HAS_PHARLAP */ 01373 01374 // If we don't get a valid response from 01375 // <FormatMessage>, we'll assume this is a 01376 // WinSock error and so we'll try to convert 01377 // it into a string. If this doesn't work it 01378 // returns "unknown error" which is fine for 01379 // our purposes. 01380 ACE_TCHAR *str = va_arg (argp, ACE_TCHAR *); 01381 if (lpMsgBuf == 0) 01382 { 01383 const ACE_TCHAR *message = 01384 ACE::sock_error (errno); 01385 ACE_OS::strcpy (fp, ACE_TEXT ("s: %s")); 01386 if (can_check) 01387 this_len = ACE_OS::snprintf 01388 (bp, bspace, format, 01389 str ? str : ACE_TEXT ("(null)"), 01390 message); 01391 else 01392 this_len = ACE_OS::sprintf 01393 (bp, format, 01394 str ? str : ACE_TEXT ("(null)"), 01395 message); 01396 } 01397 else 01398 { 01399 ACE_OS::strcpy (fp, ACE_TEXT ("s: %s")); 01400 if (can_check) 01401 this_len = ACE_OS::snprintf 01402 (bp, bspace, format, 01403 str ? str : ACE_TEXT ("(null)"), 01404 lpMsgBuf); 01405 else 01406 this_len = ACE_OS::sprintf 01407 (bp, format, 01408 str ? str : ACE_TEXT ("(null)"), 01409 lpMsgBuf); 01410 // Free the buffer. 01411 ::LocalFree (lpMsgBuf); 01412 } 01413 } 01414 #endif /* ACE_WIN32 */ 01415 ACE_UPDATE_COUNT (bspace, this_len); 01416 break; 01417 } 01418 01419 case 'M': // Print the name of the priority of the message. 01420 01421 // Look at the format precision specifier. .1 is interpreted 01422 // as a single character printout, otherwise we print the name of 01423 // the priority. 01424 01425 // So, did we find a .1 specifier? Do we need to override it? 01426 if (format[1] == ACE_TEXT('.') && 01427 format[2] == ACE_TEXT('1')) 01428 { 01429 // Yup. 01430 // Print a single character signifying the severity of the message 01431 fp = format; 01432 fp++; 01433 01434 # if defined (ACE_USES_WCHAR) 01435 01436 # if defined (ACE_WIN32) // Windows uses 'c' for a wide character 01437 ACE_OS::strcpy (fp, ACE_TEXT ("c")); 01438 # else // Other platforms behave differently 01439 # if defined (HPUX) // HP-Unix compatible 01440 ACE_OS::strcpy (fp, ACE_TEXT ("C")); 01441 # else // Other 01442 ACE_OS::strcpy (fp, ACE_TEXT ("lc")); 01443 # endif /* HPUX */ 01444 # endif 01445 01446 # else /* ACE_USES_WCHAR */ 01447 01448 // Non-unicode builds simply use a standard character format specifier 01449 ACE_OS::strcpy (fp, ACE_TEXT ("c")); 01450 01451 # endif /* ACE_USES_WCHAR */ 01452 01453 // Below is an optimized (binary search based) 01454 // version of the following simple piece of code: 01455 // 01456 // log_priority == LM_SHUTDOWN ? 'S' : // Shutdown 01457 // log_priority == LM_TRACE ? 'T' : // Trace 01458 // log_priority == LM_DEBUG ? 'D' : // Debug 01459 // log_priority == LM_INFO ? 'I' : // Info 01460 // log_priority == LM_NOTICE ? 'N' : // Notice 01461 // log_priority == LM_WARNING ? 'W' : // Warning 01462 // log_priority == LM_STARTUP ? 'U' : // Startup 01463 // log_priority == LM_ERROR ? 'E' : // Error 01464 // log_priority == LM_CRITICAL ? 'C' : // Critical 01465 // log_priority == LM_ALERT ? 'A' : // Alert 01466 // log_priority == LM_EMERGENCY ? '!' : // Emergency 01467 // '?' // Unknown 01468 01469 if (can_check) 01470 { 01471 this_len = ACE_OS::snprintf 01472 (bp, bspace, format, 01473 #if !defined (ACE_USES_WCHAR) || defined (ACE_WIN32) 01474 (int) 01475 #else 01476 (wint_t) 01477 #endif 01478 (log_priority <= LM_WARNING) ? 01479 (log_priority <= LM_DEBUG) ? 01480 (log_priority <= LM_TRACE) ? 01481 (log_priority == LM_SHUTDOWN) ? 01482 ACE_TEXT('S') : ACE_TEXT('T') : ACE_TEXT('D') : 01483 (log_priority <= LM_NOTICE) ? 01484 (log_priority == LM_INFO) ? 01485 ACE_TEXT('I') : ACE_TEXT('N') : ACE_TEXT('W') : 01486 (log_priority <= LM_CRITICAL) ? 01487 (log_priority <= LM_ERROR) ? 01488 (log_priority == LM_STARTUP) ? 01489 ACE_TEXT('U') : ACE_TEXT('E') : ACE_TEXT('C') : 01490 (log_priority <= LM_EMERGENCY) ? 01491 (log_priority == LM_ALERT) ? 01492 ACE_TEXT('A') : ACE_TEXT('!') : ACE_TEXT('?')); 01493 } 01494 else 01495 { 01496 this_len = ACE_OS::sprintf 01497 (bp, format, 01498 #if !defined (ACE_USES_WCHAR) || defined (ACE_WIN32) 01499 (int) 01500 #else 01501 (wint_t) 01502 #endif 01503 (log_priority <= LM_WARNING) ? 01504 (log_priority <= LM_DEBUG) ? 01505 (log_priority <= LM_TRACE) ? 01506 (log_priority == LM_SHUTDOWN) ? 01507 ACE_TEXT('S') : ACE_TEXT('T') : ACE_TEXT('D') : 01508 (log_priority <= LM_NOTICE) ? 01509 (log_priority == LM_INFO) ? 01510 ACE_TEXT('I') : ACE_TEXT('N') : ACE_TEXT('W') : 01511 (log_priority <= LM_CRITICAL) ? 01512 (log_priority <= LM_ERROR) ? 01513 (log_priority == LM_STARTUP) ? 01514 ACE_TEXT('U') : ACE_TEXT('E') : ACE_TEXT('C') : 01515 (log_priority <= LM_EMERGENCY) ? 01516 (log_priority == LM_ALERT) ? 01517 ACE_TEXT('A') : ACE_TEXT('!') : ACE_TEXT('?')); 01518 } 01519 01520 ACE_UPDATE_COUNT (bspace, this_len); 01521 } 01522 else 01523 { 01524 // Nope, print out standard priority_name() string 01525 01526 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 01527 ACE_OS::strcpy (fp, ACE_TEXT ("ls")); 01528 #else 01529 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01530 #endif 01531 if (can_check) 01532 this_len = ACE_OS::snprintf 01533 (bp, bspace, format, 01534 ACE_Log_Record::priority_name (log_priority)); 01535 else 01536 this_len = ACE_OS::sprintf 01537 (bp, format, 01538 ACE_Log_Record::priority_name (log_priority)); 01539 ACE_UPDATE_COUNT (bspace, this_len); 01540 } 01541 break; 01542 01543 case 'm': // Format the string assocated with the errno value. 01544 { 01545 errno = 0; 01546 const int mapped = ACE::map_errno (this->errnum ()); 01547 #ifdef ACE_LOG_MSG_USE_STRERROR_R 01548 char *msg = ACE_OS::strerror_r (mapped, strerror_buf, 01549 sizeof strerror_buf); 01550 #else 01551 char *msg = ACE_OS::strerror (mapped); 01552 #endif 01553 // Windows can try to translate the errnum using 01554 // system calls if strerror() doesn't get anything useful. 01555 #if defined (ACE_WIN32) 01556 if (errno == 0) 01557 { 01558 #endif 01559 01560 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 01561 ACE_OS::strcpy (fp, ACE_TEXT ("ls")); 01562 #else /* ACE_WIN32 && ACE_USES_WCHAR */ 01563 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01564 #endif 01565 if (can_check) 01566 this_len = ACE_OS::snprintf 01567 (bp, bspace, format, ACE_TEXT_CHAR_TO_TCHAR (msg)); 01568 else 01569 this_len = ACE_OS::sprintf 01570 (bp, format, ACE_TEXT_CHAR_TO_TCHAR (msg)); 01571 #if defined (ACE_WIN32) 01572 } 01573 else 01574 { 01575 errno = ACE::map_errno (this->errnum ()); 01576 ACE_TCHAR *lpMsgBuf = 0; 01577 01578 // PharLap can't do FormatMessage, so try for socket 01579 // error. 01580 # if !defined (ACE_HAS_PHARLAP) 01581 ACE_TEXT_FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER 01582 | FORMAT_MESSAGE_MAX_WIDTH_MASK 01583 | FORMAT_MESSAGE_FROM_SYSTEM, 01584 0, 01585 errno, 01586 MAKELANGID (LANG_NEUTRAL, 01587 SUBLANG_DEFAULT), 01588 // Default language 01589 (ACE_TCHAR *) &lpMsgBuf, 01590 0, 01591 0); 01592 # endif /* ACE_HAS_PHARLAP */ 01593 01594 // If we don't get a valid response from 01595 // <FormatMessage>, we'll assume this is a 01596 // WinSock error and so we'll try to convert 01597 // it into a string. If this doesn't work it 01598 // returns "unknown error" which is fine for 01599 // our purposes. 01600 if (lpMsgBuf == 0) 01601 { 01602 const ACE_TCHAR *message = 01603 ACE::sock_error (errno); 01604 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01605 if (can_check) 01606 this_len = ACE_OS::snprintf 01607 (bp, bspace, format, message); 01608 else 01609 this_len = ACE_OS::sprintf (bp, format, message); 01610 } 01611 else 01612 { 01613 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01614 if (can_check) 01615 this_len = ACE_OS::snprintf 01616 (bp, bspace, format, lpMsgBuf); 01617 else 01618 this_len = ACE_OS::sprintf 01619 (bp, format, lpMsgBuf); 01620 // Free the buffer. 01621 ::LocalFree (lpMsgBuf); 01622 } 01623 } 01624 #endif /* ACE_WIN32 */ 01625 ACE_UPDATE_COUNT (bspace, this_len); 01626 break; 01627 } 01628 01629 case 'R': // Format the return status of the operation. 01630 this->op_status (va_arg (argp, int)); 01631 ACE_OS::strcpy (fp, ACE_TEXT ("d")); 01632 if (can_check) 01633 this_len = ACE_OS::snprintf 01634 (bp, bspace, format, this->op_status ()); 01635 else 01636 this_len = ACE_OS::sprintf 01637 (bp, format, this->op_status ()); 01638 ACE_UPDATE_COUNT (bspace, this_len); 01639 break; 01640 01641 case '{': // Increment the trace_depth, then indent 01642 skip_nul_locate = true; 01643 (void) this->inc (); 01644 break; 01645 01646 case '}': // indent, then decrement trace_depth 01647 skip_nul_locate = true; 01648 (void) this->dec (); 01649 break; 01650 01651 case '$': // insert a newline, then indent the next line 01652 // according to %I 01653 *bp++ = '\n'; 01654 --bspace; 01655 /* fallthrough */ 01656 01657 case 'I': // Indent with nesting_depth*width spaces 01658 // Caller can do %*I to override nesting indent, and 01659 // if %*I was done, wp has the extracted width. 01660 #if defined (ACE_HAS_TRACE) 01661 if (0 == wp) 01662 wp = ACE_Trace::get_nesting_indent (); 01663 #else 01664 if (0 == wp) 01665 wp = 4; 01666 #endif /* ACE_HAS_TRACE */ 01667 wp *= this->trace_depth_; 01668 if (static_cast<size_t> (wp) > bspace) 01669 wp = static_cast<int> (bspace); 01670 for (tmp_indent = wp; 01671 tmp_indent; 01672 --tmp_indent) 01673 *bp++ = ' '; 01674 01675 *bp = '\0'; 01676 bspace -= static_cast<size_t> (wp); 01677 skip_nul_locate = true; 01678 break; 01679 01680 case 'r': // Run (invoke) this subroutine. 01681 { 01682 ptrdiff_t const osave = ACE_Log_Msg::msg_off_; 01683 01684 if (ACE_BIT_ENABLED (flags, 01685 ACE_Log_Msg::SILENT) && 01686 bspace > 1) 01687 { 01688 *bp++ = '{'; 01689 --bspace; 01690 } 01691 ACE_Log_Msg::msg_off_ = bp - this->msg_; 01692 01693 (*va_arg (argp, PTF))(); 01694 01695 if (ACE_BIT_ENABLED (flags, 01696 ACE_Log_Msg::SILENT) && 01697 bspace > (1 + ACE_OS::strlen (bp))) 01698 { 01699 bspace -= (ACE_OS::strlen (bp) + 1); 01700 bp += ACE_OS::strlen (bp); 01701 *bp++ = '}'; 01702 } 01703 *bp = '\0'; 01704 skip_nul_locate = true; 01705 ACE_Log_Msg::msg_off_ = osave; 01706 break; 01707 } 01708 01709 case 'S': // format the string for with this signal number. 01710 { 01711 const int sig = va_arg (argp, int); 01712 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01713 if (can_check) 01714 this_len = ACE_OS::snprintf 01715 (bp, bspace, format, ACE_OS::strsignal(sig)); 01716 else 01717 this_len = ACE_OS::sprintf 01718 (bp, format, ACE_OS::strsignal(sig)); 01719 ACE_UPDATE_COUNT (bspace, this_len); 01720 break; 01721 } 01722 01723 case 'D': // Format the timestamp in format: 01724 // yyyy-mm-dd hour:minute:sec.usec 01725 // This is a maximum of 27 characters 01726 // including terminator. 01727 { 01728 ACE_TCHAR day_and_time[27]; 01729 // Did we find the flag indicating a time value argument 01730 if (format[1] == ACE_TEXT('#')) 01731 { 01732 ACE_Time_Value* time_value = va_arg (argp, ACE_Time_Value*); 01733 ACE::timestamp (*time_value, 01734 day_and_time, 01735 sizeof (day_and_time) / sizeof (ACE_TCHAR), 01736 true); 01737 } 01738 else 01739 { 01740 ACE::timestamp (day_and_time, 01741 sizeof (day_and_time) / sizeof (ACE_TCHAR), 01742 true); 01743 } 01744 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 01745 ACE_OS::strcpy (fp, ACE_TEXT ("ls")); 01746 #else 01747 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01748 #endif 01749 if (can_check) 01750 this_len = ACE_OS::snprintf 01751 (bp, bspace, format, day_and_time); 01752 else 01753 this_len = ACE_OS::sprintf (bp, format, day_and_time); 01754 ACE_UPDATE_COUNT (bspace, this_len); 01755 break; 01756 } 01757 01758 case 'T': // Format the timestamp in 01759 // hour:minute:sec.usec format. 01760 { 01761 ACE_TCHAR day_and_time[27]; 01762 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 01763 ACE_OS::strcpy (fp, ACE_TEXT ("ls")); 01764 #else 01765 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01766 #endif 01767 // Did we find the flag indicating a time value argument 01768 if (format[1] == ACE_TEXT('#')) 01769 { 01770 ACE_Time_Value* time_value = va_arg (argp, ACE_Time_Value*); 01771 if (can_check) 01772 this_len = ACE_OS::snprintf 01773 (bp, bspace, format, 01774 ACE::timestamp (*time_value, 01775 day_and_time, 01776 sizeof day_and_time / sizeof (ACE_TCHAR), 01777 true)); 01778 else 01779 this_len = ACE_OS::sprintf 01780 (bp, format, ACE::timestamp (*time_value, 01781 day_and_time, 01782 sizeof day_and_time / sizeof (ACE_TCHAR), 01783 true)); 01784 } 01785 else 01786 { 01787 if (can_check) 01788 this_len = ACE_OS::snprintf 01789 (bp, bspace, format, 01790 ACE::timestamp (day_and_time, sizeof day_and_time / sizeof (ACE_TCHAR), true)); 01791 else 01792 this_len = ACE_OS::sprintf 01793 (bp, format, ACE::timestamp (day_and_time, 01794 sizeof day_and_time / sizeof (ACE_TCHAR), true)); 01795 } 01796 ACE_UPDATE_COUNT (bspace, this_len); 01797 break; 01798 } 01799 01800 case 't': // Format thread id. 01801 #if defined (ACE_WIN32) 01802 ACE_OS::strcpy (fp, ACE_TEXT ("u")); 01803 if (can_check) 01804 this_len = ACE_OS::snprintf 01805 (bp, bspace, format, 01806 static_cast<unsigned> (ACE_Thread::self ())); 01807 else 01808 this_len = 01809 ACE_OS::sprintf (bp, 01810 format, 01811 static_cast <unsigned> (ACE_Thread::self ())); 01812 #elif defined ACE_USES_WCHAR 01813 { 01814 char tid_buf[32] = {}; 01815 ACE_OS::thr_id (tid_buf, sizeof tid_buf); 01816 this_len = ACE_OS::strlen (tid_buf); 01817 ACE_OS::strncpy (bp, ACE_TEXT_CHAR_TO_TCHAR (tid_buf), 01818 bspace); 01819 } 01820 #else 01821 this_len = ACE_OS::thr_id (bp, bspace); 01822 #endif /* ACE_WIN32 */ 01823 ACE_UPDATE_COUNT (bspace, this_len); 01824 break; 01825 01826 case 's': // String 01827 { 01828 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 01829 wchar_t *str = va_arg (argp, wchar_t *); 01830 ACE_OS::strcpy (fp, ACE_TEXT ("ls")); 01831 #else /* ACE_WIN32 && ACE_USES_WCHAR */ 01832 ACE_TCHAR *str = va_arg (argp, ACE_TCHAR *); 01833 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01834 #endif /* ACE_WIN32 && ACE_USES_WCHAR */ 01835 if (can_check) 01836 this_len = ACE_OS::snprintf 01837 (bp, bspace, format, str ? str : ACE_TEXT ("(null)")); 01838 else 01839 this_len = ACE_OS::sprintf 01840 (bp, format, str ? str : ACE_TEXT ("(null)")); 01841 ACE_UPDATE_COUNT (bspace, this_len); 01842 } 01843 break; 01844 01845 case 'C': // Narrow-char string 01846 { 01847 char *cstr = va_arg (argp, char *); 01848 #if defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 01849 ACE_OS::strcpy (fp, ACE_TEXT ("S")); 01850 #else /* ACE_WIN32 && ACE_USES_WCHAR */ 01851 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01852 #endif /* ACE_WIN32 && ACE_USES_WCHAR */ 01853 if (can_check) 01854 this_len = ACE_OS::snprintf 01855 (bp, bspace, format, cstr ? cstr : "(null)"); 01856 else 01857 this_len = ACE_OS::sprintf 01858 (bp, format, cstr ? cstr : "(null)"); 01859 ACE_UPDATE_COUNT (bspace, this_len); 01860 } 01861 break; 01862 01863 case 'W': 01864 { 01865 #if defined (ACE_HAS_WCHAR) 01866 wchar_t *wchar_str = va_arg (argp, wchar_t *); 01867 # if defined (HPUX) 01868 ACE_OS::strcpy (fp, ACE_TEXT ("S")); 01869 # elif defined (ACE_WIN32) 01870 # if defined (ACE_USES_WCHAR) 01871 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01872 # else /* ACE_USES_WCHAR */ 01873 ACE_OS::strcpy (fp, ACE_TEXT ("S")); 01874 # endif /* ACE_USES_WCHAR */ 01875 # else 01876 ACE_OS::strcpy (fp, ACE_TEXT ("ls")); 01877 # endif /* HPUX */ 01878 if (can_check) 01879 this_len = ACE_OS::snprintf 01880 (bp, bspace, format, wchar_str ? wchar_str : ACE_TEXT_WIDE("(null)")); 01881 else 01882 this_len = ACE_OS::sprintf 01883 (bp, format, wchar_str ? wchar_str : ACE_TEXT_WIDE("(null)")); 01884 #endif /* ACE_HAS_WCHAR */ 01885 ACE_UPDATE_COUNT (bspace, this_len); 01886 } 01887 break; 01888 01889 case 'w': // Wide character 01890 #if defined (ACE_WIN32) 01891 # if defined (ACE_USES_WCHAR) 01892 ACE_OS::strcpy (fp, ACE_TEXT ("c")); 01893 # else /* ACE_USES_WCHAR */ 01894 ACE_OS::strcpy (fp, ACE_TEXT ("C")); 01895 # endif /* ACE_USES_WCHAR */ 01896 if (can_check) 01897 this_len = ACE_OS::snprintf 01898 (bp, bspace, format, va_arg (argp, int)); 01899 else 01900 this_len = ACE_OS::sprintf 01901 (bp, format, va_arg (argp, int)); 01902 #elif defined (ACE_USES_WCHAR) 01903 # if defined (HPUX) 01904 ACE_OS::strcpy (fp, ACE_TEXT ("C")); 01905 # else 01906 ACE_OS::strcpy (fp, ACE_TEXT ("lc")); 01907 # endif /* HPUX */ 01908 if (can_check) 01909 this_len = ACE_OS::snprintf 01910 (bp, bspace, format, va_arg (argp, wint_t)); 01911 else 01912 this_len = ACE_OS::sprintf 01913 (bp, format, va_arg (argp, wint_t)); 01914 #else /* ACE_WIN32 */ 01915 ACE_OS::strcpy (fp, ACE_TEXT ("u")); 01916 if (can_check) 01917 this_len = ACE_OS::snprintf 01918 (bp, bspace, format, va_arg (argp, int)); 01919 else 01920 this_len = ACE_OS::sprintf 01921 (bp, format, va_arg (argp, int)); 01922 #endif /* ACE_WIN32 */ 01923 ACE_UPDATE_COUNT (bspace, this_len); 01924 break; 01925 01926 case 'z': // ACE_OS::WChar character 01927 { 01928 // On some platforms sizeof (wchar_t) can be 2 01929 // on the others 4 ... 01930 wchar_t wtchar = 01931 static_cast<wchar_t> (va_arg (argp, int)); 01932 #if defined (ACE_WIN32) 01933 # if defined (ACE_USES_WCHAR) 01934 ACE_OS::strcpy (fp, ACE_TEXT ("c")); 01935 # else /* ACE_USES_WCHAR */ 01936 ACE_OS::strcpy (fp, ACE_TEXT ("C")); 01937 # endif /* ACE_USES_WCHAR */ 01938 #elif defined (ACE_USES_WCHAR) 01939 # if defined (HPUX) 01940 ACE_OS::strcpy (fp, ACE_TEXT ("C")); 01941 # else 01942 ACE_OS::strcpy (fp, ACE_TEXT ("lc")); 01943 # endif /* HPUX */ 01944 #else /* ACE_WIN32 */ 01945 ACE_OS::strcpy (fp, ACE_TEXT ("u")); 01946 #endif /* ACE_WIN32 */ 01947 if (can_check) 01948 this_len = ACE_OS::snprintf (bp, bspace, format, wtchar); 01949 else 01950 this_len = ACE_OS::sprintf (bp, format, wtchar); 01951 ACE_UPDATE_COUNT (bspace, this_len); 01952 break; 01953 } 01954 01955 case 'Z': // ACE_OS::WChar character string 01956 { 01957 ACE_OS::WChar *wchar_str = va_arg (argp, ACE_OS::WChar*); 01958 if (wchar_str == 0) 01959 break; 01960 01961 wchar_t *wchar_t_str = 0; 01962 if (sizeof (ACE_OS::WChar) != sizeof (wchar_t)) 01963 { 01964 size_t len = ACE_OS::wslen (wchar_str) + 1; 01965 ACE_NEW_NORETURN(wchar_t_str, wchar_t[len]); 01966 if (wchar_t_str == 0) 01967 break; 01968 01969 for (size_t i = 0; i < len; ++i) 01970 { 01971 wchar_t_str[i] = wchar_str[i]; 01972 } 01973 } 01974 01975 if (wchar_t_str == 0) 01976 { 01977 wchar_t_str = reinterpret_cast<wchar_t*> (wchar_str); 01978 } 01979 #if defined (ACE_WIN32) 01980 # if defined (ACE_USES_WCHAR) 01981 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 01982 # else /* ACE_USES_WCHAR */ 01983 ACE_OS::strcpy (fp, ACE_TEXT ("S")); 01984 # endif /* ACE_USES_WCHAR */ 01985 #elif defined (ACE_HAS_WCHAR) 01986 # if defined (HPUX) 01987 ACE_OS::strcpy (fp, ACE_TEXT ("S")); 01988 # else 01989 ACE_OS::strcpy (fp, ACE_TEXT ("ls")); 01990 # endif /* HPUX */ 01991 #endif /* ACE_WIN32 / ACE_HAS_WCHAR */ 01992 if (can_check) 01993 this_len = ACE_OS::snprintf 01994 (bp, bspace, format, wchar_t_str); 01995 else 01996 this_len = ACE_OS::sprintf (bp, format, wchar_t_str); 01997 if(sizeof(ACE_OS::WChar) != sizeof(wchar_t)) 01998 { 01999 delete [] wchar_t_str; 02000 } 02001 ACE_UPDATE_COUNT (bspace, this_len); 02002 break; 02003 } 02004 02005 case 'c': 02006 #if defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 02007 ACE_OS::strcpy (fp, ACE_TEXT ("C")); 02008 #else 02009 ACE_OS::strcpy (fp, ACE_TEXT ("c")); 02010 #endif /* ACE_WIN32 && ACE_USES_WCHAR */ 02011 if (can_check) 02012 this_len = ACE_OS::snprintf 02013 (bp, bspace, format, va_arg (argp, int)); 02014 else 02015 this_len = ACE_OS::sprintf 02016 (bp, format, va_arg (argp, int)); 02017 ACE_UPDATE_COUNT (bspace, this_len); 02018 break; 02019 02020 case 'd': case 'i': case 'o': 02021 case 'u': case 'x': case 'X': 02022 fp[0] = *format_str; 02023 fp[1] = '\0'; 02024 if (can_check) 02025 this_len = ACE_OS::snprintf 02026 (bp, bspace, format, va_arg (argp, int)); 02027 else 02028 this_len = ACE_OS::sprintf 02029 (bp, format, va_arg (argp, int)); 02030 ACE_UPDATE_COUNT (bspace, this_len); 02031 break; 02032 02033 case 'F': case 'f': case 'e': case 'E': 02034 case 'g': case 'G': 02035 fp[0] = *format_str; 02036 fp[1] = '\0'; 02037 if (can_check) 02038 this_len = ACE_OS::snprintf 02039 (bp, bspace, format, va_arg (argp, double)); 02040 else 02041 this_len = ACE_OS::sprintf 02042 (bp, format, va_arg (argp, double)); 02043 ACE_UPDATE_COUNT (bspace, this_len); 02044 break; 02045 02046 case 'Q': 02047 { 02048 const ACE_TCHAR *fmt = ACE_UINT64_FORMAT_SPECIFIER; 02049 ACE_OS::strcpy (fp, &fmt[1]); // Skip leading % 02050 if (can_check) 02051 this_len = ACE_OS::snprintf (bp, bspace, 02052 format, 02053 va_arg (argp, ACE_UINT64)); 02054 else 02055 this_len = ACE_OS::sprintf (bp, 02056 format, 02057 va_arg (argp, ACE_UINT64)); 02058 } 02059 ACE_UPDATE_COUNT (bspace, this_len); 02060 break; 02061 02062 case 'q': 02063 { 02064 const ACE_TCHAR *fmt = ACE_INT64_FORMAT_SPECIFIER; 02065 ACE_OS::strcpy (fp, &fmt[1]); // Skip leading % 02066 if (can_check) 02067 this_len = ACE_OS::snprintf (bp, bspace, 02068 format, 02069 va_arg (argp, ACE_INT64)); 02070 else 02071 this_len = ACE_OS::sprintf (bp, 02072 format, 02073 va_arg (argp, ACE_INT64)); 02074 } 02075 ACE_UPDATE_COUNT (bspace, this_len); 02076 break; 02077 02078 case 'b': 02079 { 02080 const ACE_TCHAR *fmt = ACE_SSIZE_T_FORMAT_SPECIFIER; 02081 ACE_OS::strcpy (fp, &fmt[1]); // Skip leading % 02082 } 02083 if (can_check) 02084 this_len = ACE_OS::snprintf (bp, bspace, 02085 format, 02086 va_arg (argp, ssize_t)); 02087 else 02088 this_len = ACE_OS::sprintf (bp, 02089 format, 02090 va_arg (argp, ssize_t)); 02091 ACE_UPDATE_COUNT (bspace, this_len); 02092 break; 02093 02094 case 'B': 02095 { 02096 const ACE_TCHAR *fmt = ACE_SIZE_T_FORMAT_SPECIFIER; 02097 ACE_OS::strcpy (fp, &fmt[1]); // Skip leading % 02098 } 02099 if (can_check) 02100 this_len = ACE_OS::snprintf (bp, bspace, 02101 format, 02102 va_arg (argp, size_t)); 02103 else 02104 this_len = ACE_OS::sprintf (bp, 02105 format, 02106 va_arg (argp, size_t)); 02107 ACE_UPDATE_COUNT (bspace, this_len); 02108 break; 02109 02110 case ':': 02111 { 02112 // Assume a 32 bit time_t and change if needed. 02113 const ACE_TCHAR *fmt = ACE_TEXT ("%d"); 02114 if (sizeof (time_t) == 8) 02115 fmt = ACE_INT64_FORMAT_SPECIFIER; 02116 02117 ACE_OS::strcpy (fp, &fmt[1]); // Skip leading % 02118 } 02119 if (can_check) 02120 this_len = ACE_OS::snprintf (bp, bspace, 02121 format, 02122 va_arg (argp, time_t)); 02123 else 02124 this_len = ACE_OS::sprintf (bp, 02125 format, 02126 va_arg (argp, time_t)); 02127 ACE_UPDATE_COUNT (bspace, this_len); 02128 break; 02129 02130 case '@': 02131 ACE_OS::strcpy (fp, ACE_TEXT ("p")); 02132 if (can_check) 02133 this_len = ACE_OS::snprintf 02134 (bp, bspace, format, va_arg (argp, void*)); 02135 else 02136 this_len = ACE_OS::sprintf 02137 (bp, format, va_arg (argp, void*)); 02138 ACE_UPDATE_COUNT (bspace, this_len); 02139 break; 02140 02141 case '?': 02142 // Stack trace up to this point 02143 { 02144 // skip the frame that we're currently in 02145 ACE_Stack_Trace t(2); 02146 #if defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 02147 ACE_OS::strcpy (fp, ACE_TEXT ("S")); 02148 #else /* ACE_WIN32 && ACE_USES_WCHAR */ 02149 ACE_OS::strcpy (fp, ACE_TEXT ("s")); 02150 #endif /* ACE_WIN32 && ACE_USES_WCHAR */ 02151 if (can_check) 02152 this_len = ACE_OS::snprintf 02153 (bp, bspace, format, t.c_str ()); 02154 else 02155 this_len = ACE_OS::sprintf 02156 (bp, format, t.c_str ()); 02157 ACE_UPDATE_COUNT (bspace, this_len); 02158 break; 02159 } 02160 02161 02162 default: 02163 // So, it's not a legit format specifier after all... 02164 // Copy from the original % to where we are now, then 02165 // continue with whatever comes next. 02166 while (start_format != format_str && bspace > 0) 02167 { 02168 *bp++ = *start_format++; 02169 --bspace; 02170 } 02171 if (bspace > 0) 02172 { 02173 *bp++ = *format_str; 02174 --bspace; 02175 } 02176 break; 02177 } 02178 02179 // Bump to the next char in the caller's format_str 02180 ++format_str; 02181 } 02182 02183 if (!skip_nul_locate) 02184 while (*bp != '\0') // Locate end of bp. 02185 ++bp; 02186 } 02187 } 02188 02189 *bp = '\0'; // Terminate bp, but don't auto-increment this! 02190 02191 ssize_t result = 0; 02192 02193 // Check that memory was not corrupted, if it corrupted we can't log anything 02194 // anymore because all our members could be corrupted. 02195 if (bp >= (this->msg_ + ACE_MAXLOGMSGLEN+1)) 02196 { 02197 abort_prog = true; 02198 ACE_OS::fprintf (stderr, 02199 "The following logged message is too long!\n"); 02200 } 02201 else 02202 { 02203 // Copy the message from thread-specific storage into the transfer 02204 // buffer (this can be optimized away by changing other code...). 02205 log_record.msg_data (this->msg ()); 02206 02207 // Write the <log_record> to the appropriate location. 02208 result = this->log (log_record, 02209 abort_prog); 02210 } 02211 02212 if (abort_prog) 02213 { 02214 // Since we are now calling abort instead of exit, this value is 02215 // not used. 02216 ACE_UNUSED_ARG (exit_value); 02217 02218 // *Always* print a message to stderr if we're aborting. We 02219 // don't use verbose, however, to avoid recursive aborts if 02220 // something is hosed. 02221 log_record.print (ACE_Log_Msg::local_host_, 0, stderr); 02222 ACE_OS::abort (); 02223 } 02224 02225 return result; 02226 #endif /* ACE_LACKS_VA_FUNCTIONS */ 02227 }
ssize_t ACE_Log_Msg::log | ( | const ACE_Log_Formatter & | formatter | ) |
ssize_t ACE_Log_Msg::log | ( | ACE_Log_Priority | log_priority, | |
const ACE_ANTI_TCHAR * | format_str, | |||
... | ||||
) |
Since this is the ANTI_TCHAR version, we need to convert the format string over.
Definition at line 980 of file Log_Msg.cpp.
00982 { 00983 ACE_TRACE ("ACE_Log_Msg::log"); 00984 00985 // Start of variable args section. 00986 va_list argp; 00987 00988 va_start (argp, format_str); 00989 00990 ssize_t const result = this->log (ACE_TEXT_ANTI_TO_TCHAR (format_str), 00991 log_priority, 00992 argp); 00993 va_end (argp); 00994 00995 return result; 00996 }
ssize_t ACE_Log_Msg::log | ( | ACE_Log_Priority | log_priority, | |
const ACE_TCHAR * | format_str, | |||
... | ||||
) |
Format a message to the thread-safe ACE logging mechanism. Valid options (prefixed by '', as in printf format strings) include:
Valid Options (prefixed by '', as in printf format strings) include: 'A': print an ACE_timer_t value 'a': exit the program at this point (var-argument is the exit status!) 'b': print a ssize_t value 'B': print a size_t value 'c': print a character 'C': print a character string 'i', 'd': print a decimal number 'I', indent according to nesting depth 'e', 'E', 'f', 'F', 'g', 'G': print a double 'l', print line number where an error occurred. 'M': print the name of the priority of the message. 'm': Return the message corresponding to errno value, e.g., as done by <strerror> 'N': print file name where the error occurred. 'n': print the name of the program (or "<unknown>" if not set) 'o': print as an octal number 'P': format the current process id 'p': format the appropriate errno message from sys_errlist, e.g., as done by <perror> 'Q': print out the uint64 number 'q': print out the int64 number '@': print a void* pointer (in hexadecimal) 'r': call the function pointed to by the corresponding argument 'R': print return status 'S': print out the appropriate signal message corresponding to var-argument, e.g., as done by strsignal() 's': format a character string 'T': print timestamp in hour:minute:sec:usec format. 'D': print timestamp in month/day/year hour:minute:sec:usec format. 't': print thread id (1 if single-threaded) 'u': print as unsigned int 'x': print as a hex number 'X': print as a hex number 'w': print a wide character 'W': print out a wide character string. 'z': print an ACE_OS::WChar character 'Z': print an ACE_OS::WChar character string ':': print a time_t value as an integral number '': format a single percent sign, ''
Definition at line 957 of file Log_Msg.cpp.
int ACE_Log_Msg::log_hexdump | ( | ACE_Log_Priority | log_priority, | |
const char * | buffer, | |||
size_t | size, | |||
const ACE_TCHAR * | text = 0 , |
|||
ACE_Log_Category_TSS * | category = 0 | |||
) |
Method to log hex dump. This is useful for debugging. Calls log() to do the actual print, but formats first to make the chars printable.
Definition at line 2959 of file Log_Msg.cpp.
02964 { 02965 // Only print the message if <priority_mask_> hasn't been reset to 02966 // exclude this logging priority. 02967 if (this->log_priority_enabled (log_priority) == 0) 02968 return 0; 02969 02970 size_t text_sz = 0; 02971 if (text) 02972 text_sz = ACE_OS::strlen (text); 02973 02974 size_t const total_buffer_size = 02975 ACE_Log_Record::MAXLOGMSGLEN - ACE_Log_Record::VERBOSE_LEN + text_sz; 02976 02977 ACE_Array<ACE_TCHAR> msg_buf(total_buffer_size); 02978 if (msg_buf.size() == 0) 02979 return -1; 02980 02981 ACE_TCHAR* end_ptr = &msg_buf[0] + total_buffer_size; 02982 ACE_TCHAR* wr_ptr = &msg_buf[0]; 02983 msg_buf[0] = 0; // in case size = 0 02984 02985 if (text) 02986 wr_ptr += ACE_OS::snprintf (wr_ptr, 02987 end_ptr - wr_ptr, 02988 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) 02989 ACE_TEXT ("%ls - "), 02990 #else 02991 ACE_TEXT ("%s - "), 02992 #endif 02993 text); 02994 02995 wr_ptr += ACE_OS::snprintf (wr_ptr, 02996 end_ptr - wr_ptr, 02997 ACE_TEXT ("HEXDUMP ") 02998 ACE_SIZE_T_FORMAT_SPECIFIER 02999 ACE_TEXT (" bytes"), 03000 size); 03001 03002 // estimate how many bytes can be output 03003 // We can fit 16 bytes output in text mode per line, 4 chars per byte; 03004 // i.e. we need 68 bytes of buffer per line. 03005 size_t hexdump_size = (end_ptr - wr_ptr -58)/68*16; 03006 03007 if (hexdump_size < size) 03008 { 03009 wr_ptr += ACE_OS::snprintf (wr_ptr, 03010 end_ptr - wr_ptr, 03011 ACE_TEXT (" (showing first ") 03012 ACE_SIZE_T_FORMAT_SPECIFIER 03013 ACE_TEXT (" bytes)"), 03014 hexdump_size); 03015 size = hexdump_size; 03016 } 03017 03018 *wr_ptr++ = '\n'; 03019 ACE::format_hexdump(buffer, size, wr_ptr, end_ptr - wr_ptr); 03020 03021 // Now print out the formatted buffer. 03022 ACE_Log_Record log_record (log_priority, 03023 ACE_OS::gettimeofday (), 03024 this->getpid ()); 03025 03026 log_record.category(category); 03027 log_record.msg_data(&msg_buf[0]); 03028 03029 this->log (log_record, false); 03030 return 0; 03031 }
int ACE_Log_Msg::log_priority_enabled | ( | ACE_Log_Priority | log_priority, | |
const wchar_t * | , | |||
... | ||||
) |
Return true if the requested priority is enabled.
int ACE_Log_Msg::log_priority_enabled | ( | ACE_Log_Priority | log_priority, | |
const char * | , | |||
... | ||||
) |
Return true if the requested priority is enabled.
Definition at line 3208 of file Log_Msg.cpp.
03211 { 03212 return this->log_priority_enabled (log_priority); 03213 }
int ACE_Log_Msg::log_priority_enabled | ( | ACE_Log_Priority | log_priority | ) | [inline] |
Return true if the requested priority is enabled.
Definition at line 18 of file Log_Msg.inl.
00019 { 00020 return ACE_BIT_ENABLED (this->priority_mask_ | 00021 ACE_Log_Msg::process_priority_mask_, 00022 log_priority); 00023 }
const ACE_TCHAR * ACE_Log_Msg::msg | ( | void | ) | [inline] |
Get the message that describes what type of error occurred.
Definition at line 169 of file Log_Msg.inl.
00170 { 00171 return this->msg_ + ACE_Log_Msg::msg_off_; 00172 }
void ACE_Log_Msg::msg | ( | const ACE_TCHAR * | m | ) | [inline] |
Set the message that describes what type of error occurred.
Definition at line 176 of file Log_Msg.inl.
00177 { 00178 ACE_OS::strsncpy (this->msg_, m, 00179 ((ACE_MAXLOGMSGLEN+1) / sizeof (ACE_TCHAR))); 00180 }
ACE_Log_Msg_Backend * ACE_Log_Msg::msg_backend | ( | void | ) | [static] |
Definition at line 3133 of file Log_Msg.cpp.
03134 { 03135 ACE_TRACE ("ACE_Log_Msg::msg_backend"); 03136 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 03137 *ACE_Log_Msg_Manager::get_lock (), 0)); 03138 03139 return ACE_Log_Msg_Manager::custom_backend_; 03140 }
ACE_Log_Msg_Backend * ACE_Log_Msg::msg_backend | ( | ACE_Log_Msg_Backend * | b | ) | [static] |
Set a new backend object and return the existing backend to allow "chaining". Note that as opposed to ACE_Log_Msg_Callback, ACE_Log_Msg_Backend is a per-process entity.
Definition at line 3121 of file Log_Msg.cpp.
03122 { 03123 ACE_TRACE ("ACE_Log_Msg::msg_backend"); 03124 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 03125 *ACE_Log_Msg_Manager::get_lock (), 0)); 03126 03127 ACE_Log_Msg_Backend *tmp = ACE_Log_Msg_Manager::custom_backend_; 03128 ACE_Log_Msg_Manager::custom_backend_ = b; 03129 return tmp; 03130 }
ACE_Log_Msg_Callback * ACE_Log_Msg::msg_callback | ( | void | ) | const [inline] |
Definition at line 184 of file Log_Msg.inl.
00185 { 00186 return this->msg_callback_; 00187 }
ACE_Log_Msg_Callback * ACE_Log_Msg::msg_callback | ( | ACE_Log_Msg_Callback * | c | ) | [inline] |
Set a new callback object and return the existing callback to allow "chaining". Note that ACE_Log_Msg_Callback objects are not inherited when spawning a new thread, so you'll need to reset them in each thread.
Definition at line 191 of file Log_Msg.inl.
00192 { 00193 ACE_Log_Msg_Callback *old = this->msg_callback_; 00194 this->msg_callback_ = c; 00195 return old; 00196 }
ACE_OSTREAM_TYPE * ACE_Log_Msg::msg_ostream | ( | void | ) | const [inline] |
Get the ostream that is used to print error messages.
Definition at line 200 of file Log_Msg.inl.
00201 { 00202 return this->ostream_; 00203 }
void ACE_Log_Msg::msg_ostream | ( | ACE_OSTREAM_TYPE * | m, | |
bool | delete_ostream | |||
) |
delete_stream == true, forces Log_Msg.h to delete the stream in its own ~dtor (assumes control of the stream) use only with proper ostream (eg: fstream), not (cout, cerr)
Definition at line 3143 of file Log_Msg.cpp.
03144 { 03145 if (this->ostream_ == m) 03146 { 03147 // Same stream, allow user to change the delete_ostream "flag" 03148 if (delete_ostream && !this->ostream_refcount_) 03149 { 03150 #if defined (ACE_HAS_ALLOC_HOOKS) 03151 ACE_NEW_MALLOC (this->ostream_refcount_, static_cast<Atomic_ULong*>(ACE_Allocator::instance()->malloc(sizeof(Atomic_ULong))), Atomic_ULong (1)); 03152 #else 03153 ACE_NEW (this->ostream_refcount_, Atomic_ULong (1)); 03154 #endif /* ACE_HAS_ALLOC_HOOKS */ 03155 } 03156 else if (!delete_ostream && this->ostream_refcount_) 03157 { 03158 if (--*this->ostream_refcount_ == 0) 03159 { 03160 #if defined (ACE_HAS_ALLOC_HOOKS) 03161 this->ostream_refcount_->~Atomic_ULong(); 03162 ACE_Allocator::instance()->free(this->ostream_refcount_); 03163 #else 03164 delete this->ostream_refcount_; 03165 #endif /* ACE_HAS_ALLOC_HOOKS */ 03166 } 03167 this->ostream_refcount_ = 0; 03168 } 03169 // The other two cases are no-ops, the user has requested the same 03170 // state that's already present. 03171 return; 03172 } 03173 03174 this->cleanup_ostream (); 03175 03176 if (delete_ostream) 03177 { 03178 #if defined (ACE_HAS_ALLOC_HOOKS) 03179 ACE_NEW_MALLOC (this->ostream_refcount_, static_cast<Atomic_ULong*>(ACE_Allocator::instance()->malloc(sizeof(Atomic_ULong))), Atomic_ULong (1)); 03180 #else 03181 ACE_NEW (this->ostream_refcount_, Atomic_ULong (1)); 03182 #endif /* ACE_HAS_ALLOC_HOOKS */ 03183 } 03184 03185 this->ostream_ = m; 03186 }
void ACE_Log_Msg::msg_ostream | ( | ACE_OSTREAM_TYPE * | m | ) | [inline] |
Update the ostream without overwriting the delete_ostream_ flag.
Definition at line 207 of file Log_Msg.inl.
00208 { 00209 this->ostream_ = m; 00210 }
int ACE_Log_Msg::op_status | ( | void | ) | const [inline] |
Get the result of the operation status (by convention, -1 means error).
Definition at line 34 of file Log_Msg.inl.
00035 { 00036 return this->status_; 00037 }
void ACE_Log_Msg::op_status | ( | int | status | ) | [inline] |
Set the result of the operation status (by convention, -1 means error).
Definition at line 27 of file Log_Msg.inl.
int ACE_Log_Msg::open | ( | const ACE_TCHAR * | prog_name, | |
u_long | options_flags = ACE_Log_Msg::STDERR , |
|||
const ACE_TCHAR * | logger_key = 0 | |||
) |
Initialize the ACE logging facility.
Initialize the ACE logging facility. Supplies the program name that is available to each logging message call. Default arguments set up logging to STDERR only.
prog_name | The name of the calling program. | |
options_flags | A bitwise-or of options flags used to set the initial behavior and logging sink(s). (see the enum above for the valid values). | |
logger_key | The name of ACE_FIFO rendezvous point where the local client logger daemon is listening for logging messages if the LOGGER bit is set in the flags argument. If the SYSLOG bit is set in flags, logger_key is the source/program name specified in the syslog facility (UNIX/Linux) or the Windows event log (Windows). In the SYSLOG case, if logger_key is 0, prog_name is used. |
Definition at line 786 of file Log_Msg.cpp.
00789 { 00790 ACE_TRACE ("ACE_Log_Msg::open"); 00791 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 00792 *ACE_Log_Msg_Manager::get_lock (), -1)); 00793 00794 if (prog_name) 00795 { 00796 #if defined(ACE_HAS_ALLOC_HOOKS) 00797 ACE_Allocator::instance()->free ((void *) ACE_Log_Msg::program_name_); 00798 #else 00799 ACE_OS::free ((void *) ACE_Log_Msg::program_name_); 00800 #endif /* ACE_HAS_ALLOC_HOOKS */ 00801 00802 // Stop heap checking, block will be freed by the destructor. 00803 { 00804 ACE_NO_HEAP_CHECK; 00805 00806 ACE_ALLOCATOR_RETURN (ACE_Log_Msg::program_name_, 00807 ACE_OS::strdup (prog_name), 00808 -1); 00809 } 00810 } 00811 else if (ACE_Log_Msg::program_name_ == 0) 00812 { 00813 // Stop heap checking, block will be freed by the destructor. 00814 ACE_NO_HEAP_CHECK; 00815 ACE_ALLOCATOR_RETURN (ACE_Log_Msg::program_name_, 00816 ACE_OS::strdup (ACE_TEXT ("<unknown>")), 00817 -1); 00818 } 00819 00820 int status = 0; 00821 00822 // Be sure that there is a message_queue_, with multiple threads. 00823 ACE_MT (ACE_Log_Msg_Manager::init_backend (&flags)); 00824 00825 // Always close the current handle before doing anything else. 00826 if (ACE_Log_Msg_Manager::log_backend_ != 0) 00827 ACE_Log_Msg_Manager::log_backend_->reset (); 00828 00829 if (ACE_Log_Msg_Manager::custom_backend_ != 0) 00830 ACE_Log_Msg_Manager::custom_backend_->reset (); 00831 00832 // Note that if we fail to open the message queue the default action 00833 // is to use stderr (set via static initialization in the 00834 // Log_Msg.cpp file). 00835 00836 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::LOGGER) 00837 || ACE_BIT_ENABLED (flags, ACE_Log_Msg::SYSLOG)) 00838 { 00839 // The SYSLOG backends (both NT and UNIX) can get along fine 00840 // without the logger_key - they will default to prog_name if 00841 // logger key is 0. 00842 if (logger_key == 0 && ACE_BIT_ENABLED (flags, ACE_Log_Msg::LOGGER)) 00843 status = -1; 00844 else 00845 status = ACE_Log_Msg_Manager::log_backend_->open (logger_key); 00846 00847 if (status == -1) 00848 ACE_SET_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::STDERR); 00849 else 00850 { 00851 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::LOGGER)) 00852 ACE_SET_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::LOGGER); 00853 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::SYSLOG)) 00854 ACE_SET_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::SYSLOG); 00855 } 00856 } 00857 else if (ACE_BIT_ENABLED (ACE_Log_Msg::flags_, ACE_Log_Msg::LOGGER) 00858 || ACE_BIT_ENABLED (ACE_Log_Msg::flags_, ACE_Log_Msg::SYSLOG)) 00859 { 00860 // If we are closing down logger, redirect logging to stderr. 00861 ACE_CLR_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::LOGGER); 00862 ACE_CLR_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::SYSLOG); 00863 ACE_SET_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::STDERR); 00864 } 00865 00866 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::CUSTOM)) 00867 { 00868 status = 00869 ACE_Log_Msg_Manager::custom_backend_->open (logger_key); 00870 00871 if (status != -1) 00872 ACE_SET_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::CUSTOM); 00873 } 00874 00875 // Remember, ACE_Log_Msg::STDERR bit is on by default... 00876 if (status != -1 00877 && ACE_BIT_ENABLED (flags, 00878 ACE_Log_Msg::STDERR) == 0) 00879 ACE_CLR_BITS (ACE_Log_Msg::flags_, 00880 ACE_Log_Msg::STDERR); 00881 00882 // VERBOSE takes precedence over VERBOSE_LITE... 00883 if (ACE_BIT_ENABLED (flags, 00884 ACE_Log_Msg::VERBOSE_LITE)) 00885 ACE_SET_BITS (ACE_Log_Msg::flags_, 00886 ACE_Log_Msg::VERBOSE_LITE); 00887 else if (ACE_BIT_ENABLED (flags, 00888 ACE_Log_Msg::VERBOSE)) 00889 ACE_SET_BITS (ACE_Log_Msg::flags_, 00890 ACE_Log_Msg::VERBOSE); 00891 00892 if (ACE_BIT_ENABLED (flags, 00893 ACE_Log_Msg::OSTREAM)) 00894 { 00895 ACE_SET_BITS (ACE_Log_Msg::flags_, 00896 ACE_Log_Msg::OSTREAM); 00897 // Only set this to cerr if it hasn't already been set. 00898 if (this->msg_ostream () == 0) 00899 this->msg_ostream (ACE_DEFAULT_LOG_STREAM); 00900 } 00901 00902 if (ACE_BIT_ENABLED (flags, 00903 ACE_Log_Msg::MSG_CALLBACK)) 00904 ACE_SET_BITS (ACE_Log_Msg::flags_, 00905 ACE_Log_Msg::MSG_CALLBACK); 00906 00907 if (ACE_BIT_ENABLED (flags, 00908 ACE_Log_Msg::SILENT)) 00909 ACE_SET_BITS (ACE_Log_Msg::flags_, 00910 ACE_Log_Msg::SILENT); 00911 00912 return status; 00913 }
ACE_Log_Msg& ACE_Log_Msg::operator= | ( | const ACE_Log_Msg & | ) | [private] |
Set the ACE_Log_Priority mask, returns original mask.
Definition at line 608 of file Log_Msg.cpp.
00609 { 00610 u_long o_mask; 00611 00612 if (mask_type == THREAD) 00613 { 00614 o_mask = this->priority_mask_; 00615 this->priority_mask_ = n_mask; 00616 } 00617 else 00618 { 00619 o_mask = ACE_Log_Msg::process_priority_mask_; 00620 ACE_Log_Msg::process_priority_mask_ = n_mask; 00621 } 00622 00623 return o_mask; 00624 }
Get the current ACE_Log_Priority mask.
Definition at line 9 of file Log_Msg.inl.
00010 { 00011 return mask_type == THREAD 00012 ? this->priority_mask_ 00013 : ACE_Log_Msg::process_priority_mask_; 00014 }
const ACE_TCHAR * ACE_Log_Msg::program_name | ( | void | ) | [static] |
Returns the current program name used for logging.
Definition at line 429 of file Log_Msg.cpp.
00430 { 00431 return ACE_Log_Msg::program_name_; 00432 }
int ACE_Log_Msg::release | ( | void | ) |
Release the internal lock.
Definition at line 627 of file Log_Msg.cpp.
bool ACE_Log_Msg::restart | ( | void | ) | const [inline] |
Get the field that indicates whether interrupted calls should be restarted.
Definition at line 48 of file Log_Msg.inl.
00049 { 00050 return this->restart_; 00051 }
void ACE_Log_Msg::restart | ( | bool | r | ) | [inline] |
Set the field that indicates whether interrupted calls should be restarted.
Definition at line 41 of file Log_Msg.inl.
00042 { 00043 this->restart_ = r; 00044 }
void ACE_Log_Msg::set | ( | const char * | file, | |
int | line, | |||
int | op_status = -1 , |
|||
int | errnum = 0 , |
|||
bool | restart = true , |
|||
ACE_OSTREAM_TYPE * | os = 0 , |
|||
ACE_Log_Msg_Callback * | c = 0 | |||
) |
Set the line number, file name, operational status, error number, restart flag, ostream, and the callback object. This combines all the other set methods into a single method.
Definition at line 3034 of file Log_Msg.cpp.
void ACE_Log_Msg::set_flags | ( | u_long | f | ) |
Enable the bits in the logger's options flags.
Definition at line 577 of file Log_Msg.cpp.
00578 { 00579 ACE_TRACE ("ACE_Log_Msg::set_flags"); 00580 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon, 00581 *ACE_Log_Msg_Manager::get_lock ())); 00582 00583 ACE_SET_BITS (ACE_Log_Msg::flags_, flgs); 00584 }
void ACE_Log_Msg::start_tracing | ( | void | ) | [inline] |
Start tracing status on a per-thread basis...
Enable the tracing facility on a per-thread basis.
Definition at line 133 of file Log_Msg.inl.
00134 { 00135 this->tracing_enabled_ = true; 00136 }
void ACE_Log_Msg::stop_tracing | ( | void | ) | [inline] |
Stop tracing status on a per-thread basis...
Disable the tracing facility on a per-thread basis.
Definition at line 141 of file Log_Msg.inl.
00142 { 00143 this->tracing_enabled_ = false; 00144 }
void ACE_Log_Msg::sync | ( | const ACE_TCHAR * | program_name | ) |
Call after doing a fork()
to resynchronize the process id and program_name_
variables.
Definition at line 538 of file Log_Msg.cpp.
00539 { 00540 ACE_TRACE ("ACE_Log_Msg::sync"); 00541 00542 if (prog_name) 00543 { 00544 // Must free if already allocated!!! 00545 #if defined (ACE_HAS_ALLOC_HOOKS) 00546 ACE_Allocator::instance()->free ((void *) ACE_Log_Msg::program_name_); 00547 #else 00548 ACE_OS::free ((void *) ACE_Log_Msg::program_name_); 00549 #endif /* ACE_HAS_ALLOC_HOOKS */ 00550 00551 // Stop heap checking, block will be freed by the destructor when 00552 // the last ACE_Log_Msg instance is deleted. 00553 // Heap checking state will be restored when the block is left. 00554 { 00555 ACE_NO_HEAP_CHECK; 00556 00557 ACE_Log_Msg::program_name_ = ACE_OS::strdup (prog_name); 00558 } 00559 } 00560 00561 ACE_Log_Msg::msg_off_ = 0; 00562 }
void ACE_Log_Msg::sync_hook | ( | const ACE_TCHAR * | prg_name | ) | [static, private] |
Decouple the OS layer from the ACE_Log_Msg layer.
Definition at line 524 of file Log_Msg.cpp.
void ACE_Log_Msg::thr_desc | ( | ACE_Thread_Descriptor * | td | ) |
Set the TSS thread descriptor. This method will call td->acquire_release to block execution until this call return.
Definition at line 3112 of file Log_Msg.cpp.
03113 { 03114 this->thr_desc_ = td; 03115 03116 if (td != 0) 03117 td->acquire_release (); 03118 }
ACE_Thread_Descriptor * ACE_Log_Msg::thr_desc | ( | void | ) | const [inline] |
Get the TSS thread descriptor.
Definition at line 125 of file Log_Msg.inl.
00126 { 00127 return this->thr_desc_; 00128 }
ACE_OS_Thread_Descriptor * ACE_Log_Msg::thr_desc_hook | ( | void | ) | [static, private] |
Return the TSS singleton thread descriptor.
Definition at line 530 of file Log_Msg.cpp.
void ACE_Log_Msg::trace_active | ( | bool | value | ) | [inline] |
Set trace active status.
Definition at line 118 of file Log_Msg.inl.
00119 { 00120 this->trace_active_ = value; 00121 }
bool ACE_Log_Msg::trace_active | ( | void | ) | const [inline] |
Get trace active status.
Definition at line 111 of file Log_Msg.inl.
00112 { 00113 return this->trace_active_; 00114 }
void ACE_Log_Msg::trace_depth | ( | int | depth | ) | [inline] |
Set trace depth.
Definition at line 104 of file Log_Msg.inl.
00105 { 00106 this->trace_depth_ = depth; 00107 }
int ACE_Log_Msg::trace_depth | ( | void | ) | const [inline] |
Get trace depth.
Definition at line 97 of file Log_Msg.inl.
00098 { 00099 return this->trace_depth_; 00100 }
bool ACE_Log_Msg::tracing_enabled | ( | void | ) | const [inline] |
Query tracing status on a per-thread basis...
Definition at line 148 of file Log_Msg.inl.
00149 { 00150 return this->tracing_enabled_; 00151 }
friend class ACE_Log_Formatter [friend] |
struct { ... } ACE_Log_Msg::conditional_values_ [private] |
Anonymous struct since there will only be one instance. This struct keeps information stored away in case we actually end up calling log() if the log priority is correct.
u_long ACE_Log_Msg::default_priority_mask_ = 0 [static, private] |
int ACE_Log_Msg::errnum_ [private] |
const char* ACE_Log_Msg::file_ |
char ACE_Log_Msg::file_[MAXPATHLEN+1] [private] |
u_long ACE_Log_Msg::flags_ = ACE_Log_Msg::STDERR [static, private] |
int ACE_Log_Msg::instance_count_ = 0 [static, private] |
Number of existing ACE_Log_Msg instances; when 0, delete program/host names
Instance count for Log_Msg - used to know when dynamically allocated storage (program name and host name) can be safely deleted.
bool ACE_Log_Msg::is_set_ |
bool ACE_Log_Msg::key_created_ [static, private] |
int ACE_Log_Msg::linenum_ [private] |
const ACE_TCHAR * ACE_Log_Msg::local_host_ = 0 [static, private] |
ACE_TCHAR* ACE_Log_Msg::msg_ [private] |
ACE_Log_Msg_Callback* ACE_Log_Msg::msg_callback_ [private] |
ptrdiff_t ACE_Log_Msg::msg_off_ = 0 [static, private] |
ACE_OSTREAM_TYPE* ACE_Log_Msg::ostream_ [private] |
Atomic_ULong* ACE_Log_Msg::ostream_refcount_ [private] |
u_long ACE_Log_Msg::priority_mask_ [private] |
u_long ACE_Log_Msg::process_priority_mask_ [static, private] |
LM_SHUTDOWN | LM_TRACE | LM_DEBUG | LM_INFO | LM_NOTICE | LM_WARNING | LM_STARTUP | LM_ERROR | LM_CRITICAL | LM_ALERT | LM_EMERGENCY
Keeps track of all the per-process ACE_Log_Priority values that are currently enabled. Default is for all logging priorities to be enabled.
Default per-process priority mask By default, all priorities are enabled.
const ACE_TCHAR * ACE_Log_Msg::program_name_ = 0 [static, private] |
bool ACE_Log_Msg::restart_ [private] |
int ACE_Log_Msg::status_ [private] |
ACE_Thread_Descriptor* ACE_Log_Msg::thr_desc_ [private] |
If we're running in the context of an ACE_Thread_Manager this will point to the thread descriptor adapter which holds the thread descriptor of the thread. This can be used to rapidly access all thread data kept in ACE_Thread_Descriptor.
int ACE_Log_Msg::timestamp_ [private] |
bool ACE_Log_Msg::trace_active_ [private] |
int ACE_Log_Msg::trace_depth_ [private] |
bool ACE_Log_Msg::tracing_enabled_ [private] |