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 
30 #include <cstddef>
31 
32 namespace fawkes {
33 
34 
36 {
37  public:
38  UnknownLoggerTypeException(const char *msg = NULL);
39 };
40 
41 class Logger;
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 
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 
63 
64 template <class L>
65 L *
66 LoggerFactory::instance(const char *type, const char *as)
67 {
68  Logger *l = LoggerFactory::instance(type, as);
69  L *tl = dynamic_cast<L *>(l);
70  if ( tl == NULL ) {
71  throw TypeMismatchException();
72  }
73  return tl;
74 }
75 
76 } // end namespace fawkes
77 
78 #endif
Fawkes library namespace.
static Logger * instance(const char *type, const char *as)
Get logger instance.
Definition: factory.cpp:78
Unknown logger type exception.
Definition: factory.h:35
Logger factory.
Definition: factory.h:44
Log through multiple loggers.
Definition: multi.h:35
Base class for exceptions in Fawkes.
Definition: exception.h:36
UnknownLoggerTypeException(const char *msg=NULL)
Constructor.
Definition: factory.cpp:44
Interface for logging.
Definition: logger.h:34