23#include <unordered_map>
28#define MARLEY_LOGGER_LEVEL_TRACE 0
29#define MARLEY_LOGGER_LEVEL_DEBUG 1
30#define MARLEY_LOGGER_LEVEL_INFO 2
31#define MARLEY_LOGGER_LEVEL_NOTICE 3
32#define MARLEY_LOGGER_LEVEL_WARN 4
33#define MARLEY_LOGGER_LEVEL_ERROR 5
34#define MARLEY_LOGGER_LEVEL_FATAL 6
41#define MARLEY_LOG_LEVEL_NUM(level) MARLEY_LOG_LEVEL_NUM_IMPL(level)
42#define MARLEY_LOG_LEVEL_NUM_IMPL(level) MARLEY_LOGGER_LEVEL_##level
49#ifndef MARLEY_COMPILED_LOG_LEVEL
50 #define MARLEY_COMPILED_LOG_LEVEL INFO
55#define MARLEY_LOG(...) \
56 MARLEY_LOG_SELECT(__VA_ARGS__, \
61#define MARLEY_LOG_SELECT(_1,_2,NAME,...) NAME
63#define MARLEY_LOG_1(level) MARLEY_LOG_IMPL(level,"")
64#define MARLEY_LOG_2(level, category) MARLEY_LOG_IMPL(level,category)
66#define MARLEY_LOG_IMPL(level, category) \
67 ( MARLEY_LOG_LEVEL_NUM(MARLEY_COMPILED_LOG_LEVEL) \
68 <= MARLEY_LOGGER_LEVEL_##level ) && \
69 marley::Logger::Instance().log( marley::Logger::LogLevel::level, category )
81std::ostream& operator<<( std::ostream& out,
84std::ostream& operator<<( std::ostream& os,
const marley::JSON& json );
85std::ostream& operator<<( std::ostream& out,
const marley::Parity& p );
86std::ostream& operator<<( std::ostream& out,
const marley::Target& t );
103 TRACE = MARLEY_LOGGER_LEVEL_TRACE,
104 DEBUG = MARLEY_LOGGER_LEVEL_DEBUG,
105 INFO = MARLEY_LOGGER_LEVEL_INFO,
106 NOTICE = MARLEY_LOGGER_LEVEL_NOTICE,
107 WARN = MARLEY_LOGGER_LEVEL_WARN,
108 ERROR = MARLEY_LOGGER_LEVEL_ERROR,
109 FATAL = MARLEY_LOGGER_LEVEL_FATAL,
116 const char* loglevel_to_str(
LogLevel lev );
138 OutStream( std::shared_ptr< std::ostream > os,
158 std::shared_ptr< std::ostream > stream_;
176 Message( std::vector< std::ostream* >& vec, std::mutex* mtx )
183 Message( Message&& other ) =
default;
184 Message& operator=( Message&& other ) =
default;
188 inline explicit operator bool()
const {
return true; }
193 if (
osvec_.empty() )
return;
197 std::string msg =
buffer_.str();
198 std::lock_guard< std::mutex > lock( *
mtx_ );
199 for (
auto& s :
osvec_ ) *s << msg;
202 template<
typename OutputType > Message&
203 operator<<(
const OutputType& out )
216 Message& operator<<( std::ostream& (*manip)(std::ostream&) );
219 Message& operator<<( std::ios_base& (*manip)(std::ios_base&) );
245 static LogLevel string_to_loglevel(
const std::string& str );
252 bool has_stream(
const std::ostream& stream )
const;
288 void add_stream( std::shared_ptr< std::ostream > stream,
301 const OutStream* get_stream(
const std::ostream* os )
const;
305 OutStream* get_stream(
const std::ostream* os );
309 std::vector< OutStream > streams_;
314 LogLevel default_level_ = LogLevel::INFO;
318 std::unordered_map< std::string, LogLevel > category_map_;
325 std::unordered_map< std::string, LogLevel > resolved_level_cache_;
331 static constexpr char CATEG_DELIM_ =
'.';
341 return ( lev >= cl );
Monte Carlo implementation of the Hauser-Feshbach statistical model for decays of highly-excited nucl...
Temporary object used for forming logger messages.
std::ostringstream buffer_
std::vector< std::ostream * > osvec_
Active output streams that should receive the Message.
Simple singleton logging class.
static Logger & Instance()
Get the singleton instance of the Logger class.
Logger(const Logger &)=delete
Deleted copy constructor.
Logger & operator=(const Logger &)=delete
Deleted copy assignment operator.
bool should_emit(const std::string &category, LogLevel lev)
Returns whether the logger should emit a message for the given category and level.
Logger()
Create the singleton Logger.
LogLevel category_level(const std::string &category)
Looks up the severity setting for the input category, including inheritance from the hierarchy.
void configure(const marley::JSON &json)
Initialize the Logger using settings expressed as a JSON object.
Message log(LogLevel lev, const std::string &category="")
Prepare the Logger to receive a log message via the << stream operator.
LogLevel
Defines the logging levels recognized by the marley::Logger.
Logger & operator=(Logger &&)=delete
Deleted move assignment operator.
bool has_stream(const std::ostream &stream) const
Returns true if stream is already registered with the Logger, or false otherwise.
Logger(Logger &&)=delete
Deleted move constructor.
Type-safe representation of a parity value (either +1 or -1)
An atomic target for a lepton scattering reaction.
Description of a macroscopic target for scattering reactions.