LogOutputStream.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 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 #ifndef ICL_CORE_LOGGING_LOG_OUTPUT_STREAM_H_INCLUDED
29 #define ICL_CORE_LOGGING_LOG_OUTPUT_STREAM_H_INCLUDED
30 
31 #include <icl_core/BaseTypes.h>
32 #include <icl_core/os_mem.h>
33 #include <icl_core/List.h>
34 #include <icl_core/Noncopyable.h>
35 #include <icl_core/TimeStamp.h>
36 
37 #ifdef _SYSTEM_LXRT_
38 #define ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE
39 #else
40 # include <icl_core/Queue.h>
41 #endif
42 
49 
50 namespace icl_core {
51 namespace logging {
52 
76 {
77 public:
88  LogOutputStream(const icl_core::String& name, const icl_core::String& config_prefix,
89  icl_core::logging::LogLevel log_level, bool use_worker_thread = true);
90 
91  virtual ~LogOutputStream();
92 
97  void changeTimeFormat(const char* format) { m_time_format = format; }
98 
130  void changeLogFormat(const char *format);
131 
148  void push(icl_core::logging::LogLevel log_level, const char *log_stream_description,
149  const char *filename, int line, const char *classname, const char *objectname,
150  const char *function, const char *text);
151 
153  void start();
154 
158  void shutdown();
159 
162  icl_core::logging::LogLevel getLogLevel() const { return m_log_level; }
163 
166  void setLogLevel(icl_core::logging::LogLevel log_level) { m_log_level = log_level; }
167 
173  icl_core::String name() const { return m_name; }
174 
178  void printConfiguration() const;
179 
181 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
182 
186  ICL_CORE_VC_DEPRECATE_STYLE void ChangeTimeFormat(const char* format) ICL_CORE_GCC_DEPRECATE_STYLE;
187 
191  ICL_CORE_VC_DEPRECATE_STYLE void ChangeLogFormat(const char *format)
193 
198  const char *log_stream_description, const char *filename,
199  int line, const char *classname, const char *objectname,
200  const char *function, const char *text)
202 
207 
213 
220 
224  ICL_CORE_VC_DEPRECATE_STYLE void SetLogLevel(icl_core::logging::LogLevel log_level)
226 
231 
236  ICL_CORE_VC_DEPRECATE_STYLE void PrintConfiguration() const ICL_CORE_GCC_DEPRECATE_STYLE;
237 
238 #endif
239 
241 protected:
243  struct LogMessage
244  {
247  const char *log_stream = "", const char *filename = "",
248  size_t line = 0,
249  const char *class_name = "", const char *object_name = "", const char *function_name = "",
250  const char *message_text = "");
251 
254  char log_stream[cMAX_IDENTIFIER_LENGTH + 1];
255  char filename[cMAX_DESCRIPTION_LENGTH + 1];
256  size_t line;
257  char class_name[cMAX_IDENTIFIER_LENGTH + 1];
258  char object_name[cMAX_DESCRIPTION_LENGTH + 1];
259  char function_name[cMAX_IDENTIFIER_LENGTH + 1];
260  char message_text[cDEFAULT_LOG_SIZE + 1];
261  };
262 
266  bool use_worker_thread = true);
267 
268 private:
269  friend class LoggingManager;
270 
272  struct WorkerThread : public Thread, protected virtual icl_core::Noncopyable
273  {
274 #ifdef ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE
275  WorkerThread(LogOutputStream *output_stream, size_t message_queue_size,
276  icl_core::ThreadPriority priority);
277 #else
278  WorkerThread(LogOutputStream *output_stream, icl_core::ThreadPriority priority);
279 #endif
280  ~WorkerThread();
281 
282  virtual void run();
283 
284 #ifdef ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE
285  void incrementIndex(size_t& index);
286  bool isMessageQueueEmpty();
287  bool isMessageQueueFull();
288 #endif
289 
291 
292 #ifdef ICL_CORE_LOG_OUTPUT_STREAM_USE_FIXED_QUEUE
293  LogMessage *m_message_queue;
294  size_t m_message_queue_size;
295  size_t m_message_queue_read_index;
296  size_t m_message_queue_write_index;
297 #else
299  MessageQueue m_message_queue;
300 #endif
301 
304  };
305  friend struct WorkerThread;
306 
311  {
313  {
324  eT_TIMESTAMP_MS
325  };
326 
328  : type(eT_TEXT), width(0)
329  {
330  icl_core::os::memset(text, 0, 100);
331  icl_core::os::memset(suffix, 0, 100);
332  }
333 
335  size_t width;
336  char text[100];
337  char suffix[100];
338  };
339 
345  virtual void onStart() { }
353  virtual void pushImpl(const LogMessage& log_message);
359  virtual void pushImpl(const std::string& log_line);
365  virtual void onShutdown() { }
366 
367  void parseLogFormat(const char *format);
368 
371  const char *m_time_format;
372 
376 
380 
383 };
384 
385 }
386 }
387 
388 #endif
Represents absolute times.
Definition: TimeStamp.h:61
const size_t cMAX_IDENTIFIER_LENGTH
Definition: Constants.h:42
#define ICL_CORE_VC_DEPRECATE_STYLE
Definition: Deprecate.h:53
const size_t cMAX_DESCRIPTION_LENGTH
Definition: Constants.h:47
Contains icl_logging::LoggingManager.
void changeTimeFormat(const char *format)
void setLogLevel(icl_core::logging::LogLevel log_level)
#define ICL_CORE_GCC_DEPRECATE_STYLE_USE(arg)
Definition: Deprecate.h:67
Contains import/export definitions for the Win32 plattform.
icl_core::logging::LogLevel getLogLevel() const
#define ICL_CORE_VC_DEPRECATE_STYLE_USE(arg)
Definition: Deprecate.h:66
icl_core::List< LogFormatEntry > m_new_log_format
Manages the logging framework.
icl_core::List< LogFormatEntry > m_log_format
icl_core::logging::LogLevel m_log_level
Contains constants used in icl_core::logging.
Contains icl_core::logging::Thread.
Implements a platform independent mutex.
Definition: Semaphore.h:44
This is an output stream class for log messages.
Contains icl_logging::LogLevel.
std::string String
Definition: BaseTypes.h:43
Contains Interface base classes and base types.
void * memset(void *dest, int c, size_t count)
Definition: os_mem.h:46
static const icl_core::ThreadPriority m_default_worker_thread_priority
Contains TimeStamp.
Defines an entry for the message queue.
Contains icl_core::Noncopyable.
#define ICL_CORE_LOGGING_IMPORT_EXPORT
int32_t ThreadPriority
Definition: os_thread.h:50
#define cDEFAULT_LOG_SIZE
Definition: Constants.h:36
Implements processing the message queue in a separate thread.
static const icl_core::String m_default_log_format
#define ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Deprecate.h:54
Contains global functions for memory manipulation, encapsulated into the icl_core::os namespace...
icl_core::String name() const
Contains icl_core::logging::Semaphore.


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