Apache Log4cxx
Version 1.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
loggerinstance.h
Go to the documentation of this file.
1
/*
2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*/
17
18
#ifndef LOG4CXX_LOGGER_INSTANCE_HDR_
19
#define LOG4CXX_LOGGER_INSTANCE_HDR_
20
21
#include <
log4cxx/logmanager.h
>
22
#include <
log4cxx/logger.h
>
23
24
namespace
LOG4CXX_NS
25
{
26
46
class
LoggerInstancePtr
47
{
48
bool
m_hadConfiguration;
49
LoggerPtr
m_logger;
50
public
:
// ...structors
52
LoggerInstancePtr
() : m_hadConfiguration(false)
53
{}
54
55
template
<
class
StringType>
56
LoggerInstancePtr
(
const
StringType& instanceName)
57
: m_hadConfiguration(
LogManager
::exists(instanceName))
58
, m_logger(
LogManager
::getLogger(instanceName))
59
{
60
}
61
62
~LoggerInstancePtr
()
63
{
64
reset
();
65
}
66
67
const
LoggerPtr
&
operator->
() const noexcept
68
{
69
return
m_logger;
70
}
71
72
explicit
operator
bool() const noexcept
73
{
74
return
!!m_logger;
75
}
76
77
operator
LoggerPtr
&()
noexcept
78
{
79
return
m_logger;
80
}
81
82
operator
const
LoggerPtr
&()
const
noexcept
83
{
84
return
m_logger;
85
}
86
87
Logger
*
get
() noexcept
88
{
89
return
m_logger.get();
90
}
91
92
const
Logger
*
get
() const noexcept
93
{
94
return
m_logger.get();
95
}
96
98
void
reset
()
99
{
100
if
(m_logger && !m_hadConfiguration)
101
{
102
auto
name = m_logger->getName();
103
m_logger.reset();
// Decrease reference count
104
LogManager::removeLogger
(name);
105
}
106
else
107
{
108
m_hadConfiguration =
false
;
109
m_logger.reset();
110
}
111
}
112
114
template
<
class
StringType>
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
}
// namespace LOG4CXX_NS
124
125
#endif
// LOG4CXX_LOGGER_INSTANCE_HDR_
log4cxx::LogManager
Use the LogManager class to retreive Logger instances or to operate on the current LoggerRepository.
Definition
logmanager.h:45
log4cxx::LogManager::removeLogger
static bool removeLogger(const LogString &name, bool ifNotUsed=true)
Remove the name Logger from the LoggerRepository.
log4cxx::LogManager::getLogger
static LoggerPtr getLogger(const std::string &name)
Retrieve the name Logger instance from the LoggerRepository using the default factory to create it if...
log4cxx::LogManager::exists
static LoggerPtr exists(const std::string &name)
A pointer to the Logger name instance if it exists in the LoggerRepository.
log4cxx::LoggerInstancePtr::LoggerInstancePtr
LoggerInstancePtr(const StringType &instanceName)
A separately configurable logger named instanceName.
Definition
loggerinstance.h:56
log4cxx::LoggerInstancePtr::get
Logger * get() noexcept
Definition
loggerinstance.h:87
log4cxx::LoggerInstancePtr::get
const Logger * get() const noexcept
Definition
loggerinstance.h:92
log4cxx::LoggerInstancePtr::reset
void reset(const StringType &instanceName)
Change this to a logger named instanceName.
Definition
loggerinstance.h:115
log4cxx::LoggerInstancePtr::LoggerInstancePtr
LoggerInstancePtr()
A null LoggerPtr.
Definition
loggerinstance.h:52
log4cxx::LoggerInstancePtr::operator->
const LoggerPtr & operator->() const noexcept
Definition
loggerinstance.h:67
log4cxx::LoggerInstancePtr::~LoggerInstancePtr
~LoggerInstancePtr()
Conditionally remove the logger from the the spi::LoggerRepository.
Definition
loggerinstance.h:62
log4cxx::LoggerInstancePtr::reset
void reset()
Conditionally remove the Logger from the spi::LoggerRepository.
Definition
loggerinstance.h:98
log4cxx::Logger
This is the central class in the log4cxx package.
Definition
log4cxx/logger.h:52
logger.h
logmanager.h
log4cxx::LoggerPtr
std::shared_ptr< Logger > LoggerPtr
Definition
defaultloggerfactory.h:27
src
main
include
log4cxx
loggerinstance.h
Generated by
1.17.0 on
SITE_PUBLISHED_DATE
Copyright © 2017-2026
Apache Software Foundation
. Apache, Chainsaw, log4cxx, Log4j, Log4net, log4php and the Apache logo are
trademarks or registered trademarks
of The Apache Software Foundation.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Privacy Policy
.