RSC  0.17.1
LoggerFactory.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of RSC project
4  *
5  * Copyright (C) 2010 by Johannes Wienke <jwienke at techfak dot uni-bielefeld dot de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #pragma once
28 
29 #include <map>
30 #include <vector>
31 
32 #include <boost/noncopyable.hpp>
33 #include <boost/thread/recursive_mutex.hpp>
34 #include <boost/shared_ptr.hpp>
35 
36 #include "Logger.h"
37 #include "LoggerTreeNode.h"
38 #include "LoggerProxy.h"
39 #include "LoggingSystem.h"
40 #include "../patterns/Singleton.h"
41 #include "../misc/langutils.h"
42 #include "rsc/rscexports.h"
43 
44 namespace rsc {
45 
75 namespace logging {
76 
83 class RSC_EXPORT LoggerFactory: public patterns::Singleton<LoggerFactory> {
84 private:
85  LoggerFactory();
86 
87 public:
88 
90 
91  virtual ~LoggerFactory();
92 
104  LoggerPtr getLogger(const std::string& name = "");
105 
116  void reconfigure(const Logger::Level& level);
117 
124  void reconfigureFromFile(const std::string& fileName);
125 
143  void reselectLoggingSystem(const std::string& nameHint = "");
144 
149  static const std::string DEFAULT_LOGGING_SYSTEM;
150 
155 
161  std::string getLoggingSystemName();
162 
166  void clearKnownLoggers();
167 
168 private:
169 
171  class ReselectVisitor;
172 
173  LoggerProxyPtr createLogger(const LoggerTreeNode::NamePath& path,
174  LoggerTreeNodePtr node);
175 
176  boost::shared_ptr<LoggingSystem> loggingSystem;
177 
178  boost::recursive_mutex mutex;
180 
181 };
182 
183 }
184 }
boost::shared_ptr< LoggerProxy > LoggerProxyPtr
Definition: LoggerProxy.h:112
std::vector< std::string > NamePath
A unique representation of a name.
Level
Possible logging levels.
Definition: Logger.h:63
boost::recursive_mutex mutex
This template class implements the singleton pattern.
Definition: Singleton.h:51
boost::shared_ptr< LoggingSystem > loggingSystem
LoggerPtr getLogger()
boost::shared_ptr< LoggerTreeNode > LoggerTreeNodePtr
Factory to create logger instances.
Definition: LoggerFactory.h:83
LoggerTreeNodePtr loggerTree
static const Logger::Level DEFAULT_LEVEL
Default level when the system is used without prior initialization.
static const std::string DEFAULT_LOGGING_SYSTEM
Parameter to pass as name hint to reselectLoggingSystem for selecting the default system...
boost::shared_ptr< Logger > LoggerPtr
Definition: Logger.h:41