EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Logger.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Logger.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
11 #include <cassert>
12 
13 namespace Acts {
14 
15 LoggerWrapper::LoggerWrapper(const Logger& logger) : m_logger(&logger) {}
16 
17 bool LoggerWrapper::doPrint(const Logging::Level& lvl) const {
18  assert(m_logger != nullptr);
19  return m_logger->doPrint(lvl);
20 }
21 
23  assert(m_logger != nullptr);
24  return m_logger->log(lvl);
25 }
26 
28  assert(m_logger != nullptr);
29  return *m_logger;
30 }
31 
32 namespace Logging {
33 
34 namespace {
35 class NeverFilterPolicy final : public OutputFilterPolicy {
36  public:
37  ~NeverFilterPolicy() override = default;
38 
39  bool doPrint(const Level& /*lvl*/) const override { return false; }
40 };
41 
42 std::unique_ptr<const Logger> makeDummyLogger() {
43  using namespace Logging;
44  auto output = std::make_unique<DefaultPrintPolicy>(&std::cout);
45  auto print = std::make_unique<NeverFilterPolicy>();
46  return std::make_unique<const Logger>(std::move(output), std::move(print));
47 }
48 
49 std::unique_ptr<const Logger> s_dummyLogger{makeDummyLogger()};
50 LoggerWrapper s_dummyLoggerWrapper{*s_dummyLogger};
51 
52 } // namespace
53 } // namespace Logging
54 
55 std::unique_ptr<const Logger> getDefaultLogger(const std::string& name,
56  const Logging::Level& lvl,
57  std::ostream* log_stream) {
58  using namespace Logging;
59  auto output = std::make_unique<LevelOutputDecorator>(
60  std::make_unique<NamedOutputDecorator>(
61  std::make_unique<TimedOutputDecorator>(
62  std::make_unique<DefaultPrintPolicy>(log_stream)),
63  name));
64  auto print = std::make_unique<DefaultFilterPolicy>(lvl);
65  return std::make_unique<const Logger>(std::move(output), std::move(print));
66 }
67 
69  return Logging::s_dummyLoggerWrapper;
70 }
71 } // namespace Acts