Apache Log4cxx: loggerinstance.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18#ifndef LOG4CXX_LOGGER_INSTANCE_HDR_

19#define LOG4CXX_LOGGER_INSTANCE_HDR_

20

23

24namespace LOG4CXX_NS

25{

26

47{

48 bool m_hadConfiguration;

50public:

53 {}

55 template

57 : m_hadConfiguration(LogManager::exists(instanceName))

58 , m_logger(LogManager::getLogger(instanceName))

59 {

60 }

63 {

64 reset();

65 }

66

68 {

69 return m_logger;

70 }

71

72 explicit operator bool() const noexcept

73 {

74 return !!m_logger;

75 }

76

78 {

79 return m_logger;

80 }

81

82 operator const LoggerPtr&() const noexcept

83 {

84 return m_logger;

85 }

86

88 {

89 return m_logger.get();

90 }

91

93 {

94 return m_logger.get();

95 }

96

99 {

100 if (m_logger && !m_hadConfiguration)

101 {

102 auto name = m_logger->getName();

103 m_logger.reset();

104 LogManager::removeLogger(name);

105 }

106 else

107 {

108 m_hadConfiguration = false;

109 m_logger.reset();

110 }

111 }

112

114 template

115 void reset(const StringType& instanceName)

116 {

117 reset();

118 m_hadConfiguration = !!LogManager::exists(instanceName);

119 m_logger = LogManager::getLogger(instanceName);

120 }

121};

122

123}

124

125#endif

Use the LogManager class to retreive Logger instances or to operate on the current LoggerRepository.

Definition: logmanager.h:45

A smart pointer (implicity convertable to LoggerPtr) that conditionally removes a Logger from the spi...

Definition: loggerinstance.h:47

LoggerInstancePtr(const StringType &instanceName)

A separately configurable logger named instanceName.

Definition: loggerinstance.h:56

Logger * get() noexcept

Definition: loggerinstance.h:87

const Logger * get() const noexcept

Definition: loggerinstance.h:92

void reset(const StringType &instanceName)

Change this to a logger named instanceName.

Definition: loggerinstance.h:115

LoggerInstancePtr()

A null LoggerPtr.

Definition: loggerinstance.h:52

const LoggerPtr & operator->() const noexcept

Definition: loggerinstance.h:67

~LoggerInstancePtr()

Conditionally remove the logger from the the spi::LoggerRepository.

Definition: loggerinstance.h:62

void reset()

Conditionally remove the Logger from the spi::LoggerRepository.

Definition: loggerinstance.h:98

This is the central class in the log4cxx package.

Definition: log4cxx/logger.h:51

std::shared_ptr< Logger > LoggerPtr

Definition: defaultloggerfactory.h:27