Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00021
00022 #include "icl_core_logging/Logging.h"
00023
00024 #include <icl_core/os_lxrt.h>
00025 #include <icl_core/os_string.h>
00026 #include <icl_core_config/Config.h>
00027
00028 namespace icl_core {
00029 namespace logging {
00030
00031 ThreadStream& operator << (ThreadStream& stream, const icl_core::TimeStamp& time_stamp)
00032 {
00033 #ifdef _SYSTEM_LXRT_
00034
00035
00036 if (icl_core::os::isThisLxrtTask() && icl_core::os::isThisHRT())
00037 {
00038 char time_buffer[100];
00039 memset(time_buffer, 0, 100);
00040 icl_core::os::snprintf(time_buffer, 99, "%d %02d:%02d:%02d(HRT)",
00041 int(time_stamp.days()),
00042 int(time_stamp.hours()),
00043 int(time_stamp.minutes()),
00044 int(time_stamp.seconds()));
00045 stream << time_buffer;
00046 }
00047 else
00048 #endif
00049 {
00050 stream << time_stamp.formatIso8601();
00051 }
00052
00053 return stream;
00054 }
00055
00056 ThreadStream& operator << (ThreadStream& stream, const icl_core::TimeSpan& time_span)
00057 {
00058 int64_t calc_secs = time_span.tsSec();
00059 int64_t calc_nsec = time_span.tsNSec();
00060 if (calc_secs < 0)
00061 {
00062 stream << "-";
00063 calc_secs = -calc_secs;
00064 }
00065 if (calc_secs > 3600)
00066 {
00067 stream << calc_secs / 3600 << "h";
00068 calc_secs = calc_secs % 3600;
00069 }
00070 if (calc_secs > 60)
00071 {
00072 stream << calc_secs / 60 << "m";
00073 calc_secs=calc_secs % 60;
00074 }
00075 if (calc_secs > 0)
00076 {
00077 stream << calc_secs << "s";
00078 }
00079
00080 if (calc_nsec / 1000000 * 1000000 == calc_nsec)
00081 {
00082 stream << calc_nsec / 1000000 << "ms";
00083 }
00084 else if (calc_nsec / 1000 * 1000 == calc_nsec)
00085 {
00086 stream << calc_nsec << "us";
00087 }
00088 else
00089 {
00090 stream << calc_nsec << "ns";
00091 }
00092
00093 return stream;
00094 }
00095
00096 REGISTER_LOG_STREAM(Default)
00097 REGISTER_LOG_STREAM(Nirwana)
00098 REGISTER_LOG_STREAM(QuickDebug)
00099
00100 bool initialize(int &argc, char *argv[], bool remove_read_arguments)
00101 {
00102 return icl_core::logging::initialize(
00103 argc, argv,
00104 remove_read_arguments ? icl_core::config::Getopt::eCLC_Cleanup : icl_core::config::Getopt::eCLC_None,
00105 icl_core::config::Getopt::ePRC_Strict);
00106 }
00107
00108 bool initialize(int &argc, char *argv[],
00109 icl_core::config::Getopt::CommandLineCleaning cleanup,
00110 icl_core::config::Getopt::ParameterRegistrationCheck registration_check)
00111 {
00112 bool result = icl_core::config::initialize(argc, argv, cleanup, registration_check);
00113 LoggingManager::instance().initialize();
00114 return result;
00115 }
00116
00117 void initialize()
00118 {
00119 LoggingManager::instance().initialize();
00120 }
00121
00122 void shutdown()
00123 {
00124 LoggingManager::instance().shutdown();
00125 }
00126
00127 boost::shared_ptr<LifeCycle> autoStart(int &argc, char *argv[])
00128 {
00129 return boost::shared_ptr<LifeCycle>(new LifeCycle(argc, argv));
00130 }
00131
00132 void setLogLevel(icl_core::logging::LogLevel log_level)
00133 {
00134 LoggingManager::instance().setLogLevel(log_level);
00135 }
00136
00138 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00139
00140 bool Initialize(int &argc, char *argv[], bool remove_read_arguments)
00141 {
00142 return ::icl_core::logging::initialize(argc, argv, remove_read_arguments);
00143 }
00144
00145 bool Initialize(int &argc, char *argv[],
00146 icl_core::config::Getopt::CommandLineCleaning cleanup,
00147 icl_core::config::Getopt::ParameterRegistrationCheck registration_check)
00148 {
00149 return ::icl_core::logging::initialize(argc, argv, cleanup, registration_check);
00150 }
00151
00152 void Initialize() { initialize(); }
00153
00154 void Shutdown() { shutdown(); }
00155
00156 #endif
00157
00158
00159 }
00160 }