asio 0.3.8rc3 | Home | Reference | Tutorial | Examples | Design

Examples |

# services::logger_service Class Reference

Inherits asio::io_service::service.

Collaboration diagram for services::logger_service:

List of all members.

## Detailed Description

Service implementation for the logger.

Definition at line 26 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.

## Static Public Attributes

static asio::io_service::id | id
| The unique service identifier.

## 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...

## Member Typedef Documentation

typedef logger_impl* services::logger_service::impl_type

The type for an implementation of the logger.

Definition at line 41 of file logger_service.hpp.

## Constructor & Destructor Documentation

services::logger_service::logger_service | ( | asio::io_service & | io_service | ) |

Constructor creates a thread to run a private io_service.

Definition at line 44 of file logger_service.hpp.

    00045     : asio::io_service::service(io_service),
    00046       work_io_service_(),
    00047       work_(new asio::io_service::work(work_io_service_)),
    00048       work_thread_(new asio::thread(
    00049             boost::bind(&asio::io_service::run, &work_io_service_)))
    00050   {
    00051   }

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

    00055   {
    00058     work_.reset();
    00059     if (work_thread_)
    00060       work_thread_->join();

## Member Function Documentation

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

    00065   {

impl_type services::logger_service::null | ( |  | ) | const

Return a null logger implementation.

Definition at line 68 of file logger_service.hpp.

    00070   {
    00071     return 0;

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

Create a new logger implementation.

Definition at line 74 of file logger_service.hpp.

    00076   {
    00077     impl = new logger_impl(identifier);

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

Destroy a logger implementation.

Definition at line 80 of file logger_service.hpp.

    00082   {
    00083     delete impl;
    00084     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 87 of file logger_service.hpp.

    00092   {

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

Log a message.

Definition at line 95 of file logger_service.hpp.

    00100   {
    00101     // Format the text to be logged.
    00102     std::ostringstream os;
    00103     os << impl->identifier << ": " << message;
    00104

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

    00110        :
    00113   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 116 of file logger_service.hpp.

## Member Data Documentation

asio::io_service::id services::logger_service::id`[static]`

The unique service identifier.

Definition at line 31 of file logger_service.hpp.

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

Private io_service used for performing logging operations.

Definition at line 122 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 125 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 128 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 131 of file logger_service.hpp.

The documentation for this class was generated from the following files:

- services/logger_service.hpp
- services/logger_service.cpp

asio 0.3.8rc3 | Home | Reference | Tutorial | Examples | Design