Apache Log4cxx  Version 1.3.1
levelchange.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_LEVEL_CHANGE_HDR_
19 #define LOG4CXX_LEVEL_CHANGE_HDR_
20 
21 #include <log4cxx/logmanager.h>
22 #include <log4cxx/logger.h>
23 
24 namespace LOG4CXX_NS
25 {
26 
42 {
43  LoggerPtr m_otherCategory;
44  LevelPtr m_savedLevel;
45 public: // ...structors
47  LevelChange(const LoggerPtr& otherCategory, const LevelPtr& level)
48  : m_otherCategory(otherCategory)
49  , m_savedLevel(otherCategory->getLevel())
50  {
51  m_otherCategory->setLevel(level);
52  }
54  LevelChange(const LoggerPtr& otherCategory, const LoggerPtr& thisCategory)
55  : LevelChange(otherCategory, thisCategory->getLevel())
56  {
57  }
59  template <class StringType>
60  LevelChange(const StringType& otherCategory, const LevelPtr& level)
61  : LevelChange(LogManager::getLogger(otherCategory), level)
62  {
63  }
65  template <class StringType>
66  LevelChange(const StringType& otherCategory, const LoggerPtr& thisCategory)
67  : LevelChange(LogManager::getLogger(otherCategory), thisCategory->getLevel())
68  {
69  }
72  {
73  m_otherCategory->setLevel(m_savedLevel);
74  }
75 private: // Prevent copies and assignment
76  LevelChange(const LevelChange&) = delete;
77  LevelChange(LevelChange&&) = delete;
78  LevelChange& operator=(const LevelChange&) = delete;
79  LevelChange& operator=(LevelChange&&) = delete;
80 };
81 
82 } // namespace LOG4CXX_NS
83 
84 #endif // LOG4CXX_LEVEL_CHANGE_HDR_
Changes a verbosity level for the instance variable's lifetime.
Definition: levelchange.h:42
LevelChange(const StringType &otherCategory, const LoggerPtr &thisCategory)
Set the logger named otherCategory to the level of thisCategory.
Definition: levelchange.h:66
~LevelChange()
Restore the verbosity level of the other logger.
Definition: levelchange.h:71
LevelChange(const LoggerPtr &otherCategory, const LoggerPtr &thisCategory)
Set otherCategory to the level of thisCategory.
Definition: levelchange.h:54
LevelChange(const LoggerPtr &otherCategory, const LevelPtr &level)
Set otherCategory to level.
Definition: levelchange.h:47
LevelChange(const StringType &otherCategory, const LevelPtr &level)
Set the logger named otherCategory to level.
Definition: levelchange.h:60
Use the LogManager class to retreive Logger instances or to operate on the current LoggerRepository.
Definition: logmanager.h:45
std::shared_ptr< Level > LevelPtr
Definition: optionconverter.h:27
std::shared_ptr< Logger > LoggerPtr
Definition: defaultloggerfactory.h:26