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 |
|
---|
30 | using namespace log4cxx;
|
---|
31 |
|
---|
32 | namespace pacpus {
|
---|
33 |
|
---|
34 | static int niftyCounter;
|
---|
35 |
|
---|
36 | LogConfigurator::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 |
|
---|
50 | LogConfigurator::~LogConfigurator()
|
---|
51 | {
|
---|
52 | if (0 == --niftyCounter) {
|
---|
53 | // clean up
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | void LogConfigurator::configureLoggerWithFile(const char * configFilename)
|
---|
58 | {
|
---|
59 | BasicConfigurator::resetConfiguration();
|
---|
60 | PropertyConfigurator::configure(configFilename);
|
---|
61 | }
|
---|
62 |
|
---|
63 | } // namespace pacpus
|
---|
64 |
|
---|
65 | helpers::CharMessageBuffer & operator<<(helpers::CharMessageBuffer & os, const QString & val)
|
---|
66 | {
|
---|
67 | return os << val.toStdString();
|
---|
68 | }
|
---|
69 |
|
---|
70 | helpers::CharMessageBuffer & operator<<(helpers::MessageBuffer & os, const QString & val)
|
---|
71 | {
|
---|
72 | return os << val.toStdString();
|
---|
73 | }
|
---|
74 |
|
---|
75 | #else // PACPUS_USE_LOG
|
---|
76 |
|
---|
77 | namespace pacpus {
|
---|
78 |
|
---|
79 | LogConfigurator::LogConfigurator()
|
---|
80 | {
|
---|
81 | }
|
---|
82 |
|
---|
83 | LogConfigurator::~LogConfigurator()
|
---|
84 | {
|
---|
85 | }
|
---|
86 |
|
---|
87 | void LogConfigurator::configureLoggerWithFile(const char * /*configFilename*/)
|
---|
88 | {
|
---|
89 | }
|
---|
90 |
|
---|
91 | } // namespace pacpus
|
---|
92 |
|
---|
93 | #endif // PACPUS_USE_LOG
|
---|