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