PLCnext API Documentation  20.6.0.30321
LogManager.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/System/Core/TypeName.hxx"
9 #include "Arp/System/Core/AppDomainSingleton.hxx"
10 #include "Arp/System/Commons/Threading/Mutex.hpp"
11 #include "Arp/System/Commons/Diagnostics/Logging/LogLevel.hpp"
12 #include "Arp/System/Commons/Diagnostics/Logging/Internal/LogAdapter.hpp"
13 #include <new>
14 
15 // forwards
16 namespace Arp
17 {
18 class AppDomain;
19 }
20 namespace log4cplus
21 {
22 class Initializer;
23 class Hierarchy;
24 class Logger;
25 }
26 
27 namespace Arp { namespace System { namespace Commons { namespace Diagnostics { namespace Logging
28 {
29 
30 using namespace Arp::System::Commons::Threading;
31 using LogAdapter = Internal::LogAdapter;
32 
33 // singleton log manager class
34 class LogManager : public AppDomainSingleton<LogManager>
35 {
36  friend class AppDomainSingleton<LogManager>;
37 
38 private: // typedefs
40 
41 private:
42  LogManager(void);
43  LogManager(const LogManager&) = delete;
44  ~LogManager(void);
45  LogManager& operator=(const LogManager&) = delete;
46 
47 public: // singleton operations
48  static void AssignAppDomain(AppDomain& otherDomain);
49  static void Create(const char* configFileName);
50  static void Create(bool enableConsoleLogging, const char* logFileName = nullptr);
51  static void Create(LogLevel logLevel, bool enableConsoleLogging, const char* logFileName = nullptr);
52  static void Create(const char* layoutPattern, bool enableConsoleLogging, const char* logFileName = nullptr);
53  static void Create(LogLevel logLevel, const char* layoutPattern, bool enableConsoleLogging, const char* logFileName = nullptr);
54  static void Dispose(void);
55 
56 public: // setter/getter
57  void SetRootLevel(LogLevel value);
58  LogLevel GetRootLevel(void);
59  Mutex& GetSyncRoot(void);
60 
61 public: // operations
62  LogAdapter CreateLogAdapter(const char* loggerName);
63 
64 private: // methods
65  void Initialize(LogLevel rootLevel, log4cplus::Logger& rootLogger);
66  log4cplus::Logger GetLoggerInstance(const char* loggerName);
67 
68 private: // fields
69  Mutex syncRoot;
70  LogAdapter::Ptr rootLogAdapterPtr;
71  log4cplus::Hierarchy* pRootHierarchy;
72  log4cplus::Initializer* pInitializer;
73 
74 private: // const static data
75  static const char* const defaultLayoutPattern;
76 };
77 
79 // inline methods of class LogManager
80 
81 inline void LogManager::SetRootLevel(LogLevel value)
82 {
83  this->rootLogAdapterPtr->SetLogLevel(value);
84 }
85 
86 inline LogLevel LogManager::GetRootLevel()
87 {
88  // OR: do not call LogAdapter::GetLogLevel() - this would cause a cyclic method invocation
89  return this->rootLogAdapterPtr->logLevel;
90 }
91 
92 inline Mutex& LogManager::GetSyncRoot()
93 {
94  return this->syncRoot;
95 }
96 
97 inline void LogManager::Create(bool enableConsoleLogging, const char* logFileName)
98 {
99  Create(LogLevel::Default, nullptr, enableConsoleLogging, logFileName);
100 }
101 
102 inline void LogManager::Create(LogLevel logLevel, bool enableConsoleLogging, const char* logFileName)
103 {
104  Create(logLevel, nullptr, enableConsoleLogging, logFileName);
105 }
106 
107 inline void LogManager::Create(const char* layoutPattern, bool enableConsoleLogging, const char* logFileName)
108 {
109  Create(LogLevel::Default, layoutPattern, enableConsoleLogging, logFileName);
110 }
111 
112 }}}}} // end of namesapce Arp::System::Commons::Diagnostics::Logging
Mutual exclusion object to prevent data from concurrent modifications.
Definition: Mutex.hpp:25
This class represents a single application domain for each process and is implemented as singleton...
Definition: AppDomain.hpp:122
Namespace for classes handling threads and synchronization
Root namespace for the PLCnext API
This class implements the singleton pattern for singletons with process wide scope.
Definition: AppDomainSingleton.hxx:24
System components used by the System, Device, Plc or Io domains.
Definition: LogAdapter.hpp:14