iMSTK
Interactive Medical Simulation Toolkit
imstkLoggerG3.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include <g3log/logmessage.hpp>
10 #include <g3log/logworker.hpp>
11 
12 #include <memory>
13 
14 namespace imstk
15 {
21 struct stdSink
22 {
23  // Linux xterm color
24  // http://stackoverflow.com/questions/2616906/how-do-i-output-coloured-text-to-a-linux-terminal
25  enum class FontColor
26  {
27  Yellow = 33,
28  Red = 31,
29  Green = 32,
30  White = 97
31  };
32 
33  FontColor GetColor(const LEVELS level) const;
34  void ReceiveLogMessage(g3::LogMessageMover logEntry);
35 };
36 
37 using FileSinkHandle = g3::SinkHandle<g3::FileSink>;
38 using StdoutSinkHandle = g3::SinkHandle<stdSink>;
39 
45 class LoggerG3
46 {
47 public:
48 
53  static LoggerG3& getInstance();
54 
59  static LoggerG3& startLogger();
60 
61  // Disable copy & move constructors & assignments
62  LoggerG3(const LoggerG3&) = delete;
63  LoggerG3& operator=(const LoggerG3&) = delete;
64  LoggerG3(LoggerG3&&) = delete;
65  LoggerG3& operator=(LoggerG3&&) = delete;
66 
70  std::unique_ptr<StdoutSinkHandle> addStdoutSink();
71 
75  std::unique_ptr<FileSinkHandle> addFileSink(const std::string& name, const std::string& path = "./");
76 
80  template<typename T, typename DefaultLogCall>
81  std::unique_ptr<g3::SinkHandle<T>> addSink(std::unique_ptr<T> real_sink, DefaultLogCall call);
82 
86  void initialize();
87 
91  void destroy();
92 
93 private:
94 
95  LoggerG3();
96 
97  std::shared_ptr<g3::LogWorker> m_g3logWorker;
98 };
99 
100 template<typename T, typename DefaultLogCall>
101 std::unique_ptr<g3::SinkHandle<T>>
102 imstk::LoggerG3::addSink(std::unique_ptr<T> real_sink, DefaultLogCall call)
103 {
104  return m_g3logWorker->addSink(std::move(real_sink), call);
105 }
106 } // namespace imstk
A standard sink that prints the message to a standard output.
Definition: imstkLoggerG3.h:21
Compound Geometry.
std::unique_ptr< g3::SinkHandle< T > > addSink(std::unique_ptr< T > real_sink, DefaultLogCall call)
Add your own sink.