Bertini 2 - C++ Core
Software for Numerical Algebraic Geometry
Loading...
Searching...
No Matches
logging.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//logging.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//logging.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with logging.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) 2015 - 2021 by Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22// individual authors of this file include:
23// silviana amethyst, university of wisconsin eau claire
24
30
31
32#ifndef BERTINI_LOGGING_HPP
33#define BERTINI_LOGGING_HPP
34
35
36#define BOOST_LOG_DYN_LINK 1
37
38#include <boost/log/core.hpp>
39#include <boost/log/trivial.hpp>
40#include <boost/log/expressions.hpp>
41#include <boost/log/sinks/text_file_backend.hpp>
42#include <boost/log/utility/setup/file.hpp>
43#include <boost/log/utility/setup/common_attributes.hpp>
44#include <boost/log/sources/severity_logger.hpp>
45#include <boost/log/sources/record_ostream.hpp>
46
47namespace bertini{
48namespace logging{
49
50
51
52 namespace blog = boost::log;
53
54 using severity_level = blog::trivial::severity_level;
55 namespace src = blog::sources;
56 namespace sinks = blog::sinks;
57 namespace keywords = blog::keywords;
58
59
60 // the following is adapted from https://stackoverflow.com/questions/11421432/
61 // question answered by user James Adkison, asked by Adi, edited by James McNellis.
62 // the adaptation is the replacement of std::ostream with the blros type. why the unmodified code still fails
63 // for blros types is a mystery.
64 using blros = blog::record_ostream;
65 template<typename T>
66 blros& operator<<(typename std::enable_if<std::is_enum<T>::value, blros>::type& stream, const T& e)
67 {
68 return stream << static_cast<typename std::underlying_type<T>::type>(e);
69 }
70
71
89 struct Logging
90 {
91
92 static
93 void Init(std::string const& name_pattern = "bertini_%N.log",
94 std::string const& format = "%Message%",
95 unsigned rotation_size = 10*1024*1024,
96 severity_level const& new_level = severity_level::error)
97 {
98 AddFile(name_pattern, format, rotation_size);
99 SetLevel(new_level);
100
101 BOOST_LOG_TRIVIAL(info) << "initialized logging";
102 }
103
104
105 static
106 void AddFile(std::string const& name_pattern, std::string const& format, unsigned rotation_size, bool auto_flush = true)
107 {
108 blog::add_file_log
109 (
110 keywords::file_name = name_pattern,
111 keywords::rotation_size = rotation_size,
112 keywords::format = format,
113 keywords::auto_flush = auto_flush
114 );
115 }
116
117
123 static
124 void SetLevel(severity_level const& new_level)
125 {
126 blog::core::get()->set_filter
127 (
128 blog::trivial::severity >= new_level
129 );
130 }
131
132
133 };
134
135
136
137} // namespace logging
138} // re: namespace bertini
139
140
141
142#endif
Definition logging.hpp:90
static void SetLevel(severity_level const &new_level)
Definition logging.hpp:124