source: XMLIO_V2/dev/dev_rv/xmlio_logger.hpp @ 88

Last change on this file since 88 was 88, checked in by hozdoba, 14 years ago

Version expérimentale, commit pour sauvegarde.

File size: 2.4 KB
Line 
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
13using Poco::Logger;
14using Poco::PatternFormatter;
15using Poco::FormattingChannel;
16using Poco::ConsoleChannel;
17using Poco::FileChannel;
18using Poco::Message;
19
20namespace 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 
65void 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}
75void baz() {
76 int *foo = (int*)-1; // make a bad pointer
77  printf("%d\n", *foo);       // causes segfault
78}
79void bar() { baz(); }
80void foo() { bar(); }
81 
82int 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__ 
Note: See TracBrowser for help on using the repository browser.