[88] | 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, pFCConsole;} |
---|
| 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 | // A compléter. |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | /************* POUR MEMOIRE ********************** |
---|
| 60 | #include <stdio.h> |
---|
| 61 | #include <execinfo.h> |
---|
| 62 | #include <signal.h> |
---|
| 63 | #include <stdlib.h> |
---|
| 64 | |
---|
| 65 | void handler(int sig) { |
---|
| 66 | void *array[10]; |
---|
| 67 | size_t size; |
---|
| 68 | // get void*'s for all entries on the stack |
---|
| 69 | size = backtrace(array, 10); |
---|
| 70 | // print out all the frames to stderr |
---|
| 71 | fprintf(stderr, "Error: signal %d:\n", sig); |
---|
| 72 | backtrace_symbols_fd(array, size, 2); |
---|
| 73 | exit(1); |
---|
| 74 | } |
---|
| 75 | void baz() { |
---|
| 76 | int *foo = (int*)-1; // make a bad pointer |
---|
| 77 | printf("%d\n", *foo); // causes segfault |
---|
| 78 | } |
---|
| 79 | void bar() { baz(); } |
---|
| 80 | void foo() { bar(); } |
---|
| 81 | |
---|
| 82 | int main(int argc, char **argv) { |
---|
| 83 | signal(SIGSEGV, handler); // install our handler |
---|
| 84 | foo(); // this will call foo, bar, and baz. baz segfaults. |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | ***************************************************************/ |
---|
| 88 | |
---|
| 89 | }; // namespace XMLIOSERVER |
---|
| 90 | |
---|
| 91 | #endif // __XMLIO_LOGGER__ |
---|