cepgen is hosted by Hepforge, IPPP Durham
CepGen 1.2.5
Central exclusive processes event generator
Loading...
Searching...
No Matches
Logger.h
Go to the documentation of this file.
1/*
2 * CepGen: a central exclusive processes event generator
3 * Copyright (C) 2015-2023 Laurent Forthomme
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef CepGen_Utils_Logger_h
20#define CepGen_Utils_Logger_h
21
22#include <regex>
23#include <vector>
24
25namespace cepgen {
26 namespace utils {
30 class Logger {
31 public:
33 static Logger& get(std::ostream* = nullptr);
34
37 void addExceptionRule(const std::string& rule);
39 const std::vector<std::regex>& exceptionRules() const { return allowed_exc_; }
40
41 typedef std::unique_ptr<std::ostream, std::function<void(std::ostream*)> > StreamHandler;
42
48 bool passExceptionRule(const std::string& tmpl, const Level& lev) const;
50 Level level() const { return level_; }
52 void setLevel(Level level) { level_ = level; }
54 bool extended() const { return extended_; }
56 void setExtended(bool ext = true) { extended_ = ext; }
58 bool isTTY() const;
59
63 void setOutput(std::ostream*);
64
65 private:
67 explicit Logger(StreamHandler);
68
70 std::vector<std::regex> allowed_exc_;
72 bool extended_{false};
76 StreamHandler output_{nullptr};
77 };
78 } // namespace utils
79 std::ostream& operator<<(std::ostream& os, const utils::Logger::Level&);
80} // namespace cepgen
81
82#define CG_LOG_MATCH(str, type) cepgen::utils::Logger::get().passExceptionRule(str, cepgen::utils::Logger::Level::type)
83#define CG_LOG_LEVEL(type) cepgen::utils::Logger::get().setLevel(cepgen::utils::Logger::Level::type)
84
85#endif
General purposes logger.
Definition Logger.h:30
Level
Logging threshold for the output stream.
Definition Logger.h:44
void addExceptionRule(const std::string &rule)
Add a new rule to display exceptions/messages.
Definition Logger.cpp:37
static Logger & get(std::ostream *=nullptr)
Retrieve the running instance of the logger.
Definition Logger.cpp:31
void setOutput(std::ostream *)
Set the output stream.
Definition Logger.cpp:56
const std::vector< std::regex > & exceptionRules() const
Collection of logging exceptions.
Definition Logger.h:39
bool extended() const
Also show extended information?
Definition Logger.h:54
void setLevel(Level level)
Set the logging threshold.
Definition Logger.h:52
Level level() const
Logging threshold.
Definition Logger.h:50
bool passExceptionRule(const std::string &tmpl, const Level &lev) const
Is the module set to be displayed/logged?
Definition Logger.cpp:41
StreamHandler & output()
Output stream to use for all logging operations.
Definition Logger.cpp:58
std::unique_ptr< std::ostream, std::function< void(std::ostream *)> > StreamHandler
Definition Logger.h:41
void setExtended(bool ext=true)
Set the extended information flag.
Definition Logger.h:56
bool isTTY() const
Is the stream handled a TTY-like stream?
Definition Logger.cpp:65
Common namespace for this Monte Carlo generator.
std::ostream & operator<<(std::ostream &os, const Exception::Type &type)
Definition Exception.cpp:59