LoggingManager.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00026 //----------------------------------------------------------------------
00027 #ifndef ICL_CORE_LOGGING_LOGGING_MANAGER_H_INCLUDED
00028 #define ICL_CORE_LOGGING_LOGGING_MANAGER_H_INCLUDED
00029 
00030 #include <icl_core/BaseTypes.h>
00031 #include <icl_core/List.h>
00032 #include <icl_core/Map.h>
00033 #include "icl_core_logging/ImportExport.h"
00034 #include "icl_core_logging/LogLevel.h"
00035 
00036 #include <boost/shared_ptr.hpp>
00037 
00038 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00039 # include "icl_core/Deprecate.h"
00040 #endif
00041 
00042 namespace icl_core {
00043 namespace logging {
00044 
00045 class LogOutputStream;
00046 class LogStream;
00047 
00048 typedef LogOutputStream* (*LogOutputStreamFactory)(const icl_core::String& name,
00049                                                    const icl_core::String& config_prefix,
00050                                                    LogLevel log_level);
00051 typedef LogStream* (*LogStreamFactory)();
00052 
00061 class ICL_CORE_LOGGING_IMPORT_EXPORT LoggingManager
00062 {
00063 public:
00064   static LoggingManager& instance()
00065   {
00066     static LoggingManager manager_instance;
00067     return manager_instance;
00068   }
00069 
00075   void configure();
00076 
00087   void initialize();
00088 
00091   bool initialized() const { return m_initialized; }
00092 
00096   void assertInitialized() const;
00097 
00100   void registerLogOutputStream(const icl_core::String& name, LogOutputStreamFactory factory);
00101 
00104   void removeLogOutputStream(LogOutputStream *log_output_stream, bool remove_from_list = true);
00105 
00108   void registerLogStream(const icl_core::String& name, LogStreamFactory factory);
00109 
00112   void registerLogStream(LogStream *log_stream);
00113 
00116   void removeLogStream(const icl_core::String& log_stream_name);
00117 
00122   void printConfiguration() const;
00123 
00127   void changeLogFormat(const icl_core::String& name, const char *format = "~T ~S(~L)~ C~(O~::D: ~E");
00128 
00134   void shutdown();
00135 
00137   void setLogLevel(icl_core::logging::LogLevel log_level);
00138 
00140 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00141 
00142   static ICL_CORE_VC_DEPRECATE_STYLE LoggingManager& Instance()
00143     ICL_CORE_GCC_DEPRECATE_STYLE;
00144 
00148   ICL_CORE_VC_DEPRECATE_STYLE void Configure()
00149     ICL_CORE_GCC_DEPRECATE_STYLE;
00150 
00154   ICL_CORE_VC_DEPRECATE_STYLE void Initialize()
00155     ICL_CORE_GCC_DEPRECATE_STYLE;
00156 
00160   ICL_CORE_VC_DEPRECATE_STYLE bool Initialized() const
00161     ICL_CORE_GCC_DEPRECATE_STYLE;
00162 
00166   ICL_CORE_VC_DEPRECATE_STYLE void AssertInitialized() const
00167     ICL_CORE_GCC_DEPRECATE_STYLE;
00168 
00172   ICL_CORE_VC_DEPRECATE_STYLE void RegisterLogOutputStream(const icl_core::String& name,
00173                                                            LogOutputStreamFactory factory)
00174     ICL_CORE_GCC_DEPRECATE_STYLE;
00175 
00179   ICL_CORE_VC_DEPRECATE_STYLE void RemoveLogOutputStream(LogOutputStream *log_output_stream,
00180                                                          bool remove_from_list = true)
00181     ICL_CORE_GCC_DEPRECATE_STYLE;
00182 
00186   ICL_CORE_VC_DEPRECATE_STYLE void RegisterLogStream(const icl_core::String& name,
00187                                                      LogStreamFactory factory)
00188     ICL_CORE_GCC_DEPRECATE_STYLE;
00189 
00193   ICL_CORE_VC_DEPRECATE_STYLE void RegisterLogStream(LogStream *log_stream)
00194     ICL_CORE_GCC_DEPRECATE_STYLE;
00195 
00199   ICL_CORE_VC_DEPRECATE_STYLE void RemoveLogStream(const icl_core::String& log_stream_name)
00200     ICL_CORE_GCC_DEPRECATE_STYLE;
00201 
00205   ICL_CORE_VC_DEPRECATE_STYLE void PrintConfiguration() const
00206     ICL_CORE_GCC_DEPRECATE_STYLE;
00207 
00211   ICL_CORE_VC_DEPRECATE_STYLE void ChangeLogFormat(const icl_core::String& name,
00212                                                    const char *format = "~T ~S(~L)~ C~(O~::D: ~E")
00213     ICL_CORE_GCC_DEPRECATE_STYLE;
00214 
00218   ICL_CORE_VC_DEPRECATE_STYLE void Shutdown()
00219     ICL_CORE_GCC_DEPRECATE_STYLE;
00220 
00221 #endif
00222 
00223 
00224 private:
00225   typedef icl_core::List<icl_core::String> StringList;
00226 
00228   struct LogOutputStreamConfig
00229   {
00233     icl_core::String output_stream_name;
00235     icl_core::String name;
00237     LogLevel log_level;
00239     StringList log_streams;
00240   };
00241   typedef icl_core::Map<icl_core::String, LogOutputStreamConfig> LogOutputStreamConfigMap;
00242 
00244   struct LogStreamConfig
00245   {
00247     icl_core::String name;
00249     LogLevel log_level;
00250   };
00251   typedef icl_core::Map<icl_core::String, LogStreamConfig> LogStreamConfigMap;
00252 
00253   LoggingManager();
00254 
00255   ~LoggingManager();
00256 
00257   // Forbid copying logging manager objects.
00258   LoggingManager(const LoggingManager&);
00259   LoggingManager& operator = (const LoggingManager&);
00260 
00261   bool m_initialized;
00262   bool m_shutdown_running;
00263 
00264   LogOutputStreamConfigMap m_output_stream_config;
00265   LogStreamConfigMap m_log_stream_config;
00266 
00267   typedef icl_core::Map<icl_core::String, LogStream*> LogStreamMap;
00268   typedef icl_core::Map<icl_core::String, LogOutputStreamFactory> LogOutputStreamFactoryMap;
00269   typedef icl_core::Map<icl_core::String, LogStreamFactory> LogStreamFactoryMap;
00270   typedef icl_core::Map<icl_core::String, LogOutputStream*> LogOutputStreamMap;
00271   LogStreamMap m_log_streams;
00272   LogOutputStreamFactoryMap m_log_output_stream_factories;
00273   LogStreamFactoryMap m_log_stream_factories;
00274   LogOutputStreamMap m_log_output_streams;
00275 
00276   LogOutputStream *m_default_log_output;
00277 };
00278 
00280 namespace hidden {
00281 
00288 class ICL_CORE_LOGGING_IMPORT_EXPORT LogOutputStreamRegistrar
00289 {
00290 public:
00291   LogOutputStreamRegistrar(const icl_core::String& name, LogOutputStreamFactory factory);
00292 };
00293 
00299 class ICL_CORE_LOGGING_IMPORT_EXPORT LogStreamRegistrar
00300 {
00301 public:
00302   LogStreamRegistrar(const icl_core::String& name, LogStreamFactory factory);
00303 };
00304 
00305 }
00306 
00310 class ICL_CORE_LOGGING_IMPORT_EXPORT LifeCycle
00311 {
00312 public:
00314   typedef boost::shared_ptr<LifeCycle> Ptr;
00316   typedef boost::shared_ptr<const LifeCycle> ConstPtr;
00317 
00319   LifeCycle(int &argc, char *argv[]);
00320 
00322   ~LifeCycle();
00323 };
00324 
00325 }
00326 }
00327 
00328 #endif


fzi_icl_core
Author(s):
autogenerated on Thu Jun 6 2019 20:22:24