EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CustomDefaultLogger.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CustomDefaultLogger.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-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 <algorithm>
12 
13 namespace Acts {
14 
15 namespace Logging {
16 
20 class MirrorOutputDecorator final : public OutputDecorator {
21  public:
26  MirrorOutputDecorator(std::unique_ptr<OutputPrintPolicy> wrappee,
27  unsigned int maxWidth = 180)
28  : OutputDecorator(std::move(wrappee)), m_maxWidth(maxWidth) {}
29 
36  void flush(const Level& lvl, const std::ostringstream& input) override {
37  std::ostringstream os;
38  std::string text = input.str();
39  std::reverse(text.begin(), text.end());
40  os << std::right << std::setw(m_maxWidth) << text;
41  OutputDecorator::flush(lvl, os);
42  }
43 
44  private:
46  unsigned int m_maxWidth;
47 };
48 
49 } // namespace Logging
50 
62 std::unique_ptr<const Logger> getDefaultLogger(const std::string& name,
63  const Logging::Level& lvl,
64  std::ostream* log_stream) {
65  using namespace Logging;
66  auto output = std::make_unique<LevelOutputDecorator>(
67  std::make_unique<NamedOutputDecorator>(
68  std::make_unique<TimedOutputDecorator>(
69  std::make_unique<MirrorOutputDecorator>(
70  std::make_unique<DefaultPrintPolicy>(log_stream))),
71  name));
72  auto print = std::make_unique<DefaultFilterPolicy>(lvl);
73  return std::make_unique<const Logger>(std::move(output), std::move(print));
74 }
75 
76 } // namespace Acts