OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Logger.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef __CUDACC__
20 
21 #include "Logger.h"
22 #include "StringTransform.h"
23 
24 #include <boost/algorithm/string.hpp>
25 #include <boost/log/expressions.hpp>
26 #include <boost/log/sinks.hpp>
27 #include <boost/log/sources/global_logger_storage.hpp>
28 #include <boost/log/sources/logger.hpp>
29 #include <boost/log/sources/severity_feature.hpp>
30 #include <boost/log/support/date_time.hpp>
31 #include <boost/log/utility/setup.hpp>
32 #include <boost/phoenix.hpp>
33 #include <boost/variant.hpp>
34 
35 #include <atomic>
36 #include <cstdlib>
37 #include <iostream>
38 #include <mutex>
39 #include <regex>
40 
41 namespace logger {
42 
43 namespace attr = boost::log::attributes;
44 namespace expr = boost::log::expressions;
45 namespace keywords = boost::log::keywords;
46 namespace sinks = boost::log::sinks;
47 namespace sources = boost::log::sources;
48 namespace po = boost::program_options;
49 
50 BOOST_LOG_ATTRIBUTE_KEYWORD(process_id, "ProcessID", attr::current_process_id::value_type)
51 BOOST_LOG_ATTRIBUTE_KEYWORD(channel, "Channel", Channel)
52 BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", Severity)
53 
54 BOOST_LOG_GLOBAL_LOGGER_DEFAULT(gChannelLogger, ChannelLogger)
55 BOOST_LOG_GLOBAL_LOGGER_DEFAULT(gSeverityLogger, SeverityLogger)
56 
57 // Return last component of path
58 std::string filename(char const* path) {
59  return boost::filesystem::path(path).filename().string();
60 }
61 
62 LogOptions::LogOptions(char const* argv0) : options_("Logging") {
63  // Log file base_name matches name of program.
64  std::string const base_name =
65  argv0 == nullptr ? std::string("omnisci_server") : filename(argv0);
67  symlink_ = base_name + symlink_;
68  std::string const channels = join(ChannelNames, " ");
69  // Filter out DEBUG[1-4] severities from --help options
70  std::string severities;
71  for (auto const& name : SeverityNames) {
72  if (!boost::algorithm::starts_with(name, "DEBUG")) {
73  (severities += (severities.empty() ? "" : " ")) += name;
74  }
75  }
76  options_.add_options()(
77  "log-directory",
78  po::value<boost::filesystem::path>(&log_dir_)->default_value(log_dir_),
79  "Logging directory. May be relative to data directory, or absolute.");
80  options_.add_options()(
81  "log-file-name",
82  po::value<std::string>(&file_name_pattern_)->default_value(file_name_pattern_),
83  "Log file name relative to log-directory.");
84  options_.add_options()("log-symlink",
85  po::value<std::string>(&symlink_)->default_value(symlink_),
86  "Symlink to active log.");
87  options_.add_options()("log-severity",
88  po::value<Severity>(&severity_)->default_value(severity_),
89  ("Log to file severity level: " + severities).c_str());
90  options_.add_options()(
91  "log-severity-clog",
92  po::value<Severity>(&severity_clog_)->default_value(severity_clog_),
93  ("Log to console severity level: " + severities).c_str());
94  options_.add_options()("log-channels",
95  po::value<Channels>(&channels_)->default_value(channels_),
96  ("Log channel debug info: " + channels).c_str());
97  options_.add_options()("log-auto-flush",
98  po::value<bool>(&auto_flush_)->default_value(auto_flush_),
99  "Flush logging buffer to file after each message.");
100  options_.add_options()("log-max-files",
101  po::value<size_t>(&max_files_)->default_value(max_files_),
102  "Maximum number of log files to keep.");
103  options_.add_options()(
104  "log-min-free-space",
105  po::value<size_t>(&min_free_space_)->default_value(20 << 20),
106  "Minimum number of bytes left on device before oldest log files are deleted.");
107  options_.add_options()("log-rotate-daily",
108  po::value<bool>(&rotate_daily_)->default_value(true),
109  "Start new log files at midnight.");
110  options_.add_options()("log-rotation-size",
111  po::value<size_t>(&rotation_size_)->default_value(10 << 20),
112  "Maximum file size in bytes before new log files are started.");
113 }
114 
115 boost::filesystem::path LogOptions::full_log_dir() const {
116  return log_dir_.has_root_directory() ? log_dir_ : base_path_ / log_dir_;
117 }
118 
119 po::options_description const& LogOptions::get_options() const {
120  return options_;
121 }
122 
123 // Typical usage calls either get_options() or parse_command_line() but not both.
124 void LogOptions::parse_command_line(int argc, char const* const* argv) {
125  po::variables_map vm;
126  po::store(
127  po::command_line_parser(argc, argv).options(options_).allow_unregistered().run(),
128  vm);
129  po::notify(vm); // Sets LogOptions member variables.
130 }
131 
132 // Must be called before init() to take effect.
133 void LogOptions::set_base_path(std::string const& base_path) {
134  base_path_ = base_path;
135 }
136 
137 template <typename TAG>
138 std::string replace_braces(std::string const& str, TAG const tag) {
139  constexpr std::regex::flag_type flags = std::regex::ECMAScript | std::regex::optimize;
140  static std::regex const regex(R"(\{SEVERITY\})", flags);
141  if /*constexpr*/ (std::is_same<TAG, Channel>::value) {
142  return std::regex_replace(str, regex, ChannelNames[tag]);
143  } else {
144  return std::regex_replace(str, regex, SeverityNames[tag]);
145  }
146 }
147 
148 // Print decimal value for process_id (14620) instead of hex (0x0000391c)
149 boost::log::attributes::current_process_id::value_type::native_type get_native_process_id(
150  boost::log::value_ref<boost::log::attributes::current_process_id::value_type,
151  tag::process_id> const& pid) {
152  return pid ? pid->native_id() : 0;
153 }
154 
155 template <typename SINK>
156 sinks::text_file_backend::open_handler_type create_or_replace_symlink(
157  boost::weak_ptr<SINK> weak_ptr,
158  std::string&& symlink) {
159  namespace fs = boost::filesystem;
160  return [weak_ptr,
161  symlink = std::move(symlink)](sinks::text_file_backend::stream_type& stream) {
162  if (boost::shared_ptr<SINK> sink = weak_ptr.lock()) {
164  fs::path const& file_name = sink->locked_backend()->get_current_file_name();
165  fs::path const symlink_path = file_name.parent_path() / symlink;
166  fs::remove(symlink_path, ec);
167  if (ec) {
168  stream << filename(__FILE__) << ':' << __LINE__ << ' ' << ec.message() << '\n';
169  }
170  fs::create_symlink(file_name.filename(), symlink_path, ec);
171  if (ec) {
172  stream << filename(__FILE__) << ':' << __LINE__ << ' ' << ec.message() << '\n';
173  }
174  }
175  };
176 }
177 
178 boost::log::formatting_ostream& operator<<(
179  boost::log::formatting_ostream& strm,
180  boost::log::to_log_manip<Channel, tag::channel> const& manip) {
181  return strm << ChannelSymbols[manip.get()];
182 }
183 
184 boost::log::formatting_ostream& operator<<(
185  boost::log::formatting_ostream& strm,
186  boost::log::to_log_manip<Severity, tag::severity> const& manip) {
187  return strm << SeveritySymbols[manip.get()];
188 }
189 
190 template <typename TAG, typename SINK>
191 void set_formatter(SINK& sink) {
192  if /*constexpr*/ (std::is_same<TAG, Channel>::value) {
193  sink->set_formatter(
194  expr::stream << expr::format_date_time<boost::posix_time::ptime>(
195  "TimeStamp", "%Y-%m-%dT%H:%M:%S.%f")
196  << ' ' << channel << ' '
197  << boost::phoenix::bind(&get_native_process_id, process_id.or_none())
198  << ' ' << expr::smessage);
199  } else {
200  sink->set_formatter(
201  expr::stream << expr::format_date_time<boost::posix_time::ptime>(
202  "TimeStamp", "%Y-%m-%dT%H:%M:%S.%f")
203  << ' ' << severity << ' '
204  << boost::phoenix::bind(&get_native_process_id, process_id.or_none())
205  << ' ' << expr::smessage);
206  }
207 }
208 
209 template <typename FILE_SINK, typename TAG>
210 boost::shared_ptr<FILE_SINK> make_sink(LogOptions const& log_opts,
211  boost::filesystem::path const& full_log_dir,
212  TAG const tag) {
213  auto sink = boost::make_shared<FILE_SINK>(
214  keywords::file_name =
215  full_log_dir / replace_braces(log_opts.file_name_pattern_, tag),
216  keywords::auto_flush = log_opts.auto_flush_,
217  keywords::rotation_size = log_opts.rotation_size_);
218  if /*constexpr*/ (std::is_same<TAG, Channel>::value) {
219  sink->set_filter(channel == static_cast<Channel>(tag));
220  set_formatter<Channel>(sink);
221  } else {
222  // INFO sink logs all other levels. Other sinks only log at their level or higher.
223  Severity const min_filter_level = static_cast<Severity>(tag) == Severity::INFO
224  ? log_opts.severity_
225  : static_cast<Severity>(tag);
226  sink->set_filter(min_filter_level <= severity);
227  set_formatter<Severity>(sink);
228  }
229  typename FILE_SINK::locked_backend_ptr backend = sink->locked_backend();
230  if (log_opts.rotate_daily_) {
231  backend->set_time_based_rotation(sinks::file::rotation_at_time_point(0, 0, 0));
232  }
233  backend->set_file_collector(
234  sinks::file::make_collector(keywords::target = full_log_dir,
235  keywords::max_files = log_opts.max_files_,
236  keywords::min_free_space = log_opts.min_free_space_));
237  backend->set_open_handler(create_or_replace_symlink(
238  boost::weak_ptr<FILE_SINK>(sink), replace_braces(log_opts.symlink_, tag)));
239  backend->scan_for_files();
240  return sink;
241 }
242 
243 // Pointer to function to optionally call on LOG(FATAL).
244 std::atomic<FatalFunc> g_fatal_func{nullptr};
245 std::once_flag g_fatal_func_flag;
246 
247 using ClogSync = sinks::synchronous_sink<sinks::text_ostream_backend>;
248 using FileSync = sinks::synchronous_sink<sinks::text_file_backend>;
249 
250 template <typename CONSOLE_SINK>
251 boost::shared_ptr<CONSOLE_SINK> make_sink(LogOptions const& log_opts) {
252  auto sink = boost::make_shared<CONSOLE_SINK>();
253  boost::shared_ptr<std::ostream> clog(&std::clog, boost::null_deleter());
254  sink->locked_backend()->add_stream(clog);
255  sink->set_filter(log_opts.severity_clog_ <= severity);
256  set_formatter<Severity>(sink);
257  return sink;
258 }
259 
260 // Locking/atomicity not needed for g_any_active_channels or g_min_active_severity
261 // as they are modifed by init() once.
264 
265 void init(LogOptions const& log_opts) {
266  boost::shared_ptr<boost::log::core> core = boost::log::core::get();
267  // boost::log::add_common_attributes(); // LineID TimeStamp ProcessID ThreadID
268  core->add_global_attribute("TimeStamp", attr::local_clock());
269  core->add_global_attribute("ProcessID", attr::current_process_id());
270  if (0 < log_opts.max_files_) {
271  boost::filesystem::path const full_log_dir = log_opts.full_log_dir();
272  bool const log_dir_was_created = boost::filesystem::create_directory(full_log_dir);
273  // Don't create separate log sinks for anything less than Severity::INFO.
274  Severity const min_sink_level = std::max(Severity::INFO, log_opts.severity_);
275  for (int i = min_sink_level; i < Severity::_NSEVERITIES; ++i) {
276  Severity const level = static_cast<Severity>(i);
277  core->add_sink(make_sink<FileSync>(log_opts, full_log_dir, level));
278  }
280  if (log_dir_was_created) {
281  LOG(INFO) << "Log directory(" << full_log_dir.native() << ") created.";
282  }
283  for (auto const channel : log_opts.channels_) {
284  core->add_sink(make_sink<FileSync>(log_opts, full_log_dir, channel));
285  }
286  g_any_active_channels = !log_opts.channels_.empty();
287  }
288  core->add_sink(make_sink<ClogSync>(log_opts));
290 }
291 
292 void set_once_fatal_func(FatalFunc fatal_func) {
293  if (g_fatal_func.exchange(fatal_func)) {
294  throw std::runtime_error(
295  "logger::set_once_fatal_func() should not be called more than once.");
296  }
297 }
298 
299 void shutdown() {
300  boost::log::core::get()->remove_all_sinks();
301 }
302 
303 // Used by boost::program_options when parsing enum Channel.
304 std::istream& operator>>(std::istream& in, Channels& channels) {
305  std::string line;
306  std::getline(in, line);
307  std::regex const rex(R"(\w+)");
308  using TokenItr = std::regex_token_iterator<std::string::iterator>;
309  TokenItr const end;
310  for (TokenItr tok(line.begin(), line.end(), rex); tok != end; ++tok) {
311  auto itr = std::find(ChannelNames.cbegin(), ChannelNames.cend(), *tok);
312  if (itr == ChannelNames.cend()) {
313  in.setstate(std::ios_base::failbit);
314  break;
315  } else {
316  channels.emplace(static_cast<Channel>(itr - ChannelNames.cbegin()));
317  }
318  }
319  return in;
320 }
321 
322 // Used by boost::program_options when stringifying Channels.
323 std::ostream& operator<<(std::ostream& out, Channels const& channels) {
324  int i = 0;
325  for (auto const channel : channels) {
326  out << (i++ ? " " : "") << ChannelNames.at(channel);
327  }
328  return out;
329 }
330 
331 // Used by boost::program_options when parsing enum Severity.
332 std::istream& operator>>(std::istream& in, Severity& sev) {
333  std::string token;
334  in >> token;
335  auto itr = std::find(SeverityNames.cbegin(), SeverityNames.cend(), token);
336  if (itr == SeverityNames.cend()) {
337  in.setstate(std::ios_base::failbit);
338  } else {
339  sev = static_cast<Severity>(itr - SeverityNames.cbegin());
340  }
341  return in;
342 }
343 
344 // Used by boost::program_options when stringifying enum Severity.
345 std::ostream& operator<<(std::ostream& out, Severity const& sev) {
346  return out << SeverityNames.at(sev);
347 }
348 
350  : is_channel_(true)
351  , enum_value_(channel)
352  , record_(std::make_unique<boost::log::record>(
353  gChannelLogger::get().open_record(boost::log::keywords::channel = channel))) {
354  if (*record_) {
355  stream_ = std::make_unique<boost::log::record_ostream>(*record_);
356  }
357 }
358 
360  : is_channel_(false)
361  , enum_value_(severity)
362  , record_(std::make_unique<boost::log::record>(gSeverityLogger::get().open_record(
363  boost::log::keywords::severity = severity))) {
364  if (*record_) {
365  stream_ = std::make_unique<boost::log::record_ostream>(*record_);
366  }
367 }
368 
370  if (stream_) {
371  if (is_channel_) {
372  gChannelLogger::get().push_record(boost::move(stream_->get_record()));
373  } else {
374  gSeverityLogger::get().push_record(boost::move(stream_->get_record()));
375  }
376  }
377  if (!is_channel_ && static_cast<Severity>(enum_value_) == Severity::FATAL) {
378  if (FatalFunc fatal_func = g_fatal_func.load()) {
379  // set_once_fatal_func() prevents race condition.
380  // Exceptions thrown by (*fatal_func)() are propagated here.
381  std::call_once(g_fatal_func_flag, *fatal_func);
382  }
383  abort();
384  }
385 }
386 
387 Logger::operator bool() const {
388  return static_cast<bool>(stream_);
389 }
390 
391 boost::log::record_ostream& Logger::stream(char const* file, int line) {
392  return *stream_ << filename(file) << ':' << line << ' ';
393 }
394 
395 // DebugTimer-related classes and functions.
396 
397 using Clock = std::chrono::steady_clock;
398 
399 class DurationTree;
400 
401 class Duration {
403  Clock::time_point const start_;
404  Clock::time_point stop_;
405 
406  public:
407  int const depth_;
409  char const* const file_;
410  int const line_;
411  char const* const name_;
412 
413  Duration(DurationTree* duration_tree,
414  int depth,
415  Severity severity,
416  char const* file,
417  int line,
418  char const* name)
419  : duration_tree_(duration_tree)
420  , start_(Clock::now())
421  , depth_(depth)
422  , severity_(severity)
423  , file_(file)
424  , line_(line)
425  , name_(name) {}
426  bool stop();
427  template <typename Units = std::chrono::milliseconds>
428  typename Units::rep value() const {
429  return std::chrono::duration_cast<Units>(stop_ - start_).count();
430  }
431 };
432 
433 using DurationTreeNode = boost::variant<Duration, DurationTree&>;
434 
436  std::deque<DurationTreeNode> durations_;
437  int current_depth_; //< Depth of next DurationTreeNode.
438 
439  public:
440  int const depth_; //< Depth of tree within parent tree, 0 for base tree.
441  std::thread::id const thread_id_;
442  DurationTree(std::thread::id thread_id, int start_depth)
443  // Add +1 to current_depth_ for non-base DurationTrees for extra indentation.
444  : current_depth_(start_depth + (start_depth == 0 ? 0 : 1))
445  , depth_(start_depth)
446  , thread_id_(thread_id) {}
447  void pushDurationTree(DurationTree& duration_tree) {
448  durations_.emplace_back(duration_tree);
449  }
450  const Duration& baseDuration() const {
451  CHECK(!durations_.empty());
452  return boost::get<Duration>(durations_.front());
453  }
454  int currentDepth() const { return current_depth_; }
456  std::deque<DurationTreeNode> const& durations() const { return durations_; }
457  template <typename... Ts>
459  durations_.emplace_back(Duration(this, current_depth_++, std::forward<Ts>(args)...));
460  return boost::get<Duration>(&durations_.back());
461  }
462 };
463 
467  stop_ = Clock::now();
469  return depth_ == 0;
470 }
471 
472 using DurationTreeMap =
473  std::unordered_map<std::thread::id, std::unique_ptr<DurationTree>>;
474 
477 
478 template <typename... Ts>
479 Duration* newDuration(Severity severity, Ts&&... args) {
480  if (g_enable_debug_timer) {
481  auto const thread_id = std::this_thread::get_id();
482  std::lock_guard<std::mutex> lock_guard(gDurationTreeMapMutex);
483  auto& duration_tree_ptr = gDurationTreeMap[thread_id];
484  if (!duration_tree_ptr) {
485  duration_tree_ptr = std::make_unique<DurationTree>(thread_id, 0);
486  }
487  return duration_tree_ptr->newDuration(severity, std::forward<Ts>(args)...);
488  }
489  return nullptr; // Inactive - don't measure or report timing.
490 }
491 
492 std::ostream& operator<<(std::ostream& os, Duration const& duration) {
493  return os << std::setw(2 * duration.depth_) << ' ' << duration.value() << "ms "
494  << duration.name_ << ' ' << filename(duration.file_) << ':' << duration.line_;
495 }
496 
497 std::ostream& operator<<(std::ostream& os, DurationTree const& duration_tree) {
498  os << std::setw(2 * duration_tree.depth_) << ' ' << "New thread("
499  << duration_tree.thread_id_ << ')';
500  for (auto const& duration_tree_node : duration_tree.durations()) {
501  os << '\n' << duration_tree_node;
502  }
503  return os << '\n'
504  << std::setw(2 * duration_tree.depth_) << ' ' << "End thread("
505  << duration_tree.thread_id_ << ')';
506 }
507 
508 // Only called by logAndEraseDurationTree() on base tree
509 boost::log::record_ostream& operator<<(boost::log::record_ostream& os,
510  DurationTreeMap::const_reference kv_pair) {
511  auto itr = kv_pair.second->durations().cbegin();
512  auto const end = kv_pair.second->durations().cend();
513  auto const& base_duration = boost::get<Duration>(*itr);
514  os << "DEBUG_TIMER thread_id(" << kv_pair.first << ")\n"
515  << base_duration.value() << "ms total duration for " << base_duration.name_;
516  for (++itr; itr != end; ++itr) {
517  os << '\n' << *itr;
518  }
519  return os;
520 }
521 
522 // Depth-first search and erase all DurationTrees. Not thread-safe.
523 struct EraseDurationTrees : boost::static_visitor<> {
524  void operator()(DurationTreeMap::const_iterator const& itr) const {
525  for (auto const& duration_tree_node : itr->second->durations()) {
526  apply_visitor(*this, duration_tree_node);
527  }
528  gDurationTreeMap.erase(itr);
529  }
530  void operator()(Duration const&) const {}
531  void operator()(DurationTree const& duration_tree) const {
532  for (auto const& duration_tree_node : duration_tree.durations()) {
533  apply_visitor(*this, duration_tree_node);
534  }
535  gDurationTreeMap.erase(duration_tree.thread_id_);
536  }
537 };
538 
539 void logAndEraseDurationTree(std::thread::id const thread_id) {
540  std::lock_guard<std::mutex> lock_guard(gDurationTreeMapMutex);
541  DurationTreeMap::const_iterator const itr = gDurationTreeMap.find(thread_id);
542  CHECK(itr != gDurationTreeMap.cend());
543  auto const& base_duration = itr->second->baseDuration();
544  if (auto log = Logger(base_duration.severity_)) {
545  log.stream(base_duration.file_, base_duration.line_) << *itr;
546  }
547  EraseDurationTrees const tree_trimmer;
548  tree_trimmer(itr);
549 }
550 
551 DebugTimer::DebugTimer(Severity severity, char const* file, int line, char const* name)
552  : duration_(newDuration(severity, file, line, name)) {}
553 
555  stop();
556 }
557 
559  if (duration_) {
560  if (duration_->stop()) {
561  logAndEraseDurationTree(std::this_thread::get_id());
562  }
563  duration_ = nullptr;
564  }
565 }
566 
569 void debugTimerNewThread(std::thread::id parent_thread_id) {
570  if (g_enable_debug_timer) {
571  auto const thread_id = std::this_thread::get_id();
572  if (thread_id != parent_thread_id) {
573  std::lock_guard<std::mutex> lock_guard(gDurationTreeMapMutex);
574  auto parent_itr = gDurationTreeMap.find(parent_thread_id);
575  if (parent_itr != gDurationTreeMap.end()) {
576  auto& duration_tree_ptr = gDurationTreeMap[thread_id];
577  if (!duration_tree_ptr) {
578  auto const current_depth = parent_itr->second->currentDepth();
579  duration_tree_ptr =
580  std::make_unique<DurationTree>(thread_id, current_depth + 1);
581  parent_itr->second->pushDurationTree(*duration_tree_ptr);
582  }
583  }
584  }
585  }
586 }
587 
588 } // namespace logger
589 
590 #endif // #ifndef __CUDACC__
std::istream & operator>>(std::istream &in, Channels &channels)
Definition: Logger.cpp:304
void pushDurationTree(DurationTree &duration_tree)
Definition: Logger.cpp:447
int const enum_value_
Definition: Logger.h:156
std::string filename(char const *path)
Definition: Logger.cpp:58
size_t min_free_space_
Definition: Logger.h:121
std::string replace_braces(std::string const &str, TAG const tag)
Definition: Logger.cpp:138
std::set< Channel > Channels
Definition: Logger.h:103
void debugTimerNewThread(std::thread::id parent_thread_id)
Definition: Logger.cpp:569
boost::log::sources::channel_logger_mt< Channel > ChannelLogger
Definition: Logger.h:147
void set_formatter(SINK &sink)
Definition: Logger.cpp:191
std::unique_ptr< boost::log::record > record_
Definition: Logger.h:158
LogOptions(char const *argv0)
Definition: Logger.cpp:62
sinks::text_file_backend::open_handler_type create_or_replace_symlink(boost::weak_ptr< SINK > weak_ptr, std::string &&symlink)
Definition: Logger.cpp:156
std::once_flag g_fatal_func_flag
Definition: Logger.cpp:245
std::deque< DurationTreeNode > durations_
Definition: Logger.cpp:436
void operator()(DurationTreeMap::const_iterator const &itr) const
Definition: Logger.cpp:524
std::string base_path_
Definition: Logger.h:107
#define LOG(tag)
Definition: Logger.h:185
Clock::time_point const start_
Definition: Logger.cpp:403
Duration(DurationTree *duration_tree, int depth, Severity severity, char const *file, int line, char const *name)
Definition: Logger.cpp:413
bool g_enable_debug_timer
Definition: Logger.cpp:17
void operator()(Duration const &) const
Definition: Logger.cpp:530
Channel
Definition: Logger.h:61
std::string join(T const &container, std::string const &delim)
const Duration & baseDuration() const
Definition: Logger.cpp:450
void operator()(DurationTree const &duration_tree) const
Definition: Logger.cpp:531
void logAndEraseDurationTree(std::thread::id const thread_id)
Definition: Logger.cpp:539
Duration * duration_
Definition: Logger.h:285
Duration * newDuration(Severity severity, Ts &&...args)
Definition: Logger.cpp:479
int currentDepth() const
Definition: Logger.cpp:454
void set_once_fatal_func(FatalFunc fatal_func)
Definition: Logger.cpp:292
sinks::synchronous_sink< sinks::text_ostream_backend > ClogSync
Definition: Logger.cpp:247
boost::program_options::options_description const & get_options() const
Definition: Logger.cpp:119
char const *const name_
Definition: Logger.cpp:411
int const line_
Definition: Logger.cpp:410
constexpr std::array< char, 8 > SeveritySymbols
Definition: Logger.h:94
Units::rep value() const
Definition: Logger.cpp:428
Channels channels_
Definition: Logger.h:118
bool const is_channel_
Definition: Logger.h:155
constexpr std::array< char, 2 > ChannelSymbols
Definition: Logger.h:65
CHECK(cgen_state)
int const depth_
Definition: Logger.cpp:407
sinks::synchronous_sink< sinks::text_file_backend > FileSync
Definition: Logger.cpp:248
void init(LogOptions const &log_opts)
Definition: Logger.cpp:265
Severity g_min_active_severity
Definition: Logger.cpp:263
std::atomic< FatalFunc > g_fatal_func
Definition: Logger.cpp:244
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t uint32_t const int64_t int32_t * error_code
DebugTimer(Severity, char const *file, int line, char const *name)
Definition: Logger.cpp:551
boost::shared_ptr< FILE_SINK > make_sink(LogOptions const &log_opts, boost::filesystem::path const &full_log_dir, TAG const tag)
Definition: Logger.cpp:210
std::thread::id const thread_id_
Definition: Logger.cpp:441
bool rotate_daily_
Definition: Logger.h:122
DurationTree *const duration_tree_
Definition: Logger.cpp:402
bool g_enable_smem_group_by true
std::string symlink_
Definition: Logger.h:115
std::mutex gDurationTreeMapMutex
Definition: Logger.cpp:475
std::unique_ptr< boost::log::record_ostream > stream_
Definition: Logger.h:159
Severity
Definition: Logger.h:73
boost::log::formatting_ostream & operator<<(boost::log::formatting_ostream &strm, boost::log::to_log_manip< Channel, tag::channel > const &manip)
Definition: Logger.cpp:178
void shutdown()
Definition: Logger.cpp:299
constexpr std::array< char const *, 8 > SeverityNames
Definition: Logger.h:85
Severity severity_
Definition: Logger.h:116
constexpr std::array< char const *, 2 > ChannelNames
Definition: Logger.h:63
bool g_any_active_channels
Definition: Logger.cpp:262
DurationTreeMap gDurationTreeMap
Definition: Logger.cpp:476
boost::program_options::options_description options_
Definition: Logger.h:108
std::deque< DurationTreeNode > const & durations() const
Definition: Logger.cpp:456
boost::log::sources::severity_logger_mt< Severity > SeverityLogger
Definition: Logger.h:150
std::string file_name_pattern_
Definition: Logger.h:114
bool g_enable_watchdog false
Definition: Execute.cpp:71
size_t rotation_size_
Definition: Logger.h:123
void set_base_path(std::string const &base_path)
Definition: Logger.cpp:133
boost::filesystem::path full_log_dir() const
Definition: Logger.cpp:115
void(*)( FatalFunc)
Definition: Logger.h:144
char const *const file_
Definition: Logger.cpp:409
int const depth_
Definition: Logger.cpp:440
std::chrono::steady_clock Clock
Definition: Logger.cpp:397
boost::log::attributes::current_process_id::value_type::native_type get_native_process_id(boost::log::value_ref< boost::log::attributes::current_process_id::value_type, tag::process_id > const &pid)
Definition: Logger.cpp:149
size_t max_files_
Definition: Logger.h:120
Logger(Channel)
Definition: Logger.cpp:349
static bool run
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t ** out
boost::variant< Duration, DurationTree & > DurationTreeNode
Definition: Logger.cpp:433
std::unordered_map< std::thread::id, std::unique_ptr< DurationTree >> DurationTreeMap
Definition: Logger.cpp:473
Severity severity_clog_
Definition: Logger.h:117
boost::filesystem::path log_dir_
Definition: Logger.h:112
Duration * newDuration(Ts &&...args)
Definition: Logger.cpp:458
Severity const severity_
Definition: Logger.cpp:408
Clock::time_point stop_
Definition: Logger.cpp:404
boost::log::record_ostream & stream(char const *file, int line)
Definition: Logger.cpp:391
void parse_command_line(int, char const *const *)
Definition: Logger.cpp:124