Fawkes API Fawkes Development Version
fd_redirect.h
1
2/***************************************************************************
3 * fd_redirect.h - Redirect file descriptor writes to log
4 *
5 * Created: Thu Aug 21 14:59:57 2014
6 * Copyright 2014 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#ifndef _LOGGING_FD_REDIRECT_H_
25#define _LOGGING_FD_REDIRECT_H_
26
27#include <logging/logger.h>
28
29#include <boost/asio.hpp>
30#include <string>
31#include <thread>
32
33namespace fawkes {
34
36{
37public:
38 LogFileDescriptorToLog(int fd, Logger *logger, const char *logname, Logger::LogLevel log_level);
40
41private:
42 void start_log(const char * logname,
43 Logger::LogLevel log_level,
44 boost::asio::posix::stream_descriptor &sd,
45 boost::asio::streambuf & buf);
46 void handle_log_line(const char * logname,
47 Logger::LogLevel log_level,
48 boost::asio::posix::stream_descriptor &sd,
49 boost::asio::streambuf & buf,
50 boost::system::error_code ec,
51 size_t bytes_read);
52
53private:
54 int log_fd_;
55 int old_fd_;
56 int old_fd_dup_;
57
58 boost::asio::io_service io_service_;
59 std::thread io_service_thread_;
60 boost::asio::io_service::work io_service_work_;
61
62 boost::asio::posix::stream_descriptor stream_;
63 boost::asio::streambuf buffer_;
64
65 Logger * logger_;
66 std::string log_name_;
67 Logger::LogLevel log_level_;
68};
69
70} // end namespace fawkes
71
72#endif
Redirect a file descriptor to the log.
Definition: fd_redirect.h:36
LogFileDescriptorToLog(int fd, Logger *logger, const char *logname, Logger::LogLevel log_level)
Constructor.
Definition: fd_redirect.cpp:44
Interface for logging.
Definition: logger.h:42
LogLevel
Log level.
Definition: logger.h:51
Fawkes library namespace.