hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Logger.hpp
Go to the documentation of this file.
1 #ifndef LOGGER_H
2 #define LOGGER_H
3 
4 #include <Poco/Util/AbstractConfiguration.h>
5 #include <Poco/PatternFormatter.h>
6 #include <Poco/FileChannel.h>
7 #include <Poco/FormattingChannel.h>
8 #include <Poco/AutoPtr.h>
9 #include <Poco/Logger.h>
10 #include <Poco/ScopedLock.h>
11 #include <iostream>
12 #include <sstream>
13 #include <Poco/SharedPtr.h>
14 
16 
17 #define DEFAULT_LOG_SUFFIX ".log.txt"
18 
19 #define DEFAULT_LOG_ALWAYS_USE_DEF_LOG true
20 #define DEFAULT_LOG_LEVEL "information"
21 
22 #define DEFAULT_LOG_NAME "Application"
23 #define DEFAULT_LOG_PATTERN_FORMATTER "%Y-%m-%d %H:%M:%S.%c %N[%P] :%p:%t %U:%u"
24 #define DEFAULT_LOG_ERROR "Default log is not exist"
25 #define MESSAGE_WRITTEN_INTO_UNREGISTER_LOG "message written into unregister log"
26 
27 #define CHANNELS "CHANNELS"
28 #define PATTERN_FORMATTER "PatternFormatter"
29 #define BASE_NAME "application.baseName"
30 #define ALWAYS_USE_DEFAULT_LOG "LOG.alwaysUseDefaultLog"
31 #define LOG_LEVEL "LOG.log_level"
32 
33 #define DEFAULT_PURGE_AGE "1 months"
34 #define DEFAULT_ARCHIVE "timestamp"
35 #define DEFAULT_ROTATION "daily"
36 
37 #define LOGGER_ON_DEFAULT_LEVEL 7
38 #define LOGGER_OFF_LEVEL 0
39 
40 /*
41  * Application - default log which writes to the file "application_name.log.txt"
42  * If log channel not set in configuration file :
43  * if flag `alwaysUseDefaultLog` equals true - writes to the "application_name.log.txt"
44  * else if flag `alwaysUseDefaultLog` not equals true - writes to the std::cout
45  */
46 
47 /*
48  * HCE::Logger it's a static class , which may be used without creating HCE::Logger object
49  */
50 
51 namespace HCE {
52  class Logger {
53  public:
55  static void initializeLoggers ();
56  private:
57  static void initializeDefaultLogger ();
60  static void checkDefaultLogger ();
62  static std::string getDefaultChannel ();
63  private:
64  static std::string createMsgIfThatChannelNotExist (const std::string& channelName);
65  public:
67  static bool alwaysUseDefaultLog;
69  static void writeLog (const Poco::Message& msg,const std::string& channel = DEFAULT_LOG_NAME);
71  static void writeUnregisterLog (const Poco::Message& msg,const std::string& channel);
72  public:
73  static void setLevelByChannelName (const std::string& name,const std::string& level);
74  static void setLevelByChannelName (const std::string& name,const int& level);
75  public:
76  static void setLevelForAllChannel (const std::string& level);
77  static void setLevelForAllChannel (const int& level);
78  public:
79  static void off ();
80  static void on (const int& level = LOGGER_ON_DEFAULT_LEVEL);
81  static void on (const std::string& level);
82  };
83 }
84 
85 #endif