icl_core_logging/Logging.cpp
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 //----------------------------------------------------------------------
21 //----------------------------------------------------------------------
23 
24 #include <icl_core/os_lxrt.h>
25 #include <icl_core/os_string.h>
26 #include <icl_core_config/Config.h>
27 
28 namespace icl_core {
29 namespace logging {
30 
32 {
33 #ifdef _SYSTEM_LXRT_
34  // Don't use FormatIso8601() in a hard realtime LXRT task, because
35  // it might use a POSIX mutex!
37  {
38  char time_buffer[100];
39  memset(time_buffer, 0, 100);
40  icl_core::os::snprintf(time_buffer, 99, "%d %02d:%02d:%02d(HRT)",
41  int(time_stamp.days()),
42  int(time_stamp.hours()),
43  int(time_stamp.minutes()),
44  int(time_stamp.seconds()));
45  stream << time_buffer;
46  }
47  else
48 #endif
49  {
50  stream << time_stamp.formatIso8601();
51  }
52 
53  return stream;
54 }
55 
57 {
58  int64_t calc_secs = time_span.tsSec();
59  int64_t calc_nsec = time_span.tsNSec();
60  if (calc_secs < 0)
61  {
62  stream << "-";
63  calc_secs = -calc_secs;
64  }
65  if (calc_secs > 3600)
66  {
67  stream << calc_secs / 3600 << "h";
68  calc_secs = calc_secs % 3600;
69  }
70  if (calc_secs > 60)
71  {
72  stream << calc_secs / 60 << "m";
73  calc_secs=calc_secs % 60;
74  }
75  if (calc_secs > 0)
76  {
77  stream << calc_secs << "s";
78  }
79 
80  if (calc_nsec / 1000000 * 1000000 == calc_nsec)
81  {
82  stream << calc_nsec / 1000000 << "ms";
83  }
84  else if (calc_nsec / 1000 * 1000 == calc_nsec)
85  {
86  stream << calc_nsec << "us";
87  }
88  else
89  {
90  stream << calc_nsec << "ns";
91  }
92 
93  return stream;
94 }
95 
96 REGISTER_LOG_STREAM(Default)
97 REGISTER_LOG_STREAM(Nirwana)
98 REGISTER_LOG_STREAM(QuickDebug)
99 
100 bool initialize(int &argc, char *argv[], bool remove_read_arguments)
101 {
103  argc, argv,
106 }
107 
108 bool initialize(int &argc, char *argv[],
111 {
112  bool result = icl_core::config::initialize(argc, argv, cleanup, registration_check);
114  return result;
115 }
116 
118 {
120 }
121 
122 void shutdown()
123 {
125 }
126 
127 boost::shared_ptr<LifeCycle> autoStart(int &argc, char *argv[])
128 {
129  return boost::shared_ptr<LifeCycle>(new LifeCycle(argc, argv));
130 }
131 
133 {
135 }
136 
138 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
139 
140 bool Initialize(int &argc, char *argv[], bool remove_read_arguments)
141 {
142  return ::icl_core::logging::initialize(argc, argv, remove_read_arguments);
143 }
144 
145 bool Initialize(int &argc, char *argv[],
148 {
149  return ::icl_core::logging::initialize(argc, argv, cleanup, registration_check);
150 }
151 
152 void Initialize() { initialize(); }
153 
154 void Shutdown() { shutdown(); }
155 
156 #endif
157 
159 }
160 }
all options have to be registered
Definition: GetoptParser.h:59
Represents absolute times.
Definition: TimeStamp.h:61
bool initialize(int &argc, char *argv[], bool remove_read_arguments)
bool initialize(int &argc, char *argv[], bool remove_read_arguments)
Definition: Config.cpp:50
int64_t minutes() const
Definition: TimeBase.h:123
Contains global functions for string manipulation, encapsulated into the icl_core::os namespace...
int64_t days() const
Use this function if you want to express the time in days.
Definition: TimeBase.h:107
known command line options are removed
Definition: GetoptParser.h:67
static LoggingManager & instance()
Base header file for the configuration framework.
Defines 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
signed __int64 int64_t
Definition: msvc_stdint.h:102
int32_t tsNSec() const
Definition: TimeSpan.cpp:153
void setLogLevel(icl_core::logging::LogLevel log_level)
Set a global log level for all streams.
bool isThisHRT()
Definition: os_lxrt.cpp:159
command line options are left untouched
Definition: GetoptParser.h:66
Contains global LXRT functions.
void setLogLevel(icl_core::logging::LogLevel log_level)
Set the log level globally for all existing streams.
REGISTER_LOG_STREAM(Performance)
Repesents absolute times.
Definition: TimeSpan.h:46
Implements the actual logging for an individual thread.
Definition: ThreadStream.h:58
bool isThisLxrtTask()
Definition: os_lxrt.cpp:150
int64_t tsSec() const
Definition: TimeSpan.cpp:148
ThreadStream & operator<<(ThreadStream &stream, const icl_core::TimeStamp &time_stamp)
void * memset(void *dest, int c, size_t count)
Definition: os_mem.h:46
int64_t hours() const
Definition: TimeBase.h:115
String formatIso8601() const
Definition: TimeStamp.cpp:221
int64_t seconds() const
Definition: TimeBase.h:131
int snprintf(char *buffer, size_t maxlen, const char *format,...)
Definition: os_string.cpp:28


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