summaryrefslogtreecommitdiffstats
path: root/src/modules/FileLogger/Module.cpp
blob: cfaf47f7af688efa0f3627057e1ac80cd57edc5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Module.cpp
 *
 * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "../export.h"

#include "Module.h"
#include <Core/ConfigEntry.h>

namespace Mad {
namespace Modules {
namespace FileLogger {

void Module::configure() {
  std::vector<const Core::ConfigEntry*> entries = application->getConfigManager()->getEntries("Log");

  for(std::vector<const Core::ConfigEntry*>::iterator entry = entries.begin(); entry != entries.end(); ++entry) {
    const std::vector<Core::String> &values = (*entry)->getValues();

    if(values.size() < 2 || !values.front().matches("File"))
      continue;

    boost::shared_ptr<FileLogger> logger(new FileLogger(values[1].toLocale()));
    loggers.insert(logger);
    application->getLogManager()->registerLogger(logger);

    bool remote = false;
    for(std::vector<Core::String>::const_iterator value = values.begin()+2; value != values.end(); ++value) {
      if(value->matches("remote"))
        remote = true;
    }

    Core::String level = (*entry)->get("Level");
    if(!level.isEmpty()) {
      try {
        if(remote)
          logger->setRemoteLevel(Core::LogManager::parseLevel(level));
        else
          logger->setLevel(Core::LogManager::parseLevel(level));
      }
      catch(Core::Exception e) {
        application->log(Core::Logger::LOG_WARNING, Core::Format("Unknown log level '%1%'.") % level);
      }
    }
  }
}

}
}
}

extern "C" {

MAD_MODULE_EXPORT Mad::Common::Module* FileLogger_create(Mad::Common::Application *application) {
  return new Mad::Modules::FileLogger::Module(application);
}

}