00001 // $Id: INet_Log.cpp 90928 2010-06-29 11:21:55Z mcorino $ 00002 00003 #include "ace/INet/INet_Log.h" 00004 #include "ace/Env_Value_T.h" 00005 #include "ace/SString.h" 00006 #include "ace/Log_Msg.h" 00007 #include "ace/streams.h" 00008 00009 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00010 00011 namespace ACE 00012 { 00013 unsigned int INet_Log::debug_level_ = INet_Log::Initializer (); 00014 00015 unsigned int INet_Log::Initializer(void) 00016 { 00017 unsigned int debug_level = 0; 00018 bool trace = false; 00019 ACE_TString filename; 00020 00021 ACE_Env_Value<int> log (ACE_TEXT("INET_LOG_LEVEL"), debug_level); 00022 debug_level = log; 00023 00024 ACE_Env_Value<int> trace_env (ACE_TEXT("INET_TRACE_ENABLE"), 0); 00025 trace = (trace_env != 0); 00026 00027 ACE_Env_Value<const ACE_TCHAR *> filename_env (ACE_TEXT("INET_LOG_FILE"), filename.c_str ()); 00028 filename = filename_env; 00029 00030 if (trace) 00031 { 00032 INET_ENABLE_TRACE (); 00033 } 00034 else 00035 { 00036 INET_DISABLE_TRACE (); 00037 } 00038 00039 if (filename.length () > 0) 00040 { 00041 #if defined (ACE_LACKS_IOSTREAM_TOTALLY) 00042 00043 FILE* output_stream = ACE_OS::fopen (filename.c_str (), ACE_TEXT ("a")); 00044 00045 ACE_LOG_MSG->msg_ostream (output_stream, 1); 00046 00047 #else /* ! ACE_LACKS_IOSTREAM_TOTALLY */ 00048 00049 ofstream* output_stream = 0; 00050 00051 ACE_NEW_NORETURN (output_stream, 00052 ofstream ()); 00053 if (output_stream) 00054 { 00055 output_stream->open (ACE_TEXT_ALWAYS_CHAR (filename.c_str ()), 00056 ios::out | ios::app); 00057 00058 if (!output_stream->bad ()) 00059 { 00060 ACE_LOG_MSG->msg_ostream (output_stream, 1); 00061 } 00062 } 00063 00064 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */ 00065 00066 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR | ACE_Log_Msg::LOGGER); 00067 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM); 00068 } 00069 00070 return debug_level; 00071 } 00072 00073 } 00074 00075 ACE_END_VERSIONED_NAMESPACE_DECL