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


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:18