Fawkes API  Fawkes Development Version
factory.h
1 
2 /***************************************************************************
3  * factory.h - Logger factory
4  *
5  * Created: Mon Jun 04 10:54:35 2007
6  * Copyright 2007 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef _UTILS_LOGGING_FACTORY_H_
25 #define _UTILS_LOGGING_FACTORY_H_
26 
27 #include <core/exception.h>
28 #include <core/exceptions/software.h>
29 #include <logging/logger.h>
30 
31 #include <cstddef>
32 
33 namespace fawkes {
34 
36 {
37 public:
38  UnknownLoggerTypeException(const char *msg = NULL);
39 };
40 
41 class MultiLogger;
42 
44 {
45 public:
46  static Logger * instance(const char *type, const char *as);
47  static MultiLogger *multilogger_instance(const char * as,
48  Logger::LogLevel default_ll = Logger::LL_DEBUG);
49 
50  /** Get typed instance of logger.
51  * Creates a new instance and converts it to the requested type. If the type
52  * does not match the requested logger an exception is thrown.
53  * @param type logger type
54  * @param as logger argument string
55  * @return typed logger instance
56  * @exception TypeMismatchException thrown, if requested logger does not match
57  * requested type.
58  */
59  template <class L>
60  static L *instance(const char *type, const char *as);
61 
62 private:
63  static Logger::LogLevel string_to_loglevel(const char *log_level);
64 };
65 
66 template <class L>
67 L *
68 LoggerFactory::instance(const char *type, const char *as)
69 {
70  Logger *l = LoggerFactory::instance(type, as);
71  L * tl = dynamic_cast<L *>(l);
72  if (tl == NULL) {
73  throw TypeMismatchException("Named type %s is not template type", type);
74  }
75  return tl;
76 }
77 
78 } // end namespace fawkes
79 
80 #endif
fawkes::LoggerFactory::multilogger_instance
static MultiLogger * multilogger_instance(const char *as, Logger::LogLevel default_ll=Logger::LL_DEBUG)
Create MultiLogger instance.
Definition: factory.cpp:142
fawkes::MultiLogger
Log through multiple loggers.
Definition: multi.h:35
fawkes::LoggerFactory
Logger factory.
Definition: factory.h:44
fawkes::Logger::LL_DEBUG
@ LL_DEBUG
debug output, relevant only when tracking down problems
Definition: logger.h:52
fawkes::LoggerFactory::instance
static Logger * instance(const char *type, const char *as)
Get logger instance.
Definition: factory.cpp:98
fawkes::TypeMismatchException
Type mismatch.
Definition: software.h:44
fawkes::Logger
Interface for logging.
Definition: logger.h:42
fawkes
Fawkes library namespace.
fawkes::UnknownLoggerTypeException::UnknownLoggerTypeException
UnknownLoggerTypeException(const char *msg=NULL)
Constructor.
Definition: factory.cpp:45
fawkes::Logger::LogLevel
LogLevel
Log level.
Definition: logger.h:51
fawkes::UnknownLoggerTypeException
Unknown logger type exception.
Definition: factory.h:36
fawkes::Exception
Base class for exceptions in Fawkes.
Definition: exception.h:36