1 | #ifndef __XMLIO_LOGGER__ |
---|
2 | #define __XMLIO_LOGGER__ |
---|
3 | |
---|
4 | // Entête Poco logging |
---|
5 | #include <Poco/Logger.h> |
---|
6 | #include <Poco/PatternFormatter.h> |
---|
7 | #include <Poco/FormattingChannel.h> |
---|
8 | #include <Poco/ConsoleChannel.h> |
---|
9 | #include <Poco/FileChannel.h> |
---|
10 | #include <Poco/Message.h> |
---|
11 | |
---|
12 | // Classes utilisées issues de Poco |
---|
13 | using Poco::Logger; |
---|
14 | using Poco::PatternFormatter; |
---|
15 | using Poco::FormattingChannel; |
---|
16 | using Poco::ConsoleChannel; |
---|
17 | using Poco::FileChannel; |
---|
18 | using Poco::Message; |
---|
19 | |
---|
20 | namespace XMLIOSERVER |
---|
21 | { |
---|
22 | class ILogger |
---|
23 | { |
---|
24 | public : |
---|
25 | |
---|
26 | ILogger(const string& _fileLogName, bool _withConsole = true) |
---|
27 | { |
---|
28 | // Perte mémoire faible ici (/ still reachable: 84 bytes in 2 blocks /) |
---|
29 | |
---|
30 | // TODO Créer une sortie fichier. |
---|
31 | pf = new PatternFormatter("[%Y-%m-%d %H:%M:%S] %t"); |
---|
32 | cc = new ConsoleChannel(); |
---|
33 | pFCConsole = new FormattingChannel(); |
---|
34 | pFCConsole->setChannel(cc); |
---|
35 | pFCConsole->open(); |
---|
36 | Logger::create("ConsoleLogger", pFCConsole, Message::PRIO_INFORMATION); |
---|
37 | } |
---|
38 | |
---|
39 | static Logger & GetConsoleLogger(void) {return (Logger::get("ConsoleLogger"));} |
---|
40 | |
---|
41 | ~ILogger(void) { delete pf;} |
---|
42 | |
---|
43 | private : |
---|
44 | FormattingChannel * pFCConsole; |
---|
45 | PatternFormatter * pf; |
---|
46 | ConsoleChannel * cc; |
---|
47 | |
---|
48 | }; // class XMLIOLogger |
---|
49 | |
---|
50 | // Initialisation de la classe de Logging |
---|
51 | static ILogger LOGGER("xmlio.log"); |
---|
52 | |
---|
53 | #define ERROR(MSG) (ILogger::GetConsoleLogger().error(MSG)) |
---|
54 | #define WARNING(MSG) (ILogger::GetConsoleLogger().warning(MSG)) |
---|
55 | #define INFO(MSG) (ILogger::GetConsoleLogger().information(MSG)) |
---|
56 | // A compléter. |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | /************* POUR MEMOIRE ********************** |
---|
61 | #include <stdio.h> |
---|
62 | #include <execinfo.h> |
---|
63 | #include <signal.h> |
---|
64 | #include <stdlib.h> |
---|
65 | |
---|
66 | void handler(int sig) { |
---|
67 | void *array[10]; |
---|
68 | size_t size; |
---|
69 | // get void*'s for all entries on the stack |
---|
70 | size = backtrace(array, 10); |
---|
71 | // print out all the frames to stderr |
---|
72 | fprintf(stderr, "Error: signal %d:\n", sig); |
---|
73 | backtrace_symbols_fd(array, size, 2); |
---|
74 | exit(1); |
---|
75 | } |
---|
76 | void baz() { |
---|
77 | int *foo = (int*)-1; // make a bad pointer |
---|
78 | printf("%d\n", *foo); // causes segfault |
---|
79 | } |
---|
80 | void bar() { baz(); } |
---|
81 | void foo() { bar(); } |
---|
82 | |
---|
83 | int main(int argc, char **argv) { |
---|
84 | signal(SIGSEGV, handler); // install our handler |
---|
85 | foo(); // this will call foo, bar, and baz. baz segfaults. |
---|
86 | } |
---|
87 | |
---|
88 | ***************************************************************/ |
---|
89 | |
---|
90 | }; // namespace XMLIOSERVER |
---|
91 | |
---|
92 | #endif // __XMLIO_LOGGER__ |
---|