Boost C++ Libraries Home Libraries People FAQ More

Home | Reference | Tutorial | Examples | Design

services/basic_logger.hpp

Go to the documentation of this file.
00001 #ifndef SERVICES_BASIC_LOGGER_HPP
00002 #define SERVICES_BASIC_LOGGER_HPP
00003 
00004 #include <boost/asio.hpp>
00005 #include <boost/noncopyable.hpp>
00006 #include <string>
00007 
00008 namespace services {
00009 
00012 template <typename Service>
00013 class basic_logger
00014   : private boost::noncopyable
00015 {
00016 public:
00018   typedef Service service_type;
00019 
00021   typedef typename service_type::impl_type impl_type;
00022 
00024 
00031   explicit basic_logger(boost::asio::io_service& io_service,
00032       const std::string& identifier)
00033     : service_(boost::asio::use_service<Service>(io_service)),
00034       impl_(service_.null())
00035   {
00036     service_.create(impl_, identifier);
00037   }
00038 
00040   ~basic_logger()
00041   {
00042     service_.destroy(impl_);
00043   }
00044 
00046   boost::asio::io_service& io_service()
00047   {
00048     return service_.io_service();
00049   }
00050 
00052   void use_file(const std::string& file)
00053   {
00054     service_.use_file(impl_, file);
00055   }
00056 
00058   void log(const std::string& message)
00059   {
00060     service_.log(impl_, message);
00061   }
00062 
00063 private:
00065   service_type& service_;
00066 
00068   impl_type impl_;
00069 };
00070 
00071 } // namespace services
00072 
00073 #endif // SERVICES_BASIC_LOGGER_HPP
Copyright © 2003 - 2006 Christopher M. Kohlhoff

Home | Reference | Tutorial | Examples | Design