Version: SMASH-1.5
logging.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2018
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/logging.h"
11 
12 #include <array>
13 
14 #include "smash/configuration.h"
15 #include "smash/stringfunctions.h"
16 
17 namespace smash {
18 
21 
23 
26 }
27 
32 static std::array<einhard::Logger<>, std::tuple_size<LogArea::AreaTuple>::value>
34 
36  return global_logger_collection[id];
37 }
38 
49 template <int index, int stop = 0>
50 constexpr typename std::enable_if<(index == stop), int>::type
52  using LogAreaTag = typename std::remove_reference<decltype(
53  std::get<index>(std::declval<LogArea::AreaTuple &>()))>::type;
54  return LogAreaTag::textual_length();
55 }
56 
68 template <int index, int stop = 0, int mid = (index + stop) / 2>
69 constexpr typename std::enable_if<(index > stop), int>::type
71  return find_longest_logger_name<index, mid + 1>() >
72  find_longest_logger_name<mid, stop>()
73  ? find_longest_logger_name<index, mid + 1>()
74  : find_longest_logger_name<mid, stop>();
75 }
76 
82 template <std::size_t index, int>
83 inline typename std::enable_if<(index == 0)>::type create_all_loggers_impl(
84  Configuration &) {}
85 
98 template <std::size_t index,
99  int longest_name = find_longest_logger_name<index - 1>()>
100 inline typename std::enable_if<(index != 0)>::type create_all_loggers_impl(
101  Configuration &config) {
102  using LogAreaTag = typename std::remove_reference<decltype(
103  std::get<index - 1>(std::declval<LogArea::AreaTuple &>()))>::type;
104  static_assert(LogAreaTag::id == index - 1,
105  "The order of types in LogArea::AreaTuple does not match the "
106  "id values in the LogArea types. Please fix! (see top of "
107  "'include/logging.h')");
108  auto &logger = global_logger_collection[LogAreaTag::id];
109  const auto tmp = utf8::fill_both(LogAreaTag::textual(), longest_name);
110  logger.setAreaName(tmp);
112  config.take({LogAreaTag::textual()}, global_default_loglevel));
113  create_all_loggers_impl<index - 1, longest_name>(config);
114 }
115 
117  create_all_loggers_impl<std::tuple_size<LogArea::AreaTuple>::value>(config);
118 }
119 
120 } // namespace smash
void setAreaName(const char *name)
Set an area name.
Definition: einhard.hpp:387
std::enable_if<(index==0)>::type create_all_loggers_impl(Configuration &)
Definition: logging.cc:83
Interface to the SMASH configuration files.
einhard::LogLevel default_loglevel()
Definition: logging.cc:22
static std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > global_logger_collection
An array that stores all pre-configured Logger objects.
Definition: logging.cc:33
void create_all_loggers(Configuration config)
Called from main() right after the Configuration object is fully set up to create all logger objects ...
Definition: logging.cc:116
constexpr std::enable_if<(index==stop), int >::type find_longest_logger_name()
Definition: logging.cc:51
static einhard::LogLevel global_default_loglevel
The default logging level is ALL.
Definition: logging.cc:20
A Logger object can be used to output messages to stdout.
Definition: einhard.hpp:347
void set_default_loglevel(einhard::LogLevel level)
Set the default log level (what will be returned from subsequent default_loglevel calls)...
Definition: logging.cc:24
void setVerbosity(LogLevel verbosity) noexcept
Modify the verbosity of the Logger.
Definition: einhard.hpp:535
std::string fill_both(const std::string &s, size_t width, char fill=' ')
Fill string with characters at both sides until the given width is reached.
Value take(std::initializer_list< const char *> keys)
The default interface for SMASH to read configuration values.
einhard::Logger & retrieve_logger_impl(int id)
Definition: logging.cc:35
LogLevel
Specification of the message severity.
Definition: einhard.hpp:104
Log all message.
Definition: einhard.hpp:106
einhard::Logger & logger()
Definition: logging.h:234
Definition: action.h:24