Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / protocols / ace / INet / INet_Log.cpp
blob11cc0af024bb2fc678c9dc23145cc6bd0b5518bf
1 #include "ace/INet/INet_Log.h"
2 #include "ace/Env_Value_T.h"
3 #include "ace/SString.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/streams.h"
7 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
9 namespace ACE
11 unsigned int INet_Log::debug_level_ = INet_Log::Initializer ();
13 unsigned int INet_Log::Initializer()
15 unsigned int debug_level = 0;
16 bool trace = false;
17 ACE_TString filename;
19 ACE_Env_Value<int> log (ACE_TEXT("INET_LOG_LEVEL"), debug_level);
20 debug_level = log;
22 ACE_Env_Value<int> trace_env (ACE_TEXT("INET_TRACE_ENABLE"), 0);
23 trace = (trace_env != 0);
25 ACE_Env_Value<ACE_TString> filename_env (ACE_TEXT("INET_LOG_FILE"), filename.c_str ());
26 filename = filename_env;
28 if (trace)
30 INET_ENABLE_TRACE ();
32 else
34 INET_DISABLE_TRACE ();
37 if (filename.length () > 0)
39 #if defined (ACE_LACKS_IOSTREAM_TOTALLY)
41 FILE* output_stream = ACE_OS::fopen (filename.c_str (), ACE_TEXT ("a"));
43 ACE_LOG_MSG->msg_ostream (output_stream, 1);
45 #else /* ! ACE_LACKS_IOSTREAM_TOTALLY */
47 ofstream* output_stream = 0;
49 ACE_NEW_NORETURN (output_stream,
50 ofstream ());
51 if (output_stream)
53 output_stream->open (ACE_TEXT_ALWAYS_CHAR (filename.c_str ()),
54 ios::out | ios::app);
56 if (!output_stream->bad ())
58 ACE_LOG_MSG->msg_ostream (output_stream, 1);
62 #endif /* ACE_LACKS_IOSTREAM_TOTALLY */
64 ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR | ACE_Log_Msg::LOGGER);
65 ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
68 return debug_level;
73 ACE_END_VERSIONED_NAMESPACE_DECL