1 #include "ace/streams.h"
3 #include "ace/Singleton.h"
4 #include "ace/Log_Msg.h"
5 #include "ace/Log_Msg_Callback.h"
10 // Listing 1 code/ch03
18 (const ACE_TCHAR
*prog_name
= ACE_TEXT (""));
20 (const ACE_TCHAR
*prog_name
= ACE_TEXT (""));
21 void redirectToOStream (ACE_OSTREAM_TYPE
*output
);
22 void redirectToFile (const char *filename
);
23 void redirectToStderr ();
24 ACE_Log_Msg_Callback
* redirectToCallback
25 (ACE_Log_Msg_Callback
*callback
);
29 ofstream
*log_stream_
;
30 ACE_OSTREAM_TYPE
*output_stream_
;
35 // Listing 2 code/ch03
36 LogManager::LogManager ()
37 : log_stream_ (0), output_stream_ (0)
40 LogManager::~LogManager ()
43 log_stream_
->close ();
47 void LogManager::redirectToSyslog (const ACE_TCHAR
*prog_name
)
49 ACE_LOG_MSG
->open (prog_name
, ACE_Log_Msg::SYSLOG
, prog_name
);
52 void LogManager::redirectToDaemon (const ACE_TCHAR
*prog_name
)
54 ACE_LOG_MSG
->open (prog_name
, ACE_Log_Msg::LOGGER
,
55 ACE_DEFAULT_LOGGER_KEY
);
58 void LogManager::redirectToOStream (ACE_OSTREAM_TYPE
*output
)
60 output_stream_
= output
;
61 ACE_LOG_MSG
->msg_ostream (this->output_stream_
);
62 ACE_LOG_MSG
->clr_flags
63 (ACE_Log_Msg::STDERR
| ACE_Log_Msg::LOGGER
);
64 ACE_LOG_MSG
->set_flags (ACE_Log_Msg::OSTREAM
);
67 void LogManager::redirectToFile (const char *filename
)
69 log_stream_
= new ofstream ();
70 log_stream_
->open (filename
, ios::out
| ios::app
);
71 this->redirectToOStream ((ACE_OSTREAM_TYPE
*)log_stream_
);
74 void LogManager::redirectToStderr ()
76 ACE_LOG_MSG
->clr_flags
77 (ACE_Log_Msg::OSTREAM
| ACE_Log_Msg::LOGGER
);
78 ACE_LOG_MSG
->set_flags (ACE_Log_Msg::STDERR
);
81 ACE_Log_Msg_Callback
*
82 LogManager::redirectToCallback (ACE_Log_Msg_Callback
* callback
)
84 ACE_Log_Msg_Callback
*previous
=
85 ACE_LOG_MSG
->msg_callback (callback
);
87 ACE_LOG_MSG
->clr_flags (ACE_Log_Msg::MSG_CALLBACK
);
89 ACE_LOG_MSG
->set_flags (ACE_Log_Msg::MSG_CALLBACK
);
94 // Listing 3 code/ch03
95 typedef ACE_Singleton
<LogManager
, ACE_Null_Mutex
>
97 #define LOG_MANAGER LogManagerSingleton::instance()
100 #endif /* LOG_MANAGER_H */