icl_core_logging/Logging.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
24 //----------------------------------------------------------------------
25 #ifndef ICL_CORE_LOGGING_LOGGING_H_INCLUDED
26 #define ICL_CORE_LOGGING_LOGGING_H_INCLUDED
27 
28 #include <assert.h>
29 #include <boost/shared_ptr.hpp>
30 
31 #include <icl_core/TimeSpan.h>
32 #include <icl_core/TimeStamp.h>
39 
40 // -- START Deprecated compatibility headers --
43 // -- END Deprecated compatibility headers --
44 
53 
54 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
55 # include "icl_core/Deprecate.h"
56 #endif
57 
58 #define LOG_THREAD_STREAM(name) name::instance().ThreadStream()
59 
60 #ifndef _IC_BUILDER_DEPRECATED_STYLE_
61 # define DECLARE_LOG_STREAM_CLASS_DEFINITION(name) \
62  name : public ::icl_core::logging::LogStream \
63  { \
64  public: \
65  static ::icl_core::logging::LogStream& instance(); \
66  static ::icl_core::logging::LogStream *create(); \
67  private: \
68  name() \
69  : LogStream(#name) \
70  { } \
71  ~name() { } \
72  static name *m_instance; \
73  friend class ::icl_core::logging::LoggingManager; \
74  friend class ::icl_core::logging::hidden::LogStreamRegistrar; \
75  };
76 #else
77 // Provide deprecated method calls as well.
78 # define DECLARE_LOG_STREAM_CLASS_DEFINITION(name) \
79  name : public ::icl_core::logging::LogStream \
80  { \
81  public: \
82  static ::icl_core::logging::LogStream& instance(); \
83  static ::icl_core::logging::LogStream *create(); \
84  static ICL_CORE_VC_DEPRECATE_STYLE ::icl_core::logging::LogStream& Instance() ICL_CORE_GCC_DEPRECATE_STYLE; \
85  static ICL_CORE_VC_DEPRECATE_STYLE ::icl_core::logging::LogStream *Create() ICL_CORE_GCC_DEPRECATE_STYLE; \
86  private: \
87  name() \
88  : LogStream(#name) \
89  { } \
90  ~name() { } \
91  static name *m_instance; \
92  friend class ::icl_core::logging::LoggingManager; \
93  friend class ::icl_core::logging::hidden::LogStreamRegistrar; \
94  }; \
95  inline ::icl_core::logging::LogStream& name::Instance() \
96  { return instance(); } \
97  inline ::icl_core::logging::LogStream *name::Create() \
98  { return create(); }
99 #endif
100 
101 #define DECLARE_LOG_STREAM(name) class DECLARE_LOG_STREAM_CLASS_DEFINITION(name)
102 #define DECLARE_LOG_STREAM_IMPORT_EXPORT(name, decl) class decl DECLARE_LOG_STREAM_CLASS_DEFINITION(name)
103 
104 // Remark: The log stream object is created here but will be deleted in the
105 // destructor of LoggingManager!
106 #define REGISTER_LOG_STREAM(name) \
107  name * name::m_instance = NULL; \
108  ::icl_core::logging::LogStream& name::instance() \
109  { \
110  if (m_instance == NULL) \
111  { \
112  std::cout << "WARNING: Logging Instance is null, did you initialize the logging framework?\nYou should initialize the logging framework at the beginning of your program. This will also enable setting the log level on the command line." << std::endl; \
113  ::icl_core::logging::LoggingManager::instance().initialize(); \
114  assert(m_instance != NULL && "Tried to initialize LoggingManager but m_instance still not available."); \
115  return *m_instance; \
116  } \
117  else \
118  { \
119  return *m_instance; \
120  } \
121  } \
122  ::icl_core::logging::LogStream * name::create() \
123  { \
124  if (m_instance == NULL) \
125  { \
126  m_instance = new name; \
127  } \
128  return m_instance; \
129  } \
130  ::icl_core::logging::hidden::LogStreamRegistrar registrar##name(#name, &name::create);
131 
132 #define REGISTER_LOG_OUTPUT_STREAM(name, factory) \
133  ::icl_core::logging::hidden::LogOutputStreamRegistrar registrar##name(#name, factory);
134 
135 #define DECLARE_LOG_STREAM_OPERATOR(object_type) \
136  ::icl_core::logging::ThreadStream & operator << (::icl_core::logging::ThreadStream &str, \
137  const object_type &object);
138 
139 #ifdef _SYSTEM_LXRT_
140 #define REGISTER_LOG_STREAM_OPERATOR(object_type) \
141  ::icl_core::logging::ThreadStream & operator << (::icl_core::logging::ThreadStream &str, \
142  const object_type &object) \
143  { \
144  str << "std::ostream redirection is not available in LXRT"; \
145  return str; \
146  }
147 #else // _SYSTEM_LXRT_
148 #define REGISTER_LOG_STREAM_OPERATOR(object_type) \
149  ::icl_core::logging::ThreadStream & operator << (::icl_core::logging::ThreadStream &str, \
150  const object_type &object) \
151  { \
152  std::ostringstream stream; \
153  stream << object; \
154  str << stream.str(); \
155  return str; \
156  }
157 #endif // _SYSTEM_LXRT_
158 
159 namespace icl_core {
161 namespace logging {
162 
164 ThreadStream& operator << (ThreadStream& stream, const icl_core::TimeStamp& time_stamp);
165 
167 ThreadStream& operator << (ThreadStream& stream, const icl_core::TimeSpan& time_span);
168 
172 
173 
177 bool ICL_CORE_LOGGING_IMPORT_EXPORT initialize(int& argc, char *argv[], bool remove_read_arguments);
178 
184 initialize(int& argc, char *argv[],
189 
196 
200 
201 boost::shared_ptr<LifeCycle> ICL_CORE_LOGGING_IMPORT_EXPORT autoStart(int &argc, char *argv[]);
202 
205 
206 
208 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
209 
214 Initialize(int& argc, char *argv[], bool remove_read_arguments)
216 
221 Initialize(int& argc, char *argv[],
227 
233 
239 
240 #endif
241 
243 }
244 }
245 
246 #endif
all options have to be registered
Definition: GetoptParser.h:59
Represents absolute times.
Definition: TimeStamp.h:61
Contains icl_logging::tLoggingManager.
bool initialize(int &argc, char *argv[], bool remove_read_arguments)
#define ICL_CORE_VC_DEPRECATE_STYLE
Definition: Deprecate.h:53
Contains icl_logging::ThreadStream.
Contains icl_logging::LoggingManager.
Defines SLOGGING logging macros.
Contains macros to deprecate classes, types, functions and variables.
Contains Getopt.
Contains import/export definitions for the Win32 plattform.
Defines LLOGGING logging macros.
boost::shared_ptr< LifeCycle > autoStart(int &argc, char *argv[])
ICL_CORE_VC_DEPRECATE_STYLE bool Initialize(int &argc, char *argv[], bool remove_read_arguments) ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Config.h:902
Defines logging macros.
Contains constants used in icl_core::logging.
Defines MLOGGING logging macros.
void setLogLevel(icl_core::logging::LogLevel log_level)
Set a global log level for all streams.
command line options are left untouched
Definition: GetoptParser.h:66
#define DECLARE_LOG_STREAM_IMPORT_EXPORT(name, decl)
Repesents absolute times.
Definition: TimeSpan.h:46
ThreadStream & operator<<(ThreadStream &stream, const icl_core::TimeStamp &time_stamp)
Contains icl_logging::LogStream.
Contains TimeStamp.
#define ICL_CORE_LOGGING_IMPORT_EXPORT
#define ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Deprecate.h:54


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58