-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathManager.h
More file actions
executable file
·145 lines (126 loc) · 4 KB
/
Manager.h
File metadata and controls
executable file
·145 lines (126 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* License plate detection
* See COPYRIGHT file at the top of the source tree.
*
* This product includes software developed by the
* STARGUE Project (http://www.stargue.org/).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the STARGUE License Statement and
* the GNU General Public License along with this program. If not,
* see <http://www.lsstcorp.org/LegalNotices/>.
*/
/**
* @file Manager.h
*
* @brief Provide logs
*
* @author Adama Zouma
*
* @Contact: stargue49@gmail.com
*
*/
#ifndef MY_MANAGER_H
#define MY_MANAGER_H
/**
* Implementation of a log manager
* This log manager store each log in a specifc file
* define by the user
* the log file name may change and the following logs output
* is directed in the file name given right before
*
*/
#include <boost/log/attributes.hpp>
#include <boost/log/common.hpp>
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sinks/text_ostream_backend.hpp>
#include <boost/log/sources/logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sources/severity_feature.hpp>
#include <boost/log/sources/severity_feature.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/support/date_time.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/formatter_parser.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread/thread.hpp>
#include <fstream>
#include <boost/core/null_deleter.hpp>
#include <boost/log/trivial.hpp>
namespace logging = boost::log;
namespace attrs = boost::log::attributes;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace expr = boost::log::expressions;
namespace keywords = boost::log::keywords;
namespace za{
enum sign_severity_level
{
trace,
debug,
info,
warning,
error,
fatal,
report
};
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(
my_logger, src::severity_logger_mt<sign_severity_level>
);
class Manager
{
public:
using Backend = sinks::text_ostream_backend;
using TextSink = sinks::synchronous_sink<Backend>;
private:
boost::shared_ptr<Backend> backend_;
boost::shared_ptr<std::ostream> current_stream_;
public:
Manager()
{
backend_ = boost::make_shared<Backend>();
backend_->auto_flush(true);
boost::shared_ptr<TextSink> sink(new TextSink(backend_));
sink->set_formatter(
expr::format("[%1%]<%2%>: %3%") %
//expr::format("[%1%]<%2%>(%3%): %4%") %
expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%Y-%m-%d %H:%M:%S") %
//logging::trivial::severity %
expr::attr < sign_severity_level > ("Severity") %
//expr::attr < attrs::current_thread_id::value_type > ("ThreadID") %
expr::smessage
);
sink->set_filter(expr::attr<sign_severity_level>("Severity") >= warning);
logging::core::get()->add_sink(sink);
logging::add_common_attributes();
logging::core::get()->add_global_attribute(
"ThreadID", attrs::current_thread_id()
);
}
void set_log_file(const char* filename)
{
backend_->remove_stream(current_stream_);
current_stream_.reset(new std::ofstream(filename));
backend_->add_stream(current_stream_);
//stdout
backend_->add_stream(
boost::shared_ptr< std::ostream >(&std::clog, boost::null_deleter()));
}
};
}
#endif