~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/main/ConfigBoundLogObserver.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Implementation: ConfigBoundLogObserver
 
3
//
 
4
// Description: 
 
5
//
 
6
//
 
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2007
 
8
//
 
9
// This program is free software; you can redistribute it and/or modify
 
10
// it under the terms of the GNU General Public License as published by
 
11
// the Free Software Foundation; either version 2 of the License, or
 
12
// (at your option) any later version.
 
13
// 
 
14
// This program is distributed in the hope that it will be useful,
 
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
// GNU General Public License for more details.
 
18
// 
 
19
// You should have received a copy of the GNU General Public License
 
20
// along with this program; if not, write to the Free Software
 
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
 
22
//
 
23
#ifdef HAVE_CONFIG_H
 
24
#include "config.h"
 
25
#endif
 
26
 
 
27
#include "ConfigBoundLogObserver.h"
 
28
 
 
29
#include "framework/LoggingInstance.h"
 
30
#include "services/config/ConfigService.h"
 
31
 
 
32
namespace Ember {
 
33
 
 
34
ConfigBoundLogObserver::ConfigBoundLogObserver(std::ostream &out) 
 
35
: Ember::StreamLogObserver(out)
 
36
{
 
37
        Ember::EmberServices::getSingletonPtr()->getConfigService()->EventChangedConfigItem.connect(sigc::mem_fun(*this, &ConfigBoundLogObserver::ConfigService_EventChangedConfigItem));
 
38
 
 
39
}
 
40
 
 
41
 
 
42
 
 
43
ConfigBoundLogObserver::~ConfigBoundLogObserver()
 
44
{
 
45
}
 
46
 
 
47
/**
 
48
* Updates from the config. The relevant section is "general" and the key "logginglevel". It can have the values of verbose|info|warning|failure|critical
 
49
*/
 
50
void ConfigBoundLogObserver::updateFromConfig()
 
51
{
 
52
        if (Ember::EmberServices::getSingletonPtr()->getConfigService()->itemExists("general", "logginglevel")) {
 
53
                std::string loggingLevel = static_cast<std::string>(Ember::EmberServices::getSingletonPtr()->getConfigService()->getValue("general", "logginglevel"));
 
54
                Ember::Log::MessageImportance importance(Ember::Log::INFO);
 
55
                if (loggingLevel == "verbose") {
 
56
                        importance = Ember::Log::VERBOSE;
 
57
                } else if (loggingLevel == "info") {
 
58
                        importance = Ember::Log::INFO;
 
59
                } else if (loggingLevel == "warning") {
 
60
                        importance = Ember::Log::WARNING;
 
61
                } else if (loggingLevel == "failure") {
 
62
                        importance = Ember::Log::FAILURE;
 
63
                } else if (loggingLevel == "critical") {
 
64
                        importance = Ember::Log::CRITICAL;
 
65
                }
 
66
                setFilter(importance);
 
67
        }
 
68
}
 
69
 
 
70
 
 
71
/**
 
72
        *          React on changes to the config.
 
73
        * @param section 
 
74
        * @param key 
 
75
        */
 
76
void ConfigBoundLogObserver::ConfigService_EventChangedConfigItem(const std::string& section, const std::string& key)
 
77
{
 
78
        if (section == "general") {
 
79
                if (key == "logginglevel") {
 
80
                        updateFromConfig();
 
81
                }
 
82
        }
 
83
}
 
84
 
 
85
}