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
class
UnknownLoggerTypeException :
public
Exception
36
{
37
public
:
38
UnknownLoggerTypeException
(
const
char
*msg = NULL);
39
};
40
41
class
MultiLogger
;
42
43
class
LoggerFactory
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:148
fawkes::MultiLogger
Definition:
multi.h:40
fawkes::LoggerFactory
Definition:
factory.h:49
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:104
fawkes::TypeMismatchException
Definition:
software.h:49
fawkes::Logger
Definition:
logger.h:41
fawkes
fawkes::UnknownLoggerTypeException::UnknownLoggerTypeException
UnknownLoggerTypeException(const char *msg=NULL)
Constructor.
Definition:
factory.cpp:51
fawkes::Logger::LogLevel
LogLevel
Log level.
Definition:
logger.h:51
src
libs
logging
factory.h
Generated by
1.8.17