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 
35 
37 {
38  public:
39  UnknownLoggerTypeException(const char *msg = NULL);
40 };
41 
42 class MultiLogger;
43 
45 {
46  public:
47  static Logger * instance(const char *type, const char *as);
48  static MultiLogger *multilogger_instance(const char *as,
49  Logger::LogLevel default_ll = Logger::LL_DEBUG);
50 
51  /** Get typed instance of logger.
52  * Creates a new instance and converts it to the requested type. If the type
53  * does not match the requested logger an exception is thrown.
54  * @param type logger type
55  * @param as logger argument string
56  * @return typed logger instance
57  * @exception TypeMismatchException thrown, if requested logger does not match
58  * requested type.
59  */
60  template <class L>
61  static L* instance(const char *type, const char *as);
62 
63  private:
64  static Logger::LogLevel string_to_loglevel(const char *log_level);
65 };
66 
67 
68 template <class L>
69 L *
70 LoggerFactory::instance(const char *type, const char *as)
71 {
72  Logger *l = LoggerFactory::instance(type, as);
73  L *tl = dynamic_cast<L *>(l);
74  if ( tl == NULL ) {
75  throw TypeMismatchException("Named type %s is not template type", type);
76  }
77  return tl;
78 }
79 
80 } // end namespace fawkes
81 
82 #endif
LogLevel
Log level.
Definition: logger.h:45
Fawkes library namespace.
static Logger * instance(const char *type, const char *as)
Get logger instance.
Definition: factory.cpp:99
Unknown logger type exception.
Definition: factory.h:36
Logger factory.
Definition: factory.h:44
Log through multiple loggers.
Definition: multi.h:35
Base class for exceptions in Fawkes.
Definition: exception.h:36
debug output, relevant only when tracking down problems
Definition: logger.h:46
UnknownLoggerTypeException(const char *msg=NULL)
Constructor.
Definition: factory.cpp:45
Interface for logging.
Definition: logger.h:34