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
25
namespace
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
44
enum class
Level
{
nothing
= 0,
error
,
warning
,
information
,
debug
,
debugInsideLoop
};
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
61
StreamHandler
&
output
();
63
void
setOutput
(std::ostream*);
64
65
private
:
67
explicit
Logger
(
StreamHandler
);
68
70
std::vector<std::regex> allowed_exc_;
72
bool
extended_{
false
};
74
Level
level_{
Level::information
};
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
cepgen::utils::Logger
General purposes logger.
Definition
Logger.h:30
cepgen::utils::Logger::Level
Level
Logging threshold for the output stream.
Definition
Logger.h:44
cepgen::utils::Logger::Level::nothing
@ nothing
cepgen::utils::Logger::Level::debugInsideLoop
@ debugInsideLoop
cepgen::utils::Logger::Level::warning
@ warning
cepgen::utils::Logger::Level::debug
@ debug
cepgen::utils::Logger::Level::information
@ information
cepgen::utils::Logger::Level::error
@ error
cepgen::utils::Logger::addExceptionRule
void addExceptionRule(const std::string &rule)
Add a new rule to display exceptions/messages.
Definition
Logger.cpp:37
cepgen::utils::Logger::get
static Logger & get(std::ostream *=nullptr)
Retrieve the running instance of the logger.
Definition
Logger.cpp:31
cepgen::utils::Logger::setOutput
void setOutput(std::ostream *)
Set the output stream.
Definition
Logger.cpp:56
cepgen::utils::Logger::exceptionRules
const std::vector< std::regex > & exceptionRules() const
Collection of logging exceptions.
Definition
Logger.h:39
cepgen::utils::Logger::extended
bool extended() const
Also show extended information?
Definition
Logger.h:54
cepgen::utils::Logger::setLevel
void setLevel(Level level)
Set the logging threshold.
Definition
Logger.h:52
cepgen::utils::Logger::level
Level level() const
Logging threshold.
Definition
Logger.h:50
cepgen::utils::Logger::passExceptionRule
bool passExceptionRule(const std::string &tmpl, const Level &lev) const
Is the module set to be displayed/logged?
Definition
Logger.cpp:41
cepgen::utils::Logger::output
StreamHandler & output()
Output stream to use for all logging operations.
Definition
Logger.cpp:58
cepgen::utils::Logger::StreamHandler
std::unique_ptr< std::ostream, std::function< void(std::ostream *)> > StreamHandler
Definition
Logger.h:41
cepgen::utils::Logger::setExtended
void setExtended(bool ext=true)
Set the extended information flag.
Definition
Logger.h:56
cepgen::utils::Logger::isTTY
bool isTTY() const
Is the stream handled a TTY-like stream?
Definition
Logger.cpp:65
cepgen
Common namespace for this Monte Carlo generator.
Definition
CommandLineHandler.cpp:36
cepgen::operator<<
std::ostream & operator<<(std::ostream &os, const Exception::Type &type)
Definition
Exception.cpp:59
CepGen
Utils
Logger.h
Generated on Mon Jul 29 2024 for CepGen by
1.9.7