Examples |
Collaboration diagram for services::logger_service:
Definition at line 16 of file logger_service.hpp.
Public Types | |
typedef logger_impl * | impl_type |
The type for an implementation of the logger. | |
Public Member Functions | |
logger_service (asio::io_service &io_service) | |
Constructor creates a thread to run a private io_service. | |
~logger_service () | |
Destructor shuts down the private io_service. | |
void | shutdown_service () |
Destroy all user-defined handler objects owned by the service. | |
impl_type | null () const |
Return a null logger implementation. | |
void | create (impl_type &impl, const std::string &identifier) |
Create a new logger implementation. | |
void | destroy (impl_type &impl) |
Destroy a logger implementation. | |
void | use_file (impl_type &impl, const std::string &file) |
Set the output file for the logger. The current implementation sets the output file for all logger instances, and so the impl parameter is not actually needed. It is retained here to illustrate how service functions are typically defined. | |
void | log (impl_type &impl, const std::string &message) |
Log a message. | |
Private Member Functions | |
void | use_file_impl (const std::string &file) |
Helper function used to open the output file from within the private io_service's thread. | |
void | log_impl (const std::string &text) |
Helper function used to log a message from within the private io_service's thread. | |
Private Attributes | |
asio::io_service | work_io_service_ |
Private io_service used for performing logging operations. | |
boost::scoped_ptr< asio::io_service::work > | work_ |
Work for the private io_service to perform. If we do not give the io_service some work to do then the io_service::run() function will exit immediately. | |
boost::scoped_ptr< asio::thread > | work_thread_ |
Thread used for running the work io_service's run loop. | |
std::ofstream | ofstream_ |
The file to which log messages will be written. | |
Classes | |
struct | logger_impl |
The backend implementation of a logger. More... |
services::logger_service::logger_service | ( | asio::io_service & | io_service | ) |
Constructor creates a thread to run a private io_service.
Definition at line 31 of file logger_service.hpp.
00032 : asio::io_service::service(io_service), 00033 work_io_service_(), 00034 work_(new asio::io_service::work(work_io_service_)), 00035 work_thread_(new asio::thread( 00036 boost::bind(&asio::io_service::run, &work_io_service_))) 00037 { 00038 }
services::logger_service::~logger_service | ( | ) |
Destructor shuts down the private io_service.
Indicate that we have finished with the private io_service. Its io_service::run() function will exit once all other work has completed.
Definition at line 41 of file logger_service.hpp.
00042 { 00045 work_.reset(); 00046 if (work_thread_) 00047 work_thread_->join();
void services::logger_service::shutdown_service | ( | ) | [virtual] |
Destroy all user-defined handler objects owned by the service.
Implements asio::io_service::service.
Definition at line 50 of file logger_service.hpp.
impl_type services::logger_service::null | ( | ) | const |
void services::logger_service::create | ( | impl_type & | impl, | |
const std::string & | identifier | |||
) |
void services::logger_service::destroy | ( | impl_type & | impl | ) |
Destroy a logger implementation.
Definition at line 67 of file logger_service.hpp.
00069 { 00070 delete impl; 00071 impl = null();
void services::logger_service::use_file | ( | impl_type & | impl, | |
const std::string & | file | |||
) |
Set the output file for the logger. The current implementation sets the output file for all logger instances, and so the impl parameter is not actually needed. It is retained here to illustrate how service functions are typically defined.
Definition at line 74 of file logger_service.hpp.
void services::logger_service::log | ( | impl_type & | impl, | |
const std::string & | message | |||
) |
Log a message.
Definition at line 82 of file logger_service.hpp.
00087 { 00088 // Format the text to be logged. 00089 std::ostringstream os; 00090 os << boost::posix_time::microsec_clock::universal_time(); 00091 os << " - " << impl->identifier << " - " << message; 00092
void services::logger_service::use_file_impl | ( | const std::string & | file | ) | [private] |
Helper function used to open the output file from within the private io_service's thread.
Definition at line 96 of file logger_service.hpp.
00098 : 00101 void use_file_impl(const std::string& file) {
void services::logger_service::log_impl | ( | const std::string & | text | ) | [private] |
Helper function used to log a message from within the private io_service's thread.
Definition at line 104 of file logger_service.hpp.
Private io_service used for performing logging operations.
Definition at line 110 of file logger_service.hpp.
boost::scoped_ptr<asio::io_service::work> services::logger_service::work_ [private] |
Work for the private io_service to perform. If we do not give the io_service some work to do then the io_service::run() function will exit immediately.
Definition at line 113 of file logger_service.hpp.
Referenced by ~logger_service().
boost::scoped_ptr<asio::thread> services::logger_service::work_thread_ [private] |
Thread used for running the work io_service's run loop.
Definition at line 116 of file logger_service.hpp.
Referenced by ~logger_service().
std::ofstream services::logger_service::ofstream_ [private] |