1 | // %pacpus:license{
|
---|
2 | // This file is part of the PACPUS framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %pacpus:license}
|
---|
5 | /// @author Marek Kurdej <firstname.surname@utc.fr>
|
---|
6 | /// @version $Id: Log.cpp 91 2013-05-19 10:32:48Z gdherbom $
|
---|
7 |
|
---|
8 | #include <Pacpus/kernel/Log.h>
|
---|
9 |
|
---|
10 | #ifdef PACPUS_USE_LOG
|
---|
11 |
|
---|
12 | #ifdef _MSC_VER
|
---|
13 | # pragma warning(push)
|
---|
14 | # pragma warning(disable: 4231 4251)
|
---|
15 | #endif // _MSC_VER
|
---|
16 |
|
---|
17 | #include <log4cxx/basicconfigurator.h>
|
---|
18 | #include <log4cxx/consoleappender.h>
|
---|
19 | #include <log4cxx/patternlayout.h>
|
---|
20 | #include <log4cxx/propertyconfigurator.h>
|
---|
21 | #include <QString>
|
---|
22 |
|
---|
23 | #ifdef _MSC_VER
|
---|
24 | # pragma warning(pop)
|
---|
25 | #endif // _MSC_VER
|
---|
26 |
|
---|
27 | using namespace log4cxx;
|
---|
28 |
|
---|
29 | namespace pacpus {
|
---|
30 |
|
---|
31 | static int niftyCounter;
|
---|
32 |
|
---|
33 | LogConfigurator::LogConfigurator()
|
---|
34 | {
|
---|
35 | using namespace log4cxx;
|
---|
36 |
|
---|
37 | if (0 == niftyCounter++) {
|
---|
38 | BasicConfigurator::resetConfiguration();
|
---|
39 |
|
---|
40 | LayoutPtr lp(new PatternLayout(LOG4CXX_STR("%-6r [%-5p] %30.30c - %m%n")));
|
---|
41 | AppenderPtr ap(new ConsoleAppender(lp));
|
---|
42 | BasicConfigurator::configure(ap);
|
---|
43 | Logger::getRootLogger()->setLevel(log4cxx::Level::getInfo());
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | LogConfigurator::~LogConfigurator()
|
---|
48 | {
|
---|
49 | if (0 == --niftyCounter) {
|
---|
50 | // clean up
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | void LogConfigurator::configureLoggerWithFile(const char * configFilename)
|
---|
55 | {
|
---|
56 | BasicConfigurator::resetConfiguration();
|
---|
57 | PropertyConfigurator::configure(configFilename);
|
---|
58 | }
|
---|
59 |
|
---|
60 | } // namespace pacpus
|
---|
61 |
|
---|
62 | helpers::CharMessageBuffer & operator<<(helpers::CharMessageBuffer & os, const QString & val)
|
---|
63 | {
|
---|
64 | return os << val.toStdString();
|
---|
65 | }
|
---|
66 |
|
---|
67 | helpers::CharMessageBuffer & operator<<(helpers::MessageBuffer & os, const QString & val)
|
---|
68 | {
|
---|
69 | return os << val.toStdString();
|
---|
70 | }
|
---|
71 |
|
---|
72 | #else // PACPUS_USE_LOG
|
---|
73 |
|
---|
74 | namespace pacpus {
|
---|
75 |
|
---|
76 | LogConfigurator::LogConfigurator()
|
---|
77 | {
|
---|
78 | }
|
---|
79 |
|
---|
80 | LogConfigurator::~LogConfigurator()
|
---|
81 | {
|
---|
82 | }
|
---|
83 |
|
---|
84 | void LogConfigurator::configureLoggerWithFile(const char * /*configFilename*/)
|
---|
85 | {
|
---|
86 | }
|
---|
87 |
|
---|
88 | } // namespace pacpus
|
---|
89 |
|
---|
90 | #endif // PACPUS_USE_LOG
|
---|