source: pacpusframework/trunk/src/PacpusLib/Log.cpp@ 36

Last change on this file since 36 was 31, checked in by sgosseli, 12 years ago

Huge commit: use the new includes style in all the files, add the license header in all the headers, and in some cpp.

File size: 1.9 KB
Line 
1/**
2 *
3 * Distributed under the UTC Heudiascy Pacpus License, Version 1.0.
4 * Copyright (c) UTC Heudiasyc 2010 - 2013. All rights reserved.
5 *
6 * See the LICENSE file for more information or a copy at:
7 * http://www.hds.utc.fr/~kurdejma/LICENSE_1_0.txt
8 *
9 */
10
11#include <Pacpus/kernel/Log.h>
12
13#ifdef PACPUS_USE_LOG
14
15#ifdef _MSC_VER
16# pragma warning(push)
17# pragma warning(disable: 4231 4251)
18#endif // _MSC_VER
19
20#include <log4cxx/basicconfigurator.h>
21#include <log4cxx/consoleappender.h>
22#include <log4cxx/patternlayout.h>
23#include <log4cxx/propertyconfigurator.h>
24#include <QString>
25
26#ifdef _MSC_VER
27# pragma warning(pop)
28#endif // _MSC_VER
29
30using namespace log4cxx;
31
32namespace pacpus {
33
34static int niftyCounter;
35
36LogConfigurator::LogConfigurator()
37{
38 using namespace log4cxx;
39
40 if (0 == niftyCounter++) {
41 BasicConfigurator::resetConfiguration();
42
43 LayoutPtr lp(new PatternLayout(LOG4CXX_STR("%-6r [%-5p] %30.30c - %m%n")));
44 AppenderPtr ap(new ConsoleAppender(lp));
45 BasicConfigurator::configure(ap);
46 Logger::getRootLogger()->setLevel(log4cxx::Level::getInfo());
47 }
48}
49
50LogConfigurator::~LogConfigurator()
51{
52 if (0 == --niftyCounter) {
53 // clean up
54 }
55}
56
57void LogConfigurator::configureLoggerWithFile(const char * configFilename)
58{
59 BasicConfigurator::resetConfiguration();
60 PropertyConfigurator::configure(configFilename);
61}
62
63} // namespace pacpus
64
65helpers::CharMessageBuffer & operator<<(helpers::CharMessageBuffer & os, const QString & val)
66{
67 return os << val.toStdString();
68}
69
70helpers::CharMessageBuffer & operator<<(helpers::MessageBuffer & os, const QString & val)
71{
72 return os << val.toStdString();
73}
74
75#else // PACPUS_USE_LOG
76
77namespace pacpus {
78
79LogConfigurator::LogConfigurator()
80{
81}
82
83LogConfigurator::~LogConfigurator()
84{
85}
86
87void LogConfigurator::configureLoggerWithFile(const char * /*configFilename*/)
88{
89}
90
91} // namespace pacpus
92
93#endif // PACPUS_USE_LOG
Note: See TracBrowser for help on using the repository browser.