Boost C++ Libraries Home Libraries People FAQ More

Home | Reference | Tutorial | Examples | Design

services::logger_service Class Reference

Inherits boost::asio::io_service::service.

Collaboration diagram for services::logger_service:

Collaboration graph
List of all members.

Detailed Description

Service implementation for the logger.

Definition at line 17 of file logger_service.hpp.

Public Types

typedef logger_implimpl_type
 The type for an implementation of the logger.

Public Member Functions

 logger_service (boost::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

boost::asio::io_service work_io_service_
 Private io_service used for performing logging operations.
boost::scoped_ptr< boost::asio::io_service::workwork_
 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< boost::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...


Member Typedef Documentation

typedef logger_impl* services::logger_service::impl_type

The type for an implementation of the logger.

Definition at line 29 of file logger_service.hpp.


Constructor & Destructor Documentation

services::logger_service::logger_service ( boost::asio::io_service io_service  ) 

Constructor creates a thread to run a private io_service.

Definition at line 32 of file logger_service.hpp.

00033     : boost::asio::io_service::service(io_service),
00034       work_io_service_(),
00035       work_(new boost::asio::io_service::work(work_io_service_)),
00036       work_thread_(new boost::thread(
00037             boost::bind(&boost::asio::io_service::run, &work_io_service_)))
00038   {
00039   }

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 42 of file logger_service.hpp.

00043   {
00046     work_.reset();
00047     if (work_thread_)
00048       work_thread_->join();


Member Function Documentation

void services::logger_service::shutdown_service (  )  [virtual]

Destroy all user-defined handler objects owned by the service.

Implements boost::asio::io_service::service.

Definition at line 51 of file logger_service.hpp.

00053   {

impl_type services::logger_service::null (  )  const

Return a null logger implementation.

Definition at line 56 of file logger_service.hpp.

00058   {
00059     return 0;

void services::logger_service::create ( impl_type impl,
const std::string &  identifier 
)

Create a new logger implementation.

Definition at line 62 of file logger_service.hpp.

00064   {
00065     impl = new logger_impl(identifier);

void services::logger_service::destroy ( impl_type impl  ) 

Destroy a logger implementation.

Definition at line 68 of file logger_service.hpp.

00070   {
00071     delete impl;
00072     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 75 of file logger_service.hpp.

00080   {

void services::logger_service::log ( impl_type impl,
const std::string &  message 
)

Log a message.

Definition at line 83 of file logger_service.hpp.

00088   {
00089     // Format the text to be logged.
00090     std::ostringstream os;
00091     os << boost::posix_time::microsec_clock::universal_time();
00092     os << " - " << impl->identifier << " - " << message;
00093 

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 97 of file logger_service.hpp.

00099        :
00102   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 105 of file logger_service.hpp.


Member Data Documentation

boost::asio::io_service services::logger_service::work_io_service_ [private]

Private io_service used for performing logging operations.

Definition at line 111 of file logger_service.hpp.

boost::scoped_ptr<boost::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 114 of file logger_service.hpp.

Referenced by ~logger_service().

boost::scoped_ptr<boost::thread> services::logger_service::work_thread_ [private]

Thread used for running the work io_service's run loop.

Definition at line 117 of file logger_service.hpp.

Referenced by ~logger_service().

std::ofstream services::logger_service::ofstream_ [private]

The file to which log messages will be written.

Definition at line 120 of file logger_service.hpp.


The documentation for this class was generated from the following file:
Copyright © 2003 - 2006 Christopher M. Kohlhoff

Home | Reference | Tutorial | Examples | Design