Version: SMASH-3.1
logging.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2015,2017-2019,2022
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 
39 std::array<einhard::Logger<>, std::tuple_size<LogArea::AreaTuple>::value> logg;
40 
51 template <int index, int stop = 0>
52 constexpr typename std::enable_if<(index == stop), int>::type
54  using LogAreaTag = typename std::remove_reference<decltype(std::get<index>(
55  std::declval<LogArea::AreaTuple &>()))>::type;
56  return LogAreaTag::textual_length();
57 }
58 
70 template <int index, int stop = 0, int mid = (index + stop) / 2>
71 constexpr typename std::enable_if<(index > stop), int>::type
73  return find_longest_logger_name<index, mid + 1>() >
74  find_longest_logger_name<mid, stop>()
75  ? find_longest_logger_name<index, mid + 1>()
76  : find_longest_logger_name<mid, stop>();
77 }
78 
84 template <std::size_t index, int>
85 inline typename std::enable_if<(index == 0)>::type create_all_loggers_impl(
86  Configuration &) {}
87 
100 template <std::size_t index,
101  int longest_name = find_longest_logger_name<index - 1>()>
102 inline typename std::enable_if<(index != 0)>::type create_all_loggers_impl(
103  Configuration &config) {
104  using LogAreaTag =
105  typename std::remove_reference<decltype(std::get<index - 1>(
106  std::declval<LogArea::AreaTuple &>()))>::type;
107  static_assert(LogAreaTag::id == index - 1,
108  "The order of types in LogArea::AreaTuple does not match the "
109  "id values in the LogArea types. Please fix! (see top of "
110  "'include/logging.h')");
111  auto &logger = logg[LogAreaTag::id];
112  const auto tmp = utf8::fill_both(LogAreaTag::textual(), longest_name);
113  logger.setAreaName(tmp);
114  logger.setVerbosity(
115  config.take({LogAreaTag::textual()}, global_default_loglevel));
116  create_all_loggers_impl<index - 1, longest_name>(config);
117 }
118 
120  create_all_loggers_impl<std::tuple_size<LogArea::AreaTuple>::value>(config);
121 }
122 
123 } // namespace smash
Interface to the SMASH configuration files.
Value take(std::initializer_list< const char * > keys)
The default interface for SMASH to read configuration values.
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
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
einhard::LogLevel default_loglevel()
Definition: logging.cc:22
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:119
LogLevel
Specification of the message severity.
Definition: einhard.hpp:105
@ ALL
Log all message.
Definition: einhard.hpp:106
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.
Definition: action.h:24
static einhard::LogLevel global_default_loglevel
The default logging level is ALL.
Definition: logging.cc:20
constexpr std::enable_if<(index==stop), int >::type find_longest_logger_name()
Definition: logging.cc:53
std::enable_if<(index==0)>::type create_all_loggers_impl(Configuration &)
Definition: logging.cc:85