00001
00002
00003
00004 #include "ace/config-all.h"
00005
00006
00007 #if defined (ACE_NTRACE)
00008 # undef ACE_NTRACE
00009 #endif
00010 #define ACE_NTRACE 1
00011
00012 #include "ace/ACE.h"
00013 #include "ace/Thread_Manager.h"
00014 #include "ace/Guard_T.h"
00015 #include "ace/OS_NS_stdio.h"
00016 #include "ace/OS_NS_errno.h"
00017 #include "ace/OS_NS_sys_time.h"
00018 #include "ace/OS_NS_wchar.h"
00019 #include "ace/OS_NS_signal.h"
00020 #include "ace/os_include/os_typeinfo.h"
00021
00022 #if !defined (ACE_MT_SAFE) || (ACE_MT_SAFE != 0)
00023 # include "ace/Object_Manager_Base.h"
00024 #endif
00025
00026 #if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
00027
00028 # include "ace/streams.h"
00029 #endif
00030
00031 #if defined (ACE_HAS_TRACE)
00032 # include "ace/Trace.h"
00033 #endif
00034
00035 #include "ace/Log_Msg.h"
00036 #include "ace/Log_Msg_Callback.h"
00037 #include "ace/Log_Msg_IPC.h"
00038 #include "ace/Log_Msg_NT_Event_Log.h"
00039 #include "ace/Log_Msg_UNIX_Syslog.h"
00040 #include "ace/Log_Record.h"
00041 #include "ace/Recursive_Thread_Mutex.h"
00042 #include "ace/Stack_Trace.h"
00043
00044 #if !defined (__ACE_INLINE__)
00045 #include "ace/Log_Msg.inl"
00046 #endif
00047
00048 ACE_RCSID(ace, Log_Msg, "$Id: Log_Msg.cpp 88331 2009-12-24 09:54:25Z johnnyw $")
00049
00050 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00051
00052 ACE_ALLOC_HOOK_DEFINE(ACE_Log_Msg)
00053
00054 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00055 bool ACE_Log_Msg::key_created_ = 0;
00056 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || \
00057 defined (ACE_HAS_TSS_EMULATION)
00058
00059 #if defined (ACE_MVS)
00060 static ACE_thread_key_t the_log_msg_tss_key =
00061 #if !defined(_LP64)
00062 { '\0','\0','\0','\0' };
00063 #else
00064 { '\0','\0','\0','\0','\0','\0','\0','\0' };
00065 #endif
00066 #else
00067 static ACE_thread_key_t the_log_msg_tss_key = 0;
00068 #endif
00069
00070 ACE_thread_key_t *log_msg_tss_key (void)
00071 {
00072 return &the_log_msg_tss_key;
00073 }
00074
00075 # endif
00076 #else
00077 static ACE_Cleanup_Adapter<ACE_Log_Msg>* log_msg_cleanup = 0;
00078 class ACE_Msg_Log_Cleanup: public ACE_Cleanup_Adapter<ACE_Log_Msg>
00079 {
00080 public:
00081 virtual ~ACE_Msg_Log_Cleanup (void) {
00082 if (this == log_msg_cleanup)
00083 log_msg_cleanup = 0;
00084 }
00085 };
00086 #endif
00087
00088 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) && !defined (ACE_HAS_PHARLAP)
00089 # define ACE_LOG_MSG_SYSLOG_BACKEND ACE_Log_Msg_NT_Event_Log
00090 #elif !defined (ACE_LACKS_UNIX_SYSLOG) && !defined (ACE_HAS_WINCE)
00091 # define ACE_LOG_MSG_SYSLOG_BACKEND ACE_Log_Msg_UNIX_Syslog
00092 #else
00093 # define ACE_LOG_MSG_SYSLOG_BACKEND ACE_Log_Msg_IPC
00094 #endif
00095
00096
00097
00098
00099
00100
00101 #define ACE_UPDATE_COUNT(COUNT, LEN) \
00102 do { if (static_cast<size_t> (LEN) > COUNT) COUNT = 0; \
00103 else COUNT -= static_cast<size_t> (LEN); \
00104 } while (0)
00105
00106
00107
00108
00109 int ACE_Log_Msg::instance_count_ = 0;
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 class ACE_Log_Msg_Manager
00122 {
00123 public:
00124 static ACE_Log_Msg_Backend *log_backend_;
00125 static ACE_Log_Msg_Backend *custom_backend_;
00126
00127 static u_long log_backend_flags_;
00128
00129 static int init_backend (const u_long *flags = 0);
00130
00131 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00132
00133 static void close (void) ACE_GCC_DESTRUCTOR_ATTRIBUTE;
00134
00135
00136 static ACE_Recursive_Thread_Mutex *get_lock (void);
00137
00138 private:
00139 static ACE_Recursive_Thread_Mutex *lock_;
00140 #endif
00141 };
00142
00143 ACE_Log_Msg_Backend *ACE_Log_Msg_Manager::log_backend_ = 0;
00144 ACE_Log_Msg_Backend *ACE_Log_Msg_Manager::custom_backend_ = 0;
00145
00146 u_long ACE_Log_Msg_Manager::log_backend_flags_ = 0;
00147
00148 int ACE_Log_Msg_Manager::init_backend (const u_long *flags)
00149 {
00150
00151
00152
00153 if (flags)
00154 {
00155
00156 if (ACE_BIT_ENABLED (*flags, ACE_Log_Msg::CUSTOM) &&
00157 ACE_Log_Msg_Manager::custom_backend_ == 0)
00158 {
00159 return -1;
00160 }
00161
00162 if ((ACE_BIT_ENABLED (*flags, ACE_Log_Msg::SYSLOG)
00163 && ACE_BIT_DISABLED (ACE_Log_Msg_Manager::log_backend_flags_, ACE_Log_Msg::SYSLOG))
00164 || (ACE_BIT_DISABLED (*flags, ACE_Log_Msg::SYSLOG)
00165 && ACE_BIT_ENABLED (ACE_Log_Msg_Manager::log_backend_flags_, ACE_Log_Msg::SYSLOG)))
00166 {
00167 delete ACE_Log_Msg_Manager::log_backend_;
00168 ACE_Log_Msg_Manager::log_backend_ = 0;
00169 }
00170
00171 ACE_Log_Msg_Manager::log_backend_flags_ = *flags;
00172 }
00173
00174 if (ACE_Log_Msg_Manager::log_backend_ == 0)
00175 {
00176 ACE_NO_HEAP_CHECK;
00177
00178 #if (defined (WIN32) || !defined (ACE_LACKS_UNIX_SYSLOG)) && !defined (ACE_HAS_WINCE) && !defined (ACE_HAS_PHARLAP)
00179
00180 if (ACE_BIT_ENABLED (ACE_Log_Msg_Manager::log_backend_flags_, ACE_Log_Msg::SYSLOG))
00181 ACE_NEW_RETURN (ACE_Log_Msg_Manager::log_backend_,
00182 ACE_LOG_MSG_SYSLOG_BACKEND,
00183 -1);
00184 else
00185 #endif
00186 ACE_NEW_RETURN (ACE_Log_Msg_Manager::log_backend_,
00187 ACE_Log_Msg_IPC,
00188 -1);
00189 }
00190
00191 return 0;
00192 }
00193
00194 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00195 ACE_Recursive_Thread_Mutex *ACE_Log_Msg_Manager::lock_ = 0;
00196
00197 ACE_Recursive_Thread_Mutex *
00198 ACE_Log_Msg_Manager::get_lock (void)
00199 {
00200
00201
00202
00203
00204 if (ACE_Log_Msg_Manager::lock_ == 0)
00205 {
00206 ACE_NO_HEAP_CHECK;
00207
00208 ACE_NEW_RETURN (ACE_Log_Msg_Manager::lock_,
00209 ACE_Recursive_Thread_Mutex,
00210 0);
00211 }
00212
00213 if (init_backend () == -1)
00214 return 0;
00215
00216 return ACE_Log_Msg_Manager::lock_;
00217 }
00218
00219 void
00220 ACE_Log_Msg_Manager::close (void)
00221 {
00222 #if defined (ACE_HAS_STHREADS) && ! defined (ACE_HAS_TSS_EMULATION) && ! defined (ACE_HAS_EXCEPTIONS)
00223
00224
00225
00226
00227
00228 delete ACE_Log_Msg::instance ();
00229 #endif
00230
00231
00232 delete ACE_Log_Msg_Manager::lock_;
00233 ACE_Log_Msg_Manager::lock_ = 0;
00234
00235 delete ACE_Log_Msg_Manager::log_backend_;
00236 ACE_Log_Msg_Manager::log_backend_ = 0;
00237
00238
00239 ACE_Log_Msg_Manager::custom_backend_ = 0;
00240 }
00241
00242 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || \
00243 defined (ACE_HAS_TSS_EMULATION)
00244
00245 # if defined (ACE_HAS_THR_C_DEST)
00246 # define LOCAL_EXTERN_PREFIX extern "C"
00247 # else
00248 # define LOCAL_EXTERN_PREFIX
00249 # endif
00250 LOCAL_EXTERN_PREFIX
00251 void
00252 ACE_TSS_CLEANUP_NAME (void *ptr)
00253 {
00254
00255 ACE_Log_Msg* log_msg = (ACE_Log_Msg*) ptr;
00256 if (log_msg->thr_desc()!=0)
00257 log_msg->thr_desc()->log_msg_cleanup(log_msg);
00258 else
00259 delete log_msg;
00260 }
00261 # endif
00262 #endif
00263
00264
00265 int
00266 ACE_Log_Msg::exists (void)
00267 {
00268 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00269 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || \
00270 defined (ACE_HAS_TSS_EMULATION)
00271 void *tss_log_msg = 0;
00272
00273
00274
00275 return ACE_Log_Msg::key_created_
00276 && ACE_Thread::getspecific (*(log_msg_tss_key ()), &tss_log_msg) != -1
00277 && tss_log_msg != 0;
00278 # else
00279 # error "Platform must support thread-specific storage if threads are used."
00280 # endif
00281 #else
00282 return 1;
00283 #endif
00284 }
00285
00286 ACE_Log_Msg *
00287 ACE_Log_Msg::instance (void)
00288 {
00289 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00290 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || \
00291 defined (ACE_HAS_TSS_EMULATION)
00292
00293
00294 if (!ACE_Log_Msg::key_created_)
00295 {
00296 ACE_thread_mutex_t *lock =
00297 reinterpret_cast<ACE_thread_mutex_t *> (
00298 ACE_OS_Object_Manager::preallocated_object
00299 [ACE_OS_Object_Manager::ACE_LOG_MSG_INSTANCE_LOCK]);
00300
00301 if (1 == ACE_OS_Object_Manager::starting_up())
00302
00303
00304
00305 ;
00306 else
00307 ACE_OS::thread_mutex_lock (lock);
00308
00309 if (!ACE_Log_Msg::key_created_)
00310 {
00311
00312 ACE_Log_Msg_Manager::get_lock ();
00313
00314 {
00315 ACE_NO_HEAP_CHECK;
00316 if (ACE_Thread::keycreate (log_msg_tss_key (),
00317 &ACE_TSS_CLEANUP_NAME) != 0)
00318 {
00319 if (1 == ACE_OS_Object_Manager::starting_up())
00320
00321
00322
00323 ;
00324 else
00325 ACE_OS::thread_mutex_unlock (lock);
00326 return 0;
00327 }
00328 }
00329
00330 ACE_Log_Msg::key_created_ = true;
00331 }
00332
00333 if (1 == ACE_OS_Object_Manager::starting_up())
00334
00335
00336
00337 ;
00338 else
00339 ACE_OS::thread_mutex_unlock (lock);
00340 }
00341
00342 ACE_Log_Msg *tss_log_msg = 0;
00343 void *temp = 0;
00344
00345
00346 if (ACE_Thread::getspecific (*(log_msg_tss_key ()), &temp) == -1)
00347 return 0;
00348
00349 tss_log_msg = static_cast <ACE_Log_Msg *> (temp);
00350
00351
00352 if (tss_log_msg == 0)
00353 {
00354
00355
00356
00357
00358
00359
00360 {
00361 ACE_NO_HEAP_CHECK;
00362
00363 ACE_NEW_RETURN (tss_log_msg,
00364 ACE_Log_Msg,
00365 0);
00366
00367
00368
00369
00370 if (ACE_Thread::setspecific (*(log_msg_tss_key()),
00371 reinterpret_cast<void *> (tss_log_msg))
00372 != 0)
00373 return 0;
00374 }
00375 }
00376
00377 return tss_log_msg;
00378 # else
00379 # error "Platform must support thread-specific storage if threads are used."
00380 # endif
00381 #else
00382
00383
00384
00385 if (ACE_Log_Msg_Manager::init_backend () == -1)
00386 return 0;
00387
00388
00389
00390 if (log_msg_cleanup == 0)
00391 {
00392 ACE_NEW_RETURN (log_msg_cleanup, ACE_Msg_Log_Cleanup, 0);
00393
00394 ACE_Object_Manager::at_exit (log_msg_cleanup,
00395 0,
00396 typeid (*log_msg_cleanup).name ());
00397 }
00398
00399 return &log_msg_cleanup->object ();
00400 #endif
00401 }
00402
00403
00404
00405 int
00406 ACE_Log_Msg::last_error_adapter (void)
00407 {
00408 return ACE_OS::last_error ();
00409 }
00410
00411
00412
00413
00414 void
00415 ACE_Log_Msg::enable_debug_messages (ACE_Log_Priority priority)
00416 {
00417 ACE_SET_BITS (ACE_Log_Msg::default_priority_mask_, priority);
00418 ACE_Log_Msg *i = ACE_Log_Msg::instance ();
00419 i->priority_mask (i->priority_mask () | priority);
00420 }
00421
00422
00423
00424
00425 void
00426 ACE_Log_Msg::disable_debug_messages (ACE_Log_Priority priority)
00427 {
00428 ACE_CLR_BITS (ACE_Log_Msg::default_priority_mask_, priority);
00429 ACE_Log_Msg *i = ACE_Log_Msg::instance ();
00430 i->priority_mask (i->priority_mask () & ~priority);
00431 }
00432
00433 const ACE_TCHAR *
00434 ACE_Log_Msg::program_name (void)
00435 {
00436 return ACE_Log_Msg::program_name_;
00437 }
00438
00439
00440 const ACE_TCHAR *ACE_Log_Msg::local_host_ = 0;
00441
00442
00443 const ACE_TCHAR *ACE_Log_Msg::program_name_ = 0;
00444
00445
00446 u_long ACE_Log_Msg::flags_ = ACE_Log_Msg::STDERR;
00447
00448
00449 pid_t ACE_Log_Msg::pid_ = -2;
00450
00451
00452 ptrdiff_t ACE_Log_Msg::msg_off_ = 0;
00453
00454
00455
00456 u_long ACE_Log_Msg::default_priority_mask_ = 0;
00457
00458
00459
00460 u_long ACE_Log_Msg::process_priority_mask_ = LM_SHUTDOWN
00461 | LM_TRACE
00462 | LM_DEBUG
00463 | LM_INFO
00464 | LM_NOTICE
00465 | LM_WARNING
00466 | LM_STARTUP
00467 | LM_ERROR
00468 | LM_CRITICAL
00469 | LM_ALERT
00470 | LM_EMERGENCY;
00471
00472 void
00473 ACE_Log_Msg::close (void)
00474 {
00475
00476 ACE_MT (ACE_Log_Msg_Manager::close ());
00477
00478
00479
00480
00481
00482 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) && \
00483 (defined (ACE_HAS_THREAD_SPECIFIC_STORAGE) || \
00484 defined (ACE_HAS_TSS_EMULATION))
00485
00486 if (ACE_Log_Msg::key_created_)
00487 {
00488 ACE_thread_mutex_t *lock =
00489 reinterpret_cast<ACE_thread_mutex_t *>
00490 (ACE_OS_Object_Manager::preallocated_object
00491 [ACE_OS_Object_Manager::ACE_LOG_MSG_INSTANCE_LOCK]);
00492 ACE_OS::thread_mutex_lock (lock);
00493
00494 if (ACE_Log_Msg::key_created_)
00495 {
00496
00497
00498
00499
00500
00501
00502 ACE_Log_Msg *tss_log_msg = 0;
00503 void *temp = 0;
00504
00505
00506 if (ACE_Thread::getspecific (*(log_msg_tss_key ()), &temp) != -1
00507 && temp)
00508 {
00509 tss_log_msg = static_cast <ACE_Log_Msg *> (temp);
00510
00511 ACE_TSS_CLEANUP_NAME(tss_log_msg);
00512 if (ACE_Thread::setspecific(*(log_msg_tss_key()),
00513 reinterpret_cast <void *>(0)) != 0)
00514 ACE_OS::printf ("ACE_Log_Msg::close failed to ACE_Thread::setspecific to 0\n");
00515 }
00516
00517
00518
00519
00520 ACE_Thread::keyfree (*(log_msg_tss_key()));
00521 ACE_Log_Msg::key_created_ = false;
00522 }
00523
00524 ACE_OS::thread_mutex_unlock (lock);
00525 }
00526 #endif
00527 }
00528
00529 void
00530 ACE_Log_Msg::sync_hook (const ACE_TCHAR *prg_name)
00531 {
00532 ACE_LOG_MSG->sync (prg_name);
00533 }
00534
00535 ACE_OS_Thread_Descriptor *
00536 ACE_Log_Msg::thr_desc_hook (void)
00537 {
00538 return ACE_LOG_MSG->thr_desc ();
00539 }
00540
00541
00542
00543 void
00544 ACE_Log_Msg::sync (const ACE_TCHAR *prog_name)
00545 {
00546 ACE_TRACE ("ACE_Log_Msg::sync");
00547
00548 if (prog_name)
00549 {
00550
00551 ACE_OS::free ((void *) ACE_Log_Msg::program_name_);
00552
00553
00554
00555
00556 {
00557 ACE_NO_HEAP_CHECK;
00558
00559 ACE_Log_Msg::program_name_ = ACE_OS::strdup (prog_name);
00560 }
00561 }
00562
00563 ACE_Log_Msg::pid_ = ACE_OS::getpid ();
00564 ACE_Log_Msg::msg_off_ = 0;
00565 }
00566
00567 u_long
00568 ACE_Log_Msg::flags (void)
00569 {
00570 ACE_TRACE ("ACE_Log_Msg::flags");
00571 u_long result;
00572 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00573 *ACE_Log_Msg_Manager::get_lock (), 0));
00574
00575 result = ACE_Log_Msg::flags_;
00576 return result;
00577 }
00578
00579 void
00580 ACE_Log_Msg::set_flags (u_long flgs)
00581 {
00582 ACE_TRACE ("ACE_Log_Msg::set_flags");
00583 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
00584 *ACE_Log_Msg_Manager::get_lock ()));
00585
00586 ACE_SET_BITS (ACE_Log_Msg::flags_, flgs);
00587 }
00588
00589 void
00590 ACE_Log_Msg::clr_flags (u_long flgs)
00591 {
00592 ACE_TRACE ("ACE_Log_Msg::clr_flags");
00593 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
00594 *ACE_Log_Msg_Manager::get_lock ()));
00595
00596 ACE_CLR_BITS (ACE_Log_Msg::flags_, flgs);
00597 }
00598
00599 int
00600 ACE_Log_Msg::acquire (void)
00601 {
00602 ACE_TRACE ("ACE_Log_Msg::acquire");
00603 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00604 return ACE_Log_Msg_Manager::get_lock ()->acquire ();
00605 #else
00606 return 0;
00607 #endif
00608 }
00609
00610 u_long
00611 ACE_Log_Msg::priority_mask (u_long n_mask, MASK_TYPE mask_type)
00612 {
00613 u_long o_mask;
00614
00615 if (mask_type == THREAD)
00616 {
00617 o_mask = this->priority_mask_;
00618 this->priority_mask_ = n_mask;
00619 }
00620 else
00621 {
00622 o_mask = ACE_Log_Msg::process_priority_mask_;
00623 ACE_Log_Msg::process_priority_mask_ = n_mask;
00624 }
00625
00626 return o_mask;
00627 }
00628
00629 int
00630 ACE_Log_Msg::release (void)
00631 {
00632 ACE_TRACE ("ACE_Log_Msg::release");
00633
00634 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00635 return ACE_Log_Msg_Manager::get_lock ()->release ();
00636 #else
00637 return 0;
00638 #endif
00639 }
00640
00641 ACE_Log_Msg::ACE_Log_Msg (void)
00642 : status_ (0),
00643 errnum_ (0),
00644 linenum_ (0),
00645 msg_ (0),
00646 restart_ (1),
00647 ostream_ (0),
00648 ostream_refcount_ (0),
00649 msg_callback_ (0),
00650 trace_depth_ (0),
00651 trace_active_ (false),
00652 tracing_enabled_ (true),
00653 thr_desc_ (0),
00654 priority_mask_ (default_priority_mask_),
00655 timestamp_ (0)
00656 {
00657
00658
00659 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
00660 *ACE_Log_Msg_Manager::get_lock ()));
00661 ++instance_count_;
00662
00663 if (this->instance_count_ == 1)
00664 ACE_Base_Thread_Adapter::set_log_msg_hooks (ACE_Log_Msg::init_hook,
00665 ACE_Log_Msg::inherit_hook,
00666 ACE_Log_Msg::close,
00667 ACE_Log_Msg::sync_hook,
00668 ACE_Log_Msg::thr_desc_hook);
00669
00670 this->conditional_values_.is_set_ = false;
00671
00672 char *timestamp = ACE_OS::getenv ("ACE_LOG_TIMESTAMP");
00673 if (timestamp != 0)
00674 {
00675
00676 if (ACE_OS::strcmp (timestamp, "TIME") == 0)
00677 {
00678 this->timestamp_ = 1;
00679 }
00680 else if (ACE_OS::strcmp (timestamp, "DATE") == 0)
00681 {
00682 this->timestamp_ = 2;
00683 }
00684 }
00685
00686 ACE_NEW_NORETURN (this->msg_, ACE_TCHAR[ACE_MAXLOGMSGLEN+1]);
00687 }
00688
00689 ACE_Log_Msg::~ACE_Log_Msg (void)
00690 {
00691 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00692
00693 int instance_count = 0;
00694
00695
00696
00697
00698 {
00699 ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
00700 *ACE_Log_Msg_Manager::get_lock ()));
00701 instance_count = --instance_count_;
00702 }
00703
00704
00705 #else
00706 int instance_count = --instance_count_;
00707 #endif
00708
00709
00710
00711
00712 if (instance_count == 0)
00713 {
00714
00715 if (ACE_Log_Msg_Manager::log_backend_ != 0)
00716 ACE_Log_Msg_Manager::log_backend_->close ();
00717
00718
00719 if (ACE_Log_Msg_Manager::custom_backend_ != 0)
00720 ACE_Log_Msg_Manager::custom_backend_->close ();
00721
00722 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00723 # if defined (ACE_HAS_TSS_EMULATION)
00724 ACE_Log_Msg_Manager::close ();
00725 # endif
00726 # endif
00727
00728 if (ACE_Log_Msg::program_name_)
00729 {
00730 ACE_OS::free ((void *) ACE_Log_Msg::program_name_);
00731 ACE_Log_Msg::program_name_ = 0;
00732 }
00733
00734 if (ACE_Log_Msg::local_host_)
00735 {
00736 ACE_OS::free ((void *) ACE_Log_Msg::local_host_);
00737 ACE_Log_Msg::local_host_ = 0;
00738 }
00739 }
00740
00741 this->cleanup_ostream ();
00742
00743 delete[] this->msg_;
00744 }
00745
00746 void
00747 ACE_Log_Msg::cleanup_ostream ()
00748 {
00749 if (this->ostream_refcount_)
00750 {
00751 if (--*this->ostream_refcount_ == 0)
00752 {
00753 delete this->ostream_refcount_;
00754 #if defined (ACE_LACKS_IOSTREAM_TOTALLY)
00755 ACE_OS::fclose (this->ostream_);
00756 #else
00757 delete this->ostream_;
00758 this->ostream_ = 0;
00759 #endif
00760 }
00761 this->ostream_refcount_ = 0;
00762 }
00763 }
00764
00765
00766
00767 int
00768 ACE_Log_Msg::open (const ACE_TCHAR *prog_name,
00769 u_long flags,
00770 const ACE_TCHAR *logger_key)
00771 {
00772 ACE_TRACE ("ACE_Log_Msg::open");
00773 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00774 *ACE_Log_Msg_Manager::get_lock (), -1));
00775
00776 if (prog_name)
00777 {
00778 ACE_OS::free ((void *) ACE_Log_Msg::program_name_);
00779
00780
00781 {
00782 ACE_NO_HEAP_CHECK;
00783
00784 ACE_ALLOCATOR_RETURN (ACE_Log_Msg::program_name_,
00785 ACE_OS::strdup (prog_name),
00786 -1);
00787 }
00788 }
00789 else if (ACE_Log_Msg::program_name_ == 0)
00790 {
00791
00792 ACE_NO_HEAP_CHECK;
00793 ACE_ALLOCATOR_RETURN (ACE_Log_Msg::program_name_,
00794 ACE_OS::strdup (ACE_TEXT ("<unknown>")),
00795 -1);
00796 }
00797
00798 int status = 0;
00799
00800
00801 ACE_MT (ACE_Log_Msg_Manager::init_backend (&flags));
00802
00803
00804 if (ACE_Log_Msg_Manager::log_backend_ != 0)
00805 ACE_Log_Msg_Manager::log_backend_->reset ();
00806
00807 if (ACE_Log_Msg_Manager::custom_backend_ != 0)
00808 ACE_Log_Msg_Manager::custom_backend_->reset ();
00809
00810
00811
00812
00813
00814 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::LOGGER)
00815 || ACE_BIT_ENABLED (flags, ACE_Log_Msg::SYSLOG))
00816 {
00817
00818
00819
00820 if (logger_key == 0 && ACE_BIT_ENABLED (flags, ACE_Log_Msg::LOGGER))
00821 status = -1;
00822 else
00823 status = ACE_Log_Msg_Manager::log_backend_->open (logger_key);
00824
00825 if (status == -1)
00826 ACE_SET_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::STDERR);
00827 else
00828 {
00829 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::LOGGER))
00830 ACE_SET_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::LOGGER);
00831 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::SYSLOG))
00832 ACE_SET_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::SYSLOG);
00833 }
00834 }
00835 else if (ACE_BIT_ENABLED (ACE_Log_Msg::flags_, ACE_Log_Msg::LOGGER)
00836 || ACE_BIT_ENABLED (ACE_Log_Msg::flags_, ACE_Log_Msg::SYSLOG))
00837 {
00838
00839 ACE_CLR_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::LOGGER);
00840 ACE_CLR_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::SYSLOG);
00841 ACE_SET_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::STDERR);
00842 }
00843
00844 if (ACE_BIT_ENABLED (flags, ACE_Log_Msg::CUSTOM))
00845 {
00846 status =
00847 ACE_Log_Msg_Manager::custom_backend_->open (logger_key);
00848
00849 if (status != -1)
00850 ACE_SET_BITS (ACE_Log_Msg::flags_, ACE_Log_Msg::CUSTOM);
00851 }
00852
00853
00854 if (status != -1
00855 && ACE_BIT_ENABLED (flags,
00856 ACE_Log_Msg::STDERR) == 0)
00857 ACE_CLR_BITS (ACE_Log_Msg::flags_,
00858 ACE_Log_Msg::STDERR);
00859
00860
00861 if (ACE_BIT_ENABLED (flags,
00862 ACE_Log_Msg::VERBOSE_LITE))
00863 ACE_SET_BITS (ACE_Log_Msg::flags_,
00864 ACE_Log_Msg::VERBOSE_LITE);
00865 else if (ACE_BIT_ENABLED (flags,
00866 ACE_Log_Msg::VERBOSE))
00867 ACE_SET_BITS (ACE_Log_Msg::flags_,
00868 ACE_Log_Msg::VERBOSE);
00869
00870 if (ACE_BIT_ENABLED (flags,
00871 ACE_Log_Msg::OSTREAM))
00872 {
00873 ACE_SET_BITS (ACE_Log_Msg::flags_,
00874 ACE_Log_Msg::OSTREAM);
00875
00876 if (this->msg_ostream () == 0)
00877 this->msg_ostream (ACE_DEFAULT_LOG_STREAM);
00878 }
00879
00880 if (ACE_BIT_ENABLED (flags,
00881 ACE_Log_Msg::MSG_CALLBACK))
00882 ACE_SET_BITS (ACE_Log_Msg::flags_,
00883 ACE_Log_Msg::MSG_CALLBACK);
00884
00885 if (ACE_BIT_ENABLED (flags,
00886 ACE_Log_Msg::SILENT))
00887 ACE_SET_BITS (ACE_Log_Msg::flags_,
00888 ACE_Log_Msg::SILENT);
00889
00890 return status;
00891 }
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933 ssize_t
00934 ACE_Log_Msg::log (ACE_Log_Priority log_priority,
00935 const ACE_TCHAR *format_str, ...)
00936 {
00937 ACE_TRACE ("ACE_Log_Msg::log");
00938
00939
00940 va_list argp;
00941
00942 va_start (argp, format_str);
00943
00944 ssize_t const result = this->log (format_str,
00945 log_priority,
00946 argp);
00947 va_end (argp);
00948
00949 return result;
00950 }
00951
00952 #if defined (ACE_HAS_WCHAR)
00953
00954
00955
00956
00957 ssize_t
00958 ACE_Log_Msg::log (ACE_Log_Priority log_priority,
00959 const ACE_ANTI_TCHAR *format_str, ...)
00960 {
00961 ACE_TRACE ("ACE_Log_Msg::log");
00962
00963
00964 va_list argp;
00965
00966 va_start (argp, format_str);
00967
00968 ssize_t const result = this->log (ACE_TEXT_ANTI_TO_TCHAR (format_str),
00969 log_priority,
00970 argp);
00971 va_end (argp);
00972
00973 return result;
00974 }
00975 #endif
00976
00977 ssize_t
00978 ACE_Log_Msg::log (const ACE_TCHAR *format_str,
00979 ACE_Log_Priority log_priority,
00980 va_list argp)
00981 {
00982 ACE_TRACE ("ACE_Log_Msg::log");
00983
00984
00985 typedef void (*PTF)(...);
00986
00987
00988 bool const conditional_values = this->conditional_values_.is_set_;
00989
00990
00991 this->conditional_values_.is_set_ = false;
00992
00993
00994
00995 if (this->log_priority_enabled (log_priority) == 0)
00996 return 0;
00997
00998
00999
01000 if (conditional_values)
01001 this->set (this->conditional_values_.file_,
01002 this->conditional_values_.line_,
01003 this->conditional_values_.op_status_,
01004 this->conditional_values_.errnum_,
01005 this->restart (),
01006 this->msg_ostream (),
01007 this->msg_callback ());
01008
01009
01010
01011
01012 ACE_Errno_Guard guard (errno);
01013
01014 ACE_Log_Record log_record (log_priority,
01015 ACE_OS::gettimeofday (),
01016 this->getpid ());
01017
01018
01019
01020 ACE_TCHAR *bp = const_cast<ACE_TCHAR *> (this->msg ());
01021 size_t bspace = ACE_MAXLOGMSGLEN;
01022 if (this->msg_off_ <= ACE_Log_Record::MAXLOGMSGLEN)
01023 bspace -= static_cast<size_t> (this->msg_off_);
01024
01025
01026
01027
01028
01029
01030 ACE_TCHAR test[2];
01031 bool can_check = ACE_OS::snprintf (test, 1, ACE_TEXT ("x")) != -1;
01032
01033 bool abort_prog = false;
01034 int exit_value = 0;
01035
01036 if (ACE_BIT_ENABLED (ACE_Log_Msg::flags_, ACE_Log_Msg::VERBOSE))
01037 {
01038
01039
01040 if (ACE_Log_Msg::program_name_ != 0)
01041 {
01042 for (const ACE_TCHAR *s = ACE_Log_Msg::program_name_;
01043 bspace > 1 && (*bp = *s) != '\0';
01044 ++s, --bspace)
01045 bp++;
01046
01047 *bp++ = '|';
01048 --bspace;
01049 }
01050 }
01051
01052 if (timestamp_ > 0)
01053 {
01054 ACE_TCHAR day_and_time[35];
01055 const ACE_TCHAR *s = 0;
01056 if (timestamp_ == 1)
01057 {
01058
01059 s = ACE::timestamp (day_and_time, sizeof day_and_time / sizeof (ACE_TCHAR), 1);
01060 }
01061 else
01062 {
01063
01064 ACE::timestamp (day_and_time, sizeof day_and_time / sizeof (ACE_TCHAR));
01065 s = day_and_time;
01066 }
01067
01068 for (; bspace > 1 && (*bp = *s) != '\0'; ++s, --bspace)
01069 ++bp;
01070
01071 *bp++ = '|';
01072 --bspace;
01073 }
01074
01075 while (*format_str != '\0' && bspace > 0)
01076 {
01077
01078
01079
01080 if (*format_str != '%')
01081 {
01082 *bp++ = *format_str++;
01083 --bspace;
01084 }
01085 else if (format_str[1] == '%')
01086 {
01087 *bp++ = *format_str++;
01088 ++format_str;
01089 --bspace;
01090 }
01091 else
01092 {
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105 const ACE_TCHAR *abort_str = ACE_TEXT ("Aborting...");
01106 const ACE_TCHAR *start_format = format_str;
01107 ACE_TCHAR format[128];
01108 ACE_TCHAR *fp;
01109 int wp = 0;
01110 bool done = false;
01111 bool skip_nul_locate = false;
01112 int this_len = 0;
01113
01114 fp = format;
01115 *fp++ = *format_str++;
01116
01117
01118 int tmp_indent = 0;
01119
01120
01121
01122
01123
01124
01125
01126 while (!done)
01127 {
01128 done = true;
01129
01130 switch (*format_str)
01131 {
01132
01133
01134
01135
01136
01137 case '-':
01138 case '+':
01139 case '0':
01140 case ' ':
01141 case '#':
01142 case '1':
01143 case '2':
01144 case '3':
01145 case '4':
01146 case '5':
01147 case '6':
01148 case '7':
01149 case '8':
01150 case '9':
01151 case '.':
01152 case 'L':
01153 case 'h':
01154 *fp++ = *format_str;
01155 done = false;
01156 break;
01157
01158 case '*':
01159 wp = va_arg (argp, int);
01160 ACE_OS::sprintf (fp, ACE_TEXT ("%d"), wp);
01161 fp += ACE_OS::strlen (fp);
01162 done = false;
01163 break;
01164
01165 case 'A':
01166 {
01167 ACE_OS::strcpy (fp, ACE_TEXT ("f"));
01168 double const value = va_arg (argp, double);
01169 if (can_check)
01170 this_len = ACE_OS::snprintf (bp, bspace, format, value);
01171 else
01172 this_len = ACE_OS::sprintf (bp, format, value);
01173 ACE_UPDATE_COUNT (bspace, this_len);
01174 }
01175 break;
01176
01177 case 'a':
01178 abort_prog = true;
01179 exit_value = va_arg (argp, int);
01180 ACE_OS::strsncpy (bp, abort_str, bspace);
01181 if (bspace > ACE_OS::strlen (abort_str))
01182 bspace -= ACE_OS::strlen (abort_str);
01183 else
01184 bspace = 0;
01185 break;
01186
01187 case 'l':
01188 ACE_OS::strcpy (fp, ACE_TEXT ("d"));
01189 if (can_check)
01190 this_len = ACE_OS::snprintf (bp,
01191 bspace,
01192 format,
01193 this->linenum ());
01194 else
01195 this_len = ACE_OS::sprintf (bp, format, this->linenum ());
01196 ACE_UPDATE_COUNT (bspace, this_len);
01197 break;
01198
01199 case 'N':
01200 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
01201 ACE_OS::strcpy (fp, ACE_TEXT ("ls"));
01202 #else
01203 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01204 #endif
01205 if (can_check)
01206 this_len = ACE_OS::snprintf (bp, bspace, format,
01207 this->file () ?
01208 ACE_TEXT_CHAR_TO_TCHAR (this->file ())
01209 : ACE_TEXT ("<unknown file>"));
01210 else
01211 this_len = ACE_OS::sprintf (bp, format,
01212 this->file () ?
01213 ACE_TEXT_CHAR_TO_TCHAR (this->file ())
01214 : ACE_TEXT ("<unknown file>"));
01215 ACE_UPDATE_COUNT (bspace, this_len);
01216 break;
01217
01218 case 'n':
01219 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
01220 ACE_OS::strcpy (fp, ACE_TEXT ("ls"));
01221 #else
01222 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01223 #endif
01224 if (can_check)
01225 this_len = ACE_OS::snprintf (bp, bspace, format,
01226 ACE_Log_Msg::program_name_ ?
01227 ACE_Log_Msg::program_name_ :
01228 ACE_TEXT ("<unknown>"));
01229 else
01230 this_len = ACE_OS::sprintf (bp, format,
01231 ACE_Log_Msg::program_name_ ?
01232 ACE_Log_Msg::program_name_ :
01233 ACE_TEXT ("<unknown>"));
01234 ACE_UPDATE_COUNT (bspace, this_len);
01235 break;
01236
01237 case 'P':
01238 #if defined (ACE_OPENVMS)
01239
01240 ACE_OS::strcpy (fp, ACE_TEXT ("x"));
01241 #else
01242 ACE_OS::strcpy (fp, ACE_TEXT ("d"));
01243 #endif
01244 if (can_check)
01245 this_len = ACE_OS::snprintf
01246 (bp, bspace, format,
01247 static_cast<int> (this->getpid ()));
01248 else
01249 this_len = ACE_OS::sprintf
01250 (bp, format, static_cast<int> (this->getpid ()));
01251 ACE_UPDATE_COUNT (bspace, this_len);
01252 break;
01253
01254 case 'p':
01255 {
01256 errno = 0;
01257 char *msg = ACE_OS::strerror (ACE::map_errno (this->errnum ()));
01258
01259
01260 #if defined (ACE_WIN32)
01261 if (errno == 0)
01262 {
01263 #endif
01264
01265 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
01266 ACE_OS::strcpy (fp, ACE_TEXT ("ls: %ls"));
01267 wchar_t *str = va_arg (argp, wchar_t *);
01268 #else
01269 ACE_OS::strcpy (fp, ACE_TEXT ("s: %s"));
01270 ACE_TCHAR *str = va_arg (argp, ACE_TCHAR *);
01271 #endif
01272 if (can_check)
01273 this_len = ACE_OS::snprintf
01274 (bp, bspace, format,
01275 str ? str : ACE_TEXT ("(null)"),
01276 ACE_TEXT_CHAR_TO_TCHAR (msg));
01277 else
01278 this_len = ACE_OS::sprintf
01279 (bp, format,
01280 str ? str : ACE_TEXT ("(null)"),
01281 ACE_TEXT_CHAR_TO_TCHAR (msg));
01282 #if defined (ACE_WIN32)
01283 }
01284 else
01285 {
01286 errno = ACE::map_errno (this->errnum ());
01287 ACE_TCHAR *lpMsgBuf = 0;
01288
01289
01290
01291 # if !defined (ACE_HAS_PHARLAP)
01292 ACE_TEXT_FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
01293 | FORMAT_MESSAGE_MAX_WIDTH_MASK
01294 | FORMAT_MESSAGE_FROM_SYSTEM,
01295 0,
01296 errno,
01297 MAKELANGID (LANG_NEUTRAL,
01298 SUBLANG_DEFAULT),
01299
01300 (ACE_TCHAR *) &lpMsgBuf,
01301 0,
01302 0);
01303 # endif
01304
01305
01306
01307
01308
01309
01310
01311 ACE_TCHAR *str = va_arg (argp, ACE_TCHAR *);
01312 if (lpMsgBuf == 0)
01313 {
01314 const ACE_TCHAR *message =
01315 ACE::sock_error (errno);
01316 ACE_OS::strcpy (fp, ACE_TEXT ("s: %s"));
01317 if (can_check)
01318 this_len = ACE_OS::snprintf
01319 (bp, bspace, format,
01320 str ? str : ACE_TEXT ("(null)"),
01321 message);
01322 else
01323 this_len = ACE_OS::sprintf
01324 (bp, format,
01325 str ? str : ACE_TEXT ("(null)"),
01326 message);
01327 }
01328 else
01329 {
01330 ACE_OS::strcpy (fp, ACE_TEXT ("s: %s"));
01331 if (can_check)
01332 this_len = ACE_OS::snprintf
01333 (bp, bspace, format,
01334 str ? str : ACE_TEXT ("(null)"),
01335 lpMsgBuf);
01336 else
01337 this_len = ACE_OS::sprintf
01338 (bp, format,
01339 str ? str : ACE_TEXT ("(null)"),
01340 lpMsgBuf);
01341
01342 ::LocalFree (lpMsgBuf);
01343 }
01344 }
01345 #endif
01346 ACE_UPDATE_COUNT (bspace, this_len);
01347 break;
01348 }
01349
01350 case 'M':
01351
01352
01353
01354
01355
01356
01357 if (format[1] == ACE_TEXT('.') &&
01358 format[2] == ACE_TEXT('1'))
01359 {
01360
01361
01362 fp = format;
01363 fp++;
01364
01365 # if defined (ACE_USES_WCHAR)
01366
01367 # if defined (ACE_WIN32) // Windows uses 'c' for a wide character
01368 ACE_OS::strcpy (fp, ACE_TEXT ("c"));
01369 # else // Other platforms behave differently
01370 # if defined (HPUX) // HP-Unix compatible
01371 ACE_OS::strcpy (fp, ACE_TEXT ("C"));
01372 # else // Other
01373 ACE_OS::strcpy (fp, ACE_TEXT ("lc"));
01374 # endif
01375 # endif
01376
01377 # else
01378
01379
01380 ACE_OS::strcpy (fp, ACE_TEXT ("c"));
01381
01382 # endif
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400 if (can_check)
01401 {
01402 this_len = ACE_OS::snprintf
01403 (bp, bspace, format,
01404 #if !defined (ACE_USES_WCHAR) || defined (ACE_WIN32)
01405 (int)
01406 #else
01407 (wint_t)
01408 #endif
01409 (log_priority <= LM_WARNING) ?
01410 (log_priority <= LM_DEBUG) ?
01411 (log_priority <= LM_TRACE) ?
01412 (log_priority == LM_SHUTDOWN) ?
01413 ACE_TEXT('S') : ACE_TEXT('T') : ACE_TEXT('D') :
01414 (log_priority <= LM_NOTICE) ?
01415 (log_priority == LM_INFO) ?
01416 ACE_TEXT('I') : ACE_TEXT('N') : ACE_TEXT('W') :
01417 (log_priority <= LM_CRITICAL) ?
01418 (log_priority <= LM_ERROR) ?
01419 (log_priority == LM_STARTUP) ?
01420 ACE_TEXT('U') : ACE_TEXT('E') : ACE_TEXT('C') :
01421 (log_priority <= LM_EMERGENCY) ?
01422 (log_priority == LM_ALERT) ?
01423 ACE_TEXT('A') : ACE_TEXT('!') : ACE_TEXT('?'));
01424 }
01425 else
01426 {
01427 this_len = ACE_OS::sprintf
01428 (bp, format,
01429 #if !defined (ACE_USES_WCHAR) || defined (ACE_WIN32)
01430 (int)
01431 #else
01432 (wint_t)
01433 #endif
01434 (log_priority <= LM_WARNING) ?
01435 (log_priority <= LM_DEBUG) ?
01436 (log_priority <= LM_TRACE) ?
01437 (log_priority == LM_SHUTDOWN) ?
01438 ACE_TEXT('S') : ACE_TEXT('T') : ACE_TEXT('D') :
01439 (log_priority <= LM_NOTICE) ?
01440 (log_priority == LM_INFO) ?
01441 ACE_TEXT('I') : ACE_TEXT('N') : ACE_TEXT('W') :
01442 (log_priority <= LM_CRITICAL) ?
01443 (log_priority <= LM_ERROR) ?
01444 (log_priority == LM_STARTUP) ?
01445 ACE_TEXT('U') : ACE_TEXT('E') : ACE_TEXT('C') :
01446 (log_priority <= LM_EMERGENCY) ?
01447 (log_priority == LM_ALERT) ?
01448 ACE_TEXT('A') : ACE_TEXT('!') : ACE_TEXT('?'));
01449 }
01450
01451 ACE_UPDATE_COUNT (bspace, this_len);
01452 }
01453 else
01454 {
01455
01456
01457 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
01458 ACE_OS::strcpy (fp, ACE_TEXT ("ls"));
01459 #else
01460 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01461 #endif
01462 if (can_check)
01463 this_len = ACE_OS::snprintf
01464 (bp, bspace, format,
01465 ACE_Log_Record::priority_name (log_priority));
01466 else
01467 this_len = ACE_OS::sprintf
01468 (bp, format,
01469 ACE_Log_Record::priority_name (log_priority));
01470 ACE_UPDATE_COUNT (bspace, this_len);
01471 }
01472 break;
01473
01474 case 'm':
01475 {
01476 errno = 0;
01477 char *msg = ACE_OS::strerror (ACE::map_errno (this->errnum ()));
01478
01479
01480 #if defined (ACE_WIN32)
01481 if (errno == 0)
01482 {
01483 #endif
01484
01485 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
01486 ACE_OS::strcpy (fp, ACE_TEXT ("ls"));
01487 #else
01488 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01489 #endif
01490 if (can_check)
01491 this_len = ACE_OS::snprintf
01492 (bp, bspace, format, ACE_TEXT_CHAR_TO_TCHAR (msg));
01493 else
01494 this_len = ACE_OS::sprintf
01495 (bp, format, ACE_TEXT_CHAR_TO_TCHAR (msg));
01496 #if defined (ACE_WIN32)
01497 }
01498 else
01499 {
01500 errno = ACE::map_errno (this->errnum ());
01501 ACE_TCHAR *lpMsgBuf = 0;
01502
01503
01504
01505 # if !defined (ACE_HAS_PHARLAP)
01506 ACE_TEXT_FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
01507 | FORMAT_MESSAGE_MAX_WIDTH_MASK
01508 | FORMAT_MESSAGE_FROM_SYSTEM,
01509 0,
01510 errno,
01511 MAKELANGID (LANG_NEUTRAL,
01512 SUBLANG_DEFAULT),
01513
01514 (ACE_TCHAR *) &lpMsgBuf,
01515 0,
01516 0);
01517 # endif
01518
01519
01520
01521
01522
01523
01524
01525 if (lpMsgBuf == 0)
01526 {
01527 const ACE_TCHAR *message =
01528 ACE::sock_error (errno);
01529 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01530 if (can_check)
01531 this_len = ACE_OS::snprintf
01532 (bp, bspace, format, message);
01533 else
01534 this_len = ACE_OS::sprintf (bp, format, message);
01535 }
01536 else
01537 {
01538 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01539 if (can_check)
01540 this_len = ACE_OS::snprintf
01541 (bp, bspace, format, lpMsgBuf);
01542 else
01543 this_len = ACE_OS::sprintf
01544 (bp, format, lpMsgBuf);
01545
01546 ::LocalFree (lpMsgBuf);
01547 }
01548 }
01549 #endif
01550 ACE_UPDATE_COUNT (bspace, this_len);
01551 break;
01552 }
01553
01554 case 'R':
01555 this->op_status (va_arg (argp, int));
01556 ACE_OS::strcpy (fp, ACE_TEXT ("d"));
01557 if (can_check)
01558 this_len = ACE_OS::snprintf
01559 (bp, bspace, format, this->op_status ());
01560 else
01561 this_len = ACE_OS::sprintf
01562 (bp, format, this->op_status ());
01563 ACE_UPDATE_COUNT (bspace, this_len);
01564 break;
01565
01566 case '{':
01567 skip_nul_locate = true;
01568 (void) this->inc ();
01569 break;
01570
01571 case '}':
01572 skip_nul_locate = true;
01573 (void) this->dec ();
01574 break;
01575
01576 case '$':
01577
01578 *bp++ = '\n';
01579 --bspace;
01580
01581
01582 case 'I':
01583
01584
01585 #if defined (ACE_HAS_TRACE)
01586 if (0 == wp)
01587 wp = ACE_Trace::get_nesting_indent ();
01588 #else
01589 if (0 == wp)
01590 wp = 4;
01591 #endif
01592 wp *= this->trace_depth_;
01593 if (static_cast<size_t> (wp) > bspace)
01594 wp = static_cast<int> (bspace);
01595 for (tmp_indent = wp;
01596 tmp_indent;
01597 --tmp_indent)
01598 *bp++ = ' ';
01599
01600 *bp = '\0';
01601 bspace -= static_cast<size_t> (wp);
01602 skip_nul_locate = true;
01603 break;
01604
01605 case 'r':
01606 {
01607 ptrdiff_t const osave = ACE_Log_Msg::msg_off_;
01608
01609 if (ACE_BIT_ENABLED (ACE_Log_Msg::flags_,
01610 ACE_Log_Msg::SILENT) &&
01611 bspace > 1)
01612 {
01613 *bp++ = '{';
01614 --bspace;
01615 }
01616 ACE_Log_Msg::msg_off_ = bp - this->msg_;
01617
01618 (*va_arg (argp, PTF))();
01619
01620 if (ACE_BIT_ENABLED (ACE_Log_Msg::flags_,
01621 ACE_Log_Msg::SILENT) &&
01622 bspace > (1 + ACE_OS::strlen (bp)))
01623 {
01624 bspace -= (ACE_OS::strlen (bp) + 1);
01625 bp += ACE_OS::strlen (bp);
01626 *bp++ = '}';
01627 }
01628 *bp = '\0';
01629 skip_nul_locate = true;
01630 ACE_Log_Msg::msg_off_ = osave;
01631 break;
01632 }
01633
01634 case 'S':
01635 {
01636 const int sig = va_arg (argp, int);
01637 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01638 if (can_check)
01639 this_len = ACE_OS::snprintf
01640 (bp, bspace, format, ACE_OS::strsignal(sig));
01641 else
01642 this_len = ACE_OS::sprintf
01643 (bp, format, ACE_OS::strsignal(sig));
01644 ACE_UPDATE_COUNT (bspace, this_len);
01645 break;
01646 }
01647
01648 case 'D':
01649
01650 {
01651 ACE_TCHAR day_and_time[35];
01652
01653 if (format[1] == ACE_TEXT('#'))
01654 {
01655 ACE_Time_Value* time_value = va_arg (argp, ACE_Time_Value*);
01656 ACE::timestamp (*time_value,
01657 day_and_time,
01658 sizeof day_and_time / sizeof (ACE_TCHAR));
01659 }
01660 else
01661 {
01662 ACE::timestamp (day_and_time,
01663 sizeof day_and_time / sizeof (ACE_TCHAR));
01664 }
01665 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
01666 ACE_OS::strcpy (fp, ACE_TEXT ("ls"));
01667 #else
01668 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01669 #endif
01670 if (can_check)
01671 this_len = ACE_OS::snprintf
01672 (bp, bspace, format, day_and_time);
01673 else
01674 this_len = ACE_OS::sprintf (bp, format, day_and_time);
01675 ACE_UPDATE_COUNT (bspace, this_len);
01676 break;
01677 }
01678
01679 case 'T':
01680
01681 {
01682 ACE_TCHAR day_and_time[35];
01683 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
01684 ACE_OS::strcpy (fp, ACE_TEXT ("ls"));
01685 #else
01686 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01687 #endif
01688
01689 if (format[1] == ACE_TEXT('#'))
01690 {
01691 ACE_Time_Value* time_value = va_arg (argp, ACE_Time_Value*);
01692 if (can_check)
01693 this_len = ACE_OS::snprintf
01694 (bp, bspace, format,
01695 ACE::timestamp (*time_value,
01696 day_and_time,
01697 sizeof day_and_time / sizeof (ACE_TCHAR)));
01698 else
01699 this_len = ACE_OS::sprintf
01700 (bp, format, ACE::timestamp (*time_value,
01701 day_and_time,
01702 sizeof day_and_time / sizeof (ACE_TCHAR)));
01703 }
01704 else
01705 {
01706 if (can_check)
01707 this_len = ACE_OS::snprintf
01708 (bp, bspace, format,
01709 ACE::timestamp (day_and_time, sizeof day_and_time / sizeof (ACE_TCHAR)));
01710 else
01711 this_len = ACE_OS::sprintf
01712 (bp, format, ACE::timestamp (day_and_time,
01713 sizeof day_and_time / sizeof (ACE_TCHAR)));
01714 }
01715 ACE_UPDATE_COUNT (bspace, this_len);
01716 break;
01717 }
01718
01719 case 't':
01720 #if defined (ACE_WIN32)
01721 ACE_OS::strcpy (fp, ACE_TEXT ("u"));
01722 if (can_check)
01723 this_len = ACE_OS::snprintf
01724 (bp, bspace, format,
01725 static_cast<unsigned> (ACE_Thread::self ()));
01726 else
01727 this_len =
01728 ACE_OS::sprintf (bp,
01729 format,
01730 static_cast <unsigned> (ACE_Thread::self ()));
01731 #elif defined (DIGITAL_UNIX)
01732 ACE_OS::strcpy (fp, ACE_TEXT ("u"));
01733 {
01734 int id =
01735 # if defined (ACE_HAS_THREADS)
01736 pthread_getselfseq_np ();
01737 # else
01738 ACE_Thread::self ();
01739 # endif
01740
01741 if (can_check)
01742 this_len = ACE_OS::snprintf (bp, bspace, format, id);
01743 else
01744 this_len = ACE_OS::sprintf (bp, format, id);
01745 }
01746 #else
01747 ACE_hthread_t t_id;
01748 ACE_Thread::self (t_id);
01749
01750 # if defined (ACE_MVS) || defined (ACE_TANDEM_T1248_PTHREADS)
01751
01752
01753 ACE_OS::strcpy (fp, ACE_TEXT ("u"));
01754 if (can_check)
01755 this_len = ACE_OS::snprintf (bp, bspace, format, t_id);
01756 else
01757 this_len = ACE_OS::sprintf (bp, format, t_id);
01758 # else
01759
01760
01761
01762
01763
01764 ACE_OS::strcpy (fp, ACE_TEXT ("lu"));
01765 if (can_check)
01766 this_len = ACE_OS::snprintf
01767 (bp, bspace, format, (unsigned long)t_id);
01768 else
01769 this_len = ACE_OS::sprintf
01770 (bp, format, (unsigned long)t_id);
01771 # endif
01772
01773 #endif
01774 ACE_UPDATE_COUNT (bspace, this_len);
01775 break;
01776
01777 case 's':
01778 {
01779 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
01780 wchar_t *str = va_arg (argp, wchar_t *);
01781 ACE_OS::strcpy (fp, ACE_TEXT ("ls"));
01782 #else
01783 ACE_TCHAR *str = va_arg (argp, ACE_TCHAR *);
01784 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01785 #endif
01786 if (can_check)
01787 this_len = ACE_OS::snprintf
01788 (bp, bspace, format, str ? str : ACE_TEXT ("(null)"));
01789 else
01790 this_len = ACE_OS::sprintf
01791 (bp, format, str ? str : ACE_TEXT ("(null)"));
01792 ACE_UPDATE_COUNT (bspace, this_len);
01793 }
01794 break;
01795
01796 case 'C':
01797 {
01798 char *cstr = va_arg (argp, char *);
01799 #if defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
01800 ACE_OS::strcpy (fp, ACE_TEXT ("S"));
01801 #else
01802 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01803 #endif
01804 if (can_check)
01805 this_len = ACE_OS::snprintf
01806 (bp, bspace, format, cstr ? cstr : "(null)");
01807 else
01808 this_len = ACE_OS::sprintf
01809 (bp, format, cstr ? cstr : "(null)");
01810 ACE_UPDATE_COUNT (bspace, this_len);
01811 }
01812 break;
01813
01814 case 'W':
01815 {
01816 #if defined (ACE_HAS_WCHAR)
01817 wchar_t *wchar_str = va_arg (argp, wchar_t *);
01818 # if defined (HPUX)
01819 ACE_OS::strcpy (fp, ACE_TEXT ("S"));
01820 # elif defined (ACE_WIN32)
01821 # if defined (ACE_USES_WCHAR)
01822 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01823 # else
01824 ACE_OS::strcpy (fp, ACE_TEXT ("S"));
01825 # endif
01826 # else
01827 ACE_OS::strcpy (fp, ACE_TEXT ("ls"));
01828 # endif
01829 if (can_check)
01830 this_len = ACE_OS::snprintf
01831 (bp, bspace, format, wchar_str ? wchar_str : ACE_TEXT_WIDE("(null)"));
01832 else
01833 this_len = ACE_OS::sprintf
01834 (bp, format, wchar_str ? wchar_str : ACE_TEXT_WIDE("(null)"));
01835 #endif
01836 ACE_UPDATE_COUNT (bspace, this_len);
01837 }
01838 break;
01839
01840 case 'w':
01841 #if defined (ACE_WIN32)
01842 # if defined (ACE_USES_WCHAR)
01843 ACE_OS::strcpy (fp, ACE_TEXT ("c"));
01844 # else
01845 ACE_OS::strcpy (fp, ACE_TEXT ("C"));
01846 # endif
01847 if (can_check)
01848 this_len = ACE_OS::snprintf
01849 (bp, bspace, format, va_arg (argp, int));
01850 else
01851 this_len = ACE_OS::sprintf
01852 (bp, format, va_arg (argp, int));
01853 #elif defined (ACE_USES_WCHAR)
01854 # if defined (HPUX)
01855 ACE_OS::strcpy (fp, ACE_TEXT ("C"));
01856 # else
01857 ACE_OS::strcpy (fp, ACE_TEXT ("lc"));
01858 # endif
01859 if (can_check)
01860 this_len = ACE_OS::snprintf
01861 (bp, bspace, format, va_arg (argp, wint_t));
01862 else
01863 this_len = ACE_OS::sprintf
01864 (bp, format, va_arg (argp, wint_t));
01865 #else
01866 ACE_OS::strcpy (fp, ACE_TEXT ("u"));
01867 if (can_check)
01868 this_len = ACE_OS::snprintf
01869 (bp, bspace, format, va_arg (argp, int));
01870 else
01871 this_len = ACE_OS::sprintf
01872 (bp, format, va_arg (argp, int));
01873 #endif
01874 ACE_UPDATE_COUNT (bspace, this_len);
01875 break;
01876
01877 case 'z':
01878 {
01879
01880
01881 wchar_t wtchar =
01882 static_cast<wchar_t> (va_arg (argp, int));
01883 #if defined (ACE_WIN32)
01884 # if defined (ACE_USES_WCHAR)
01885 ACE_OS::strcpy (fp, ACE_TEXT ("c"));
01886 # else
01887 ACE_OS::strcpy (fp, ACE_TEXT ("C"));
01888 # endif
01889 #elif defined (ACE_USES_WCHAR)
01890 # if defined (HPUX)
01891 ACE_OS::strcpy (fp, ACE_TEXT ("C"));
01892 # else
01893 ACE_OS::strcpy (fp, ACE_TEXT ("lc"));
01894 # endif
01895 #else
01896 ACE_OS::strcpy (fp, ACE_TEXT ("u"));
01897 #endif
01898 if (can_check)
01899 this_len = ACE_OS::snprintf (bp, bspace, format, wtchar);
01900 else
01901 this_len = ACE_OS::sprintf (bp, format, wtchar);
01902 ACE_UPDATE_COUNT (bspace, this_len);
01903 break;
01904 }
01905
01906 case 'Z':
01907 {
01908 ACE_OS::WChar *wchar_str = va_arg (argp, ACE_OS::WChar*);
01909 if (wchar_str == 0)
01910 break;
01911
01912 wchar_t *wchar_t_str = 0;
01913 if (sizeof (ACE_OS::WChar) != sizeof (wchar_t))
01914 {
01915 size_t len = ACE_OS::wslen (wchar_str) + 1;
01916 ACE_NEW_NORETURN(wchar_t_str, wchar_t[len]);
01917 if (wchar_t_str == 0)
01918 break;
01919
01920 for (size_t i = 0; i < len; ++i)
01921 {
01922 wchar_t_str[i] = wchar_str[i];
01923 }
01924 }
01925
01926 if (wchar_t_str == 0)
01927 {
01928 wchar_t_str = reinterpret_cast<wchar_t*> (wchar_str);
01929 }
01930 #if defined (ACE_WIN32)
01931 # if defined (ACE_USES_WCHAR)
01932 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
01933 # else
01934 ACE_OS::strcpy (fp, ACE_TEXT ("S"));
01935 # endif
01936 #elif defined (ACE_HAS_WCHAR)
01937 # if defined (HPUX)
01938 ACE_OS::strcpy (fp, ACE_TEXT ("S"));
01939 # else
01940 ACE_OS::strcpy (fp, ACE_TEXT ("ls"));
01941 # endif
01942 #endif
01943 if (can_check)
01944 this_len = ACE_OS::snprintf
01945 (bp, bspace, format, wchar_t_str);
01946 else
01947 this_len = ACE_OS::sprintf (bp, format, wchar_t_str);
01948 if(sizeof(ACE_OS::WChar) != sizeof(wchar_t))
01949 {
01950 delete [] wchar_t_str;
01951 }
01952 ACE_UPDATE_COUNT (bspace, this_len);
01953 break;
01954 }
01955
01956 case 'c':
01957 #if defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
01958 ACE_OS::strcpy (fp, ACE_TEXT ("C"));
01959 #else
01960 ACE_OS::strcpy (fp, ACE_TEXT ("c"));
01961 #endif
01962 if (can_check)
01963 this_len = ACE_OS::snprintf
01964 (bp, bspace, format, va_arg (argp, int));
01965 else
01966 this_len = ACE_OS::sprintf
01967 (bp, format, va_arg (argp, int));
01968 ACE_UPDATE_COUNT (bspace, this_len);
01969 break;
01970
01971 case 'd': case 'i': case 'o':
01972 case 'u': case 'x': case 'X':
01973 fp[0] = *format_str;
01974 fp[1] = '\0';
01975 if (can_check)
01976 this_len = ACE_OS::snprintf
01977 (bp, bspace, format, va_arg (argp, int));
01978 else
01979 this_len = ACE_OS::sprintf
01980 (bp, format, va_arg (argp, int));
01981 ACE_UPDATE_COUNT (bspace, this_len);
01982 break;
01983
01984 case 'F': case 'f': case 'e': case 'E':
01985 case 'g': case 'G':
01986 fp[0] = *format_str;
01987 fp[1] = '\0';
01988 if (can_check)
01989 this_len = ACE_OS::snprintf
01990 (bp, bspace, format, va_arg (argp, double));
01991 else
01992 this_len = ACE_OS::sprintf
01993 (bp, format, va_arg (argp, double));
01994 ACE_UPDATE_COUNT (bspace, this_len);
01995 break;
01996
01997 case 'Q':
01998 #if defined (ACE_LACKS_LONGLONG_T) || defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
01999 {
02000
02001 ACE_UINT32 hi = va_arg (argp, ACE_UINT32);
02002 ACE_UINT32 lo = va_arg (argp, ACE_UINT32);
02003 if (hi > 0)
02004 this_len = ACE_OS::sprintf (bp,
02005 "0x%lx%0*lx",
02006 hi,
02007 2 * sizeof lo,
02008 lo);
02009 else
02010 this_len = ACE_OS::sprintf (bp, "0x%lx", lo);
02011 }
02012 #else
02013 {
02014 const ACE_TCHAR *fmt = ACE_UINT64_FORMAT_SPECIFIER;
02015 ACE_OS::strcpy (fp, &fmt[1]);
02016 if (can_check)
02017 this_len = ACE_OS::snprintf (bp, bspace,
02018 format,
02019 va_arg (argp, ACE_UINT64));
02020 else
02021 this_len = ACE_OS::sprintf (bp,
02022 format,
02023 va_arg (argp, ACE_UINT64));
02024 }
02025 #endif
02026 ACE_UPDATE_COUNT (bspace, this_len);
02027 break;
02028
02029 case 'q':
02030 #if defined (ACE_LACKS_LONGLONG_T)
02031
02032
02033 #else
02034 {
02035 const ACE_TCHAR *fmt = ACE_INT64_FORMAT_SPECIFIER;
02036 ACE_OS::strcpy (fp, &fmt[1]);
02037 if (can_check)
02038 this_len = ACE_OS::snprintf (bp, bspace,
02039 format,
02040 va_arg (argp, ACE_INT64));
02041 else
02042 this_len = ACE_OS::sprintf (bp,
02043 format,
02044 va_arg (argp, ACE_INT64));
02045 }
02046 #endif
02047 ACE_UPDATE_COUNT (bspace, this_len);
02048 break;
02049
02050 case 'b':
02051 {
02052 const ACE_TCHAR *fmt = ACE_SSIZE_T_FORMAT_SPECIFIER;
02053 ACE_OS::strcpy (fp, &fmt[1]);
02054 }
02055 if (can_check)
02056 this_len = ACE_OS::snprintf (bp, bspace,
02057 format,
02058 va_arg (argp, ssize_t));
02059 else
02060 this_len = ACE_OS::sprintf (bp,
02061 format,
02062 va_arg (argp, ssize_t));
02063 ACE_UPDATE_COUNT (bspace, this_len);
02064 break;
02065
02066 case 'B':
02067 {
02068 const ACE_TCHAR *fmt = ACE_SIZE_T_FORMAT_SPECIFIER;
02069 ACE_OS::strcpy (fp, &fmt[1]);
02070 }
02071 if (can_check)
02072 this_len = ACE_OS::snprintf (bp, bspace,
02073 format,
02074 va_arg (argp, size_t));
02075 else
02076 this_len = ACE_OS::sprintf (bp,
02077 format,
02078 va_arg (argp, size_t));
02079 ACE_UPDATE_COUNT (bspace, this_len);
02080 break;
02081
02082 case ':':
02083 {
02084
02085 const ACE_TCHAR *fmt = ACE_TEXT ("%d");
02086 if (sizeof (time_t) == 8)
02087 fmt = ACE_INT64_FORMAT_SPECIFIER;
02088
02089 ACE_OS::strcpy (fp, &fmt[1]);
02090 }
02091 if (can_check)
02092 this_len = ACE_OS::snprintf (bp, bspace,
02093 format,
02094 va_arg (argp, time_t));
02095 else
02096 this_len = ACE_OS::sprintf (bp,
02097 format,
02098 va_arg (argp, time_t));
02099 ACE_UPDATE_COUNT (bspace, this_len);
02100 break;
02101
02102 case '@':
02103 ACE_OS::strcpy (fp, ACE_TEXT ("p"));
02104 if (can_check)
02105 this_len = ACE_OS::snprintf
02106 (bp, bspace, format, va_arg (argp, void*));
02107 else
02108 this_len = ACE_OS::sprintf
02109 (bp, format, va_arg (argp, void*));
02110 ACE_UPDATE_COUNT (bspace, this_len);
02111 break;
02112
02113 case '?':
02114
02115 {
02116
02117 ACE_Stack_Trace t(2);
02118 ACE_OS::strcpy (fp, ACE_TEXT ("s"));
02119 if (can_check)
02120 this_len = ACE_OS::snprintf
02121 (bp, bspace, format, t.c_str ());
02122 else
02123 this_len = ACE_OS::sprintf
02124 (bp, format, t.c_str ());
02125 ACE_UPDATE_COUNT (bspace, this_len);
02126 break;
02127 }
02128
02129
02130 default:
02131
02132
02133
02134 while (start_format != format_str && bspace > 0)
02135 {
02136 *bp++ = *start_format++;
02137 --bspace;
02138 }
02139 if (bspace > 0)
02140 {
02141 *bp++ = *format_str;
02142 --bspace;
02143 }
02144 break;
02145 }
02146
02147
02148 ++format_str;
02149 }
02150
02151 if (!skip_nul_locate)
02152 while (*bp != '\0')
02153 ++bp;
02154 }
02155 }
02156
02157 *bp = '\0';
02158
02159 ssize_t result = 0;
02160
02161
02162
02163 if (bp >= (this->msg_ + ACE_MAXLOGMSGLEN+1))
02164 {
02165 abort_prog = true;
02166 ACE_OS::fprintf (stderr,
02167 "The following logged message is too long!\n");
02168 }
02169 else
02170 {
02171
02172
02173 log_record.msg_data (this->msg ());
02174
02175
02176 result = this->log (log_record,
02177 abort_prog);
02178 }
02179
02180 if (abort_prog)
02181 {
02182
02183
02184 ACE_UNUSED_ARG (exit_value);
02185
02186
02187
02188
02189 log_record.print (ACE_Log_Msg::local_host_, 0, stderr);
02190 ACE_OS::abort ();
02191 }
02192
02193 return result;
02194 }
02195
02196 #if !defined (ACE_WIN32)
02197
02198
02199
02200
02201
02202
02203
02204
02205 class ACE_Log_Msg_Sig_Guard
02206 {
02207 private:
02208 ACE_Log_Msg_Sig_Guard (void);
02209 ~ACE_Log_Msg_Sig_Guard (void);
02210
02211
02212 sigset_t omask_;
02213
02214 friend ssize_t ACE_Log_Msg::log (ACE_Log_Record &log_record,
02215 int suppress_stderr);
02216 };
02217
02218 ACE_Log_Msg_Sig_Guard::ACE_Log_Msg_Sig_Guard (void)
02219 {
02220 #if !defined (ACE_LACKS_UNIX_SIGNALS)
02221 ACE_OS::sigemptyset (&this->omask_);
02222
02223 # if defined (ACE_LACKS_PTHREAD_THR_SIGSETMASK)
02224 ACE_OS::sigprocmask (SIG_BLOCK,
02225 ACE_OS_Object_Manager::default_mask (),
02226 &this->omask_);
02227 # else
02228 ACE_OS::thr_sigsetmask (SIG_BLOCK,
02229 ACE_OS_Object_Manager::default_mask (),
02230 &this->omask_);
02231 # endif
02232 #endif
02233 }
02234
02235 ACE_Log_Msg_Sig_Guard::~ACE_Log_Msg_Sig_Guard (void)
02236 {
02237 #if !defined (ACE_LACKS_UNIX_SIGNALS)
02238 # if defined (ACE_LACKS_PTHREAD_THR_SIGSETMASK)
02239 ACE_OS::sigprocmask (SIG_SETMASK,
02240 &this->omask_,
02241 0);
02242 # else
02243 ACE_OS::thr_sigsetmask (SIG_SETMASK,
02244 &this->omask_,
02245 0);
02246 # endif
02247 #endif
02248 }
02249 #endif
02250
02251 ssize_t
02252 ACE_Log_Msg::log (ACE_Log_Record &log_record,
02253 int suppress_stderr)
02254 {
02255 ssize_t result = 0;
02256
02257
02258
02259
02260 if (ACE_BIT_DISABLED (ACE_Log_Msg::flags_,
02261 ACE_Log_Msg::SILENT))
02262 {
02263 bool tracing = this->tracing_enabled ();
02264 this->stop_tracing ();
02265
02266 #if !defined (ACE_WIN32)
02267
02268 ACE_Log_Msg_Sig_Guard sb;
02269 #endif
02270
02271
02272
02273
02274 if (ACE_BIT_ENABLED (ACE_Log_Msg::flags_,
02275 ACE_Log_Msg::MSG_CALLBACK)
02276 && this->msg_callback () != 0)
02277 this->msg_callback ()->log (log_record);
02278
02279
02280 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
02281 *ACE_Log_Msg_Manager::get_lock (),
02282 -1));
02283
02284 if (ACE_BIT_ENABLED (ACE_Log_Msg::flags_,
02285 ACE_Log_Msg::STDERR)
02286 && !suppress_stderr)
02287 log_record.print (ACE_Log_Msg::local_host_,
02288 ACE_Log_Msg::flags_,
02289 stderr);
02290
02291 if (ACE_BIT_ENABLED (ACE_Log_Msg::flags_, ACE_Log_Msg::CUSTOM) ||
02292 ACE_BIT_ENABLED (ACE_Log_Msg::flags_, ACE_Log_Msg::SYSLOG) ||
02293 ACE_BIT_ENABLED (ACE_Log_Msg::flags_, ACE_Log_Msg::LOGGER))
02294 {
02295
02296 ACE_MT (ACE_Log_Msg_Manager::init_backend ());
02297 }
02298
02299
02300 if (ACE_BIT_ENABLED (ACE_Log_Msg::flags_, ACE_Log_Msg::LOGGER) ||
02301 ACE_BIT_ENABLED (ACE_Log_Msg::flags_, ACE_Log_Msg::SYSLOG))
02302 {
02303 result =
02304 ACE_Log_Msg_Manager::log_backend_->log (log_record);
02305 }
02306
02307 if (ACE_BIT_ENABLED (ACE_Log_Msg::flags_, ACE_Log_Msg::CUSTOM) &&
02308 ACE_Log_Msg_Manager::custom_backend_ != 0)
02309 {
02310 result =
02311 ACE_Log_Msg_Manager::custom_backend_->log (log_record);
02312 }
02313
02314
02315
02316 if (ACE_BIT_ENABLED (ACE_Log_Msg::flags_,
02317 ACE_Log_Msg::OSTREAM)
02318 && this->msg_ostream () != 0)
02319 log_record.print (ACE_Log_Msg::local_host_,
02320 ACE_Log_Msg::flags_,
02321 #if defined (ACE_LACKS_IOSTREAM_TOTALLY)
02322 static_cast<FILE *> (this->msg_ostream ())
02323 #else
02324 *this->msg_ostream ()
02325 #endif
02326 );
02327
02328 if (tracing)
02329 this->start_tracing ();
02330 }
02331
02332 return result;
02333 }
02334
02335
02336
02337 int
02338 ACE_Log_Msg::log_hexdump (ACE_Log_Priority log_priority,
02339 const char *buffer,
02340 size_t size,
02341 const ACE_TCHAR *text)
02342 {
02343
02344
02345 if (this->log_priority_enabled (log_priority) == 0)
02346 return 0;
02347
02348 ACE_TCHAR* buf = 0;
02349 size_t const buf_sz =
02350 ACE_Log_Record::MAXLOGMSGLEN - ACE_Log_Record::VERBOSE_LEN - 58;
02351 ACE_NEW_RETURN (buf, ACE_TCHAR[buf_sz], -1);
02352
02353 ACE_TCHAR *msg_buf = 0;
02354 const size_t text_sz = text ? ACE_OS::strlen(text) : 0;
02355 ACE_NEW_RETURN (msg_buf,
02356 ACE_TCHAR[text_sz + 58],
02357 -1);
02358
02359 buf[0] = 0;
02360
02361 size_t const len = ACE::format_hexdump
02362 (buffer, size, buf, buf_sz / sizeof (ACE_TCHAR) - text_sz);
02363
02364 int sz = 0;
02365
02366 if (text)
02367 sz = ACE_OS::sprintf (msg_buf,
02368 #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
02369 ACE_TEXT ("%ls - "),
02370 #else
02371 ACE_TEXT ("%s - "),
02372 #endif
02373 text);
02374
02375 sz += ACE_OS::sprintf (msg_buf + sz,
02376 ACE_TEXT ("HEXDUMP ")
02377 ACE_SIZE_T_FORMAT_SPECIFIER
02378 ACE_TEXT (" bytes"),
02379 size);
02380
02381 if (len < size)
02382 ACE_OS::sprintf (msg_buf + sz,
02383 ACE_TEXT (" (showing first ")
02384 ACE_SIZE_T_FORMAT_SPECIFIER
02385 ACE_TEXT (" bytes)"),
02386 len);
02387
02388
02389 this->log (log_priority,
02390 ACE_TEXT ("%s\n%s"),
02391 msg_buf,
02392 buf);
02393
02394 delete [] msg_buf;
02395 delete [] buf;
02396 return 0;
02397 }
02398
02399 void
02400 ACE_Log_Msg::set (const char *file,
02401 int line,
02402 int op_status,
02403 int errnum,
02404 bool restart,
02405 ACE_OSTREAM_TYPE *os,
02406 ACE_Log_Msg_Callback *c)
02407 {
02408 ACE_TRACE ("ACE_Log_Msg::set");
02409 this->file (file);
02410 this->linenum (line);
02411 this->op_status (op_status);
02412 this->errnum (errnum);
02413 this->restart (restart);
02414 this->msg_ostream (os);
02415 this->msg_callback (c);
02416 }
02417
02418 void
02419 ACE_Log_Msg::conditional_set (const char *filename,
02420 int line,
02421 int status,
02422 int err)
02423 {
02424 this->conditional_values_.is_set_ = true;
02425 this->conditional_values_.file_ = filename;
02426 this->conditional_values_.line_ = line;
02427 this->conditional_values_.op_status_ = status;
02428 this->conditional_values_.errnum_ = err;
02429 }
02430
02431 void
02432 ACE_Log_Msg::dump (void) const
02433 {
02434 #if defined (ACE_HAS_DUMP)
02435 ACE_TRACE ("ACE_Log_Msg::dump");
02436
02437 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
02438 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("status_ = %d\n"), this->status_));
02439 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nerrnum_ = %d\n"), this->errnum_));
02440 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nlinenum_ = %d\n"), this->linenum_));
02441 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nfile_ = %C\n"), this->file_));
02442 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmsg_ = %s\n"), this->msg_));
02443 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nrestart_ = %d\n"), this->restart_));
02444 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nostream_ = %@\n"), this->ostream_));
02445 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmsg_callback_ = %@\n"),
02446 this->msg_callback_));
02447 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nprogram_name_ = %s\n"),
02448 this->program_name_ ? this->program_name_
02449 : ACE_TEXT ("<unknown>")));
02450 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nlocal_host_ = %s\n"),
02451 this->local_host_ ? this->local_host_
02452 : ACE_TEXT ("<unknown>")));
02453 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\npid_ = %d\n"), this->getpid ()));
02454 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nflags_ = 0x%x\n"), this->flags_));
02455 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntrace_depth_ = %d\n"),
02456 this->trace_depth_));
02457 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntrace_active_ = %d\n"),
02458 this->trace_active_));
02459 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntracing_enabled_ = %d\n"),
02460 this->tracing_enabled_));
02461 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\npriority_mask_ = 0x%x\n"),
02462 this->priority_mask_));
02463 if (this->thr_desc_ != 0 && this->thr_desc_->state () != 0)
02464 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nthr_state_ = %d\n"),
02465 this->thr_desc_->state ()));
02466 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmsg_off_ = %d\n"), this->msg_off_));
02467
02468
02469 ACE_MT (ACE_Log_Msg_Manager::init_backend ());
02470
02471 ACE_MT (ACE_Log_Msg_Manager::get_lock ()->dump ());
02472
02473
02474 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
02475 #endif
02476 }
02477
02478 void
02479 ACE_Log_Msg::thr_desc (ACE_Thread_Descriptor *td)
02480 {
02481 this->thr_desc_ = td;
02482
02483 if (td != 0)
02484 td->acquire_release ();
02485 }
02486
02487 #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS) && defined(ACE_LEGACY_MODE)
02488 ACE_SEH_EXCEPT_HANDLER
02489 ACE_Log_Msg::seh_except_selector (void)
02490 {
02491 return ACE_OS_Object_Manager::seh_except_selector ();
02492 }
02493
02494 ACE_SEH_EXCEPT_HANDLER
02495 ACE_Log_Msg::seh_except_selector (ACE_SEH_EXCEPT_HANDLER n)
02496 {
02497 return ACE_OS_Object_Manager::seh_except_selector (n);
02498 }
02499
02500 ACE_SEH_EXCEPT_HANDLER
02501 ACE_Log_Msg::seh_except_handler (void)
02502 {
02503 return ACE_OS_Object_Manager::seh_except_handler ();
02504 }
02505
02506 ACE_SEH_EXCEPT_HANDLER
02507 ACE_Log_Msg::seh_except_handler (ACE_SEH_EXCEPT_HANDLER n)
02508 {
02509 return ACE_OS_Object_Manager::seh_except_handler (n);
02510 }
02511 #endif
02512
02513 ACE_Log_Msg_Backend *
02514 ACE_Log_Msg::msg_backend (ACE_Log_Msg_Backend *b)
02515 {
02516 ACE_TRACE ("ACE_Log_Msg::msg_backend");
02517 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
02518 *ACE_Log_Msg_Manager::get_lock (), 0));
02519
02520 ACE_Log_Msg_Backend *tmp = ACE_Log_Msg_Manager::custom_backend_;
02521 ACE_Log_Msg_Manager::custom_backend_ = b;
02522 return tmp;
02523 }
02524
02525 ACE_Log_Msg_Backend *
02526 ACE_Log_Msg::msg_backend (void)
02527 {
02528 ACE_TRACE ("ACE_Log_Msg::msg_backend");
02529 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
02530 *ACE_Log_Msg_Manager::get_lock (), 0));
02531
02532 return ACE_Log_Msg_Manager::custom_backend_;
02533 }
02534
02535 void
02536 ACE_Log_Msg::msg_ostream (ACE_OSTREAM_TYPE *m, bool delete_ostream)
02537 {
02538 if (this->ostream_ == m)
02539 {
02540
02541 if (delete_ostream && !this->ostream_refcount_)
02542 {
02543 ACE_NEW (this->ostream_refcount_, Atomic_ULong (1));
02544 }
02545 else if (!delete_ostream && this->ostream_refcount_)
02546 {
02547 if (--*this->ostream_refcount_ == 0)
02548 {
02549 delete this->ostream_refcount_;
02550 }
02551 this->ostream_refcount_ = 0;
02552 }
02553
02554
02555 return;
02556 }
02557
02558 this->cleanup_ostream ();
02559
02560 if (delete_ostream)
02561 {
02562 ACE_NEW (this->ostream_refcount_, Atomic_ULong (1));
02563 }
02564
02565 this->ostream_ = m;
02566 }
02567
02568 void
02569 ACE_Log_Msg::local_host (const ACE_TCHAR *s)
02570 {
02571 if (s)
02572 {
02573 ACE_OS::free ((void *) ACE_Log_Msg::local_host_);
02574 {
02575 ACE_NO_HEAP_CHECK;
02576
02577 ACE_ALLOCATOR (ACE_Log_Msg::local_host_, ACE_OS::strdup (s));
02578 }
02579 }
02580 }
02581
02582 int
02583 ACE_Log_Msg::log_priority_enabled (ACE_Log_Priority log_priority,
02584 const char *,
02585 ...)
02586 {
02587 return this->log_priority_enabled (log_priority);
02588 }
02589
02590 #if defined (ACE_USES_WCHAR)
02591 int
02592 ACE_Log_Msg::log_priority_enabled (ACE_Log_Priority log_priority,
02593 const wchar_t *,
02594 ...)
02595 {
02596 return this->log_priority_enabled (log_priority);
02597 }
02598 #endif
02599
02600
02601
02602 void
02603 ACE_Log_Msg::init_hook (ACE_OS_Log_Msg_Attributes &attributes
02604 # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
02605 , ACE_SEH_EXCEPT_HANDLER selector
02606 , ACE_SEH_EXCEPT_HANDLER handler
02607 # endif
02608 )
02609 {
02610 # if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS)
02611 attributes.seh_except_selector_ = selector;
02612 attributes.seh_except_handler_ = handler;
02613 # endif
02614 if (ACE_Log_Msg::exists ())
02615 {
02616 ACE_Log_Msg *inherit_log = ACE_LOG_MSG;
02617 attributes.ostream_ = inherit_log->msg_ostream ();
02618 if (attributes.ostream_ && inherit_log->ostream_refcount_)
02619 {
02620 ++*inherit_log->ostream_refcount_;
02621 attributes.ostream_refcount_ = inherit_log->ostream_refcount_;
02622 }
02623 else
02624 {
02625 attributes.ostream_refcount_ = 0;
02626 }
02627 attributes.priority_mask_ = inherit_log->priority_mask ();
02628 attributes.tracing_enabled_ = inherit_log->tracing_enabled ();
02629 attributes.restart_ = inherit_log->restart ();
02630 attributes.trace_depth_ = inherit_log->trace_depth ();
02631 }
02632 }
02633
02634 void
02635 ACE_Log_Msg::inherit_hook (ACE_OS_Thread_Descriptor *thr_desc,
02636 ACE_OS_Log_Msg_Attributes &attributes)
02637 {
02638 #if !defined (ACE_THREADS_DONT_INHERIT_LOG_MSG) && \
02639 !defined (ACE_HAS_MINIMAL_ACE_OS)
02640
02641
02642
02643 ACE_Log_Msg *new_log = ACE_LOG_MSG;
02644
02645
02646
02647
02648
02649 if (attributes.ostream_)
02650 {
02651 new_log->ostream_ = attributes.ostream_;
02652 new_log->ostream_refcount_ =
02653 static_cast<Atomic_ULong *> (attributes.ostream_refcount_);
02654
02655 new_log->priority_mask (attributes.priority_mask_);
02656
02657 if (attributes.tracing_enabled_)
02658 new_log->start_tracing ();
02659
02660 new_log->restart (attributes.restart_);
02661 new_log->trace_depth (attributes.trace_depth_);
02662 }
02663
02664
02665
02666
02667 if (thr_desc != 0)
02668
02669
02670 new_log->thr_desc (static_cast<ACE_Thread_Descriptor *> (thr_desc));
02671
02672
02673 #endif
02674 }
02675
02676 ACE_END_VERSIONED_NAMESPACE_DECL