5 // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef SERVICES_BASIC_LOGGER_HPP
12 #define SERVICES_BASIC_LOGGER_HPP
14 #include <boost/asio.hpp>
15 #include <boost/noncopyable.hpp>
20 /// Class to provide simple logging functionality. Use the services::logger
22 template <typename Service>
24 : private boost::noncopyable
27 /// The type of the service that will be used to provide timer operations.
28 typedef Service service_type;
30 /// The native implementation type of the timer.
31 typedef typename service_type::impl_type impl_type;
35 * This constructor creates a logger.
37 * @param context The execution context used to locate the logger service.
39 * @param identifier An identifier for this logger.
41 explicit basic_logger(boost::asio::execution_context& context,
42 const std::string& identifier)
43 : service_(boost::asio::use_service<Service>(context)),
44 impl_(service_.null())
46 service_.create(impl_, identifier);
52 service_.destroy(impl_);
55 /// Set the output file for all logger instances.
56 void use_file(const std::string& file)
58 service_.use_file(impl_, file);
62 void log(const std::string& message)
64 service_.log(impl_, message);
68 /// The backend service implementation.
69 service_type& service_;
71 /// The underlying native implementation.
75 } // namespace services
77 #endif // SERVICES_BASIC_LOGGER_HPP