11 #ifndef SERVICES_LOGGER_SERVICE_HPP 12 #define SERVICES_LOGGER_SERVICE_HPP 15 #include <boost/bind.hpp> 16 #include <boost/date_time/posix_time/posix_time.hpp> 17 #include <boost/noncopyable.hpp> 18 #include <boost/scoped_ptr.hpp> 47 work_(new
asio::io_service::work(work_io_service_)),
91 void use_file(impl_type& ,
const std::string& file)
95 &logger_service::use_file_impl,
this, file));
99 void log(impl_type& impl,
const std::string& message)
102 std::ostringstream os;
107 &logger_service::log_impl,
this, os.str()));
113 void use_file_impl(
const std::string& file)
117 ofstream_.open(file.c_str());
122 void log_impl(
const std::string& text)
124 ofstream_ << text << std::endl;
133 boost::scoped_ptr<asio::io_service::work> work_;
136 boost::scoped_ptr<asio::thread> work_thread_;
139 std::ofstream ofstream_;
144 #endif // SERVICES_LOGGER_SERVICE_HPP void use_file(impl_type &, const std::string &file)
void log(impl_type &impl, const std::string &message)
Log a message.
Class used to uniquely identify a service.
Provides core I/O functionality.
ASIO_DECL service(asio::io_service &owner)
Constructor.
impl_type null() const
Return a null logger implementation.
Service implementation for the logger.
The backend implementation of a logger.
static asio::io_service::id id
The unique service identifier.
logger_impl * impl_type
The type for an implementation of the logger.
int bind(socket_type s, const socket_addr_type *addr, std::size_t addrlen, asio::error_code &ec)
void shutdown_service()
Destroy all user-defined handler objects owned by the service.
~logger_service()
Destructor shuts down the private io_service.
void create(impl_type &impl, const std::string &identifier)
Create a new logger implementation.
Base class for all io_service services.
void destroy(impl_type &impl)
Destroy a logger implementation.
logger_service(asio::io_service &io_service)
Constructor creates a thread to run a private io_service.
logger_impl(const std::string &ident)