GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TestLOG.C
Go to the documentation of this file.
1 
2 
3 #include "TObject.h"
4 #include "LogMessage.h"
5 
6 class TestLOG_0
7 {
8 protected:
10  LogMessage fLog;
11 public:
12  TestLOG_0() : fLog("TestLOG_0") {;}
13  virtual ~TestLOG_0()
14  {;}
15 
16  void ToLog_0();
17 };
18 
20 {
21  Int_t i = 0;
22 
23  // set the method and open a log ticket
24  fLog.SetProcessMethod("ToLog_0");
25  fLog << debug << "IN BASE " << nline;
26 
27  // ... do something
28  fLog << info << i << " set to 0 " << nline;
29  // ... do something
30 
31  fLog << debug << "OUT BASE " << nline;
32  fLog << dolog;
33 }
34 
35 class TestLOG_1 : public TestLOG_0
36 {
37 public:
38  TestLOG_1() { fLog.GetProcessName() = "TestLOG_1" ; }
39  virtual ~TestLOG_1()
40  {;}
41 
42  virtual void ToLog_1();
43 };
44 
46 {
47  Int_t i = 1;
48 
49  // set the method and open a log ticket
50  fLog.SetProcessMethod("ToLog_1");
51  fLog << debug << "IN LEVEL 1 " << nline;
52 
53  fLog << debug << "Call of BASE " << nline;
55  fLog << debug << "end Call of BASE " << nline;
56 
57  // ... do something
58  fLog << error << i << " cannot be set to 1 " << nline;
59  // ... do something
60 
61  // sent all the collected messages to the LogCollector
62  fLog << debug << "OUT LEVEL 1 " << nline;
63  fLog << dolog;
64 }
65 
66 class TestLOG_2 : public TestLOG_1
67 {
68 public:
69  TestLOG_2() { fLog.GetProcessName() = "TestLOG_2" ; }
70  virtual ~TestLOG_2()
71  {;}
72 
73  virtual void ToLog_2();
74 };
75 
77 {
78  Int_t i = 2;
79 
80  // set the method and open a log ticket
81  fLog.SetProcessMethod("ToLog_2");
82  if ( fLog.IsDebug(2) ) {
83  fLog << "It could be boring the send debug lines line by line " << nline;
84  fLog << "thus, it could be done using IsDebug() " << nline;
85  fLog << "IN LEVEL 2 " << nline;
86  }
88 
89  // ... do something
90  fLog.SetLevel(LogMessage::kWarning,1);
91  fLog << i << " cannot be set to 2 " << nline;
92  fLog.SetLevel(LogMessage::kInfo,0);
93  // ... do something
94 
95  // sent all the collected messages to the LogCollector
96  if ( fLog.IsDebug(2) ) {
97  fLog << "It could be boring the send debug lines line by line " << nline;
98  fLog << "thus, it could be done using IsDebug() " << nline;
99  fLog << "OUT LEVEL 2 " << nline;
100  }
101  fLog << dolog;
102 }
103 
104 class TestLOG_3 : public TestLOG_2
105 {
106 public:
107  TestLOG_3() { fLog.GetProcessName() = "TestLOG_3" ; }
108  virtual ~TestLOG_3()
109  {;}
110 
111  virtual void ToLog_3();
112 };
113 
115 {
116  Int_t i = 3;
117 
118  // set the method and open a log ticket
119  fLog.SetProcessMethod("ToLog_3");
120 
122 
123  // ... do something
124  fLog << i << " cannot be set to 3 " << nline;
125  // ... do something
126 
127  // sent all the collected messages to the LogCollector
128  fLog << dolog;
129 }
130 
131 #include "LogCollector.h"
132 #include "CentralLog.h"
133 
134 void TestLOG()
135 {
136  TestLOG_0 lev0; TestLOG_1 lev1; TestLOG_2 lev2; TestLOG_3 lev3;
137 
138  printf("\n*************** Log cout, not depth *************** \n");
139  LogMessage::SetLogParameters(0,1);
140 /* means :
141  LogMessage::gDebug = 0;
142  LogMessage::gkMaxDepth = 1;
143  LogMessage::gkAutoClear = 7; */
144 
145  // log messages, no depth
146  lev0.ToLog_0();
147  // log messages, one depth's call
148  lev1.ToLog_1();
149  // log messages, two depth' calls
150  lev2.ToLog_2();
151  // log messages, three depth' calls
152  lev3.ToLog_3();
153 
154  printf("\n*************** Log cout, and depth *************** \n");
155  LogMessage::SetLogParameters();
156 /* means :
157  LogMessage::gDebug = 0;
158  LogMessage::gkMaxDepth = 5;
159  LogMessage::gkAutoClear = 7; */
160 
161  // log messages, no depth
162  lev0.ToLog_0();
163  // log messages, one depth's call
164  lev1.ToLog_1();
165  // log messages, two depth' calls
166  lev2.ToLog_2();
167  // log messages, three depth' calls
168  lev3.ToLog_3();
169 
170  // A log collector is created to collector logs in a file
171  // WARNING !! the user should notify if the new collector is owned by teh CentralLog with
172  // OStreamCollector("TEST.log",true)
173  // which is the default behavior. In this case CentralLog deletes the Collector
174  // if set to false, the user should take of deleting the collector
175  OStreamCollector *test_collector = new OStreamCollector("TestLOG.log");
176  CentralLog::theCentralLog()->Add( test_collector ) ;
177  CentralLog::theCentralLog()->ChangeCollector(std::string("TestLOG.log"));
178 
179  printf("\n*************** Log file, and depth *************** \n");
180 
181  // log messages, no depth
182  lev0.ToLog_0();
183  // log messages, one depth's call
184  lev1.ToLog_1();
185  // log messages, two depth' calls
186  lev2.ToLog_2();
187  // log messages, three depth' calls
188  lev3.ToLog_3();
189 
190  printf("\n************** Log all to black hole ************** \n");
191  // messages are now sent to a black hole !
192  CentralLog::theCentralLog()->ChangeCollector(std::string("Null"));
193 
194  // log messages, no depth
195  lev0.ToLog_0();
196  // log messages, one depth's call
197  lev1.ToLog_1();
198  // log messages, two depth' calls
199  lev2.ToLog_2();
200  // log messages, three depth' calls
201  lev3.ToLog_3();
202 
203  printf("\n************** Cout and debug info ************** \n");
204  CentralLog::theCentralLog()->ChangeCollector(std::string("cout"));
205  LogMessage::SetLogParameters(2);
206 /* means :
207  LogMessage::gDebug = 2;
208  LogMessage::gkMaxDepth = 5;
209  LogMessage::gkAutoClear = 7; */
210 
211  // log messages, no depth
212  lev0.ToLog_0();
213  // log messages, one depth's call
214  lev1.ToLog_1();
215  // log messages, two depth' calls
216  lev2.ToLog_2();
217  // log messages, three depth' calls
218  lev3.ToLog_3();
219 }
220 
221 
222 
223 
printf("******************************************************************** \n")
virtual ~TestLOG_0()
Definition: TestLOG.C:13
void TestLOG()
Definition: TestLOG.C:134
LogMessage & error(LogMessage &)
virtual ~TestLOG_1()
Definition: TestLOG.C:39
void ToLog_0()
Definition: TestLOG.C:19
LogMessage & nline(LogMessage &)
virtual void ToLog_2()
Definition: TestLOG.C:76
global header
LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
TestLOG_3()
Definition: TestLOG.C:107
TestLOG_0()
Definition: TestLOG.C:12
LogMessage & dolog(LogMessage &)
TestLOG_2()
Definition: TestLOG.C:69
LogMessage & debug(LogMessage &)
virtual void ToLog_3()
Definition: TestLOG.C:114
TestLOG_1()
Definition: TestLOG.C:38
virtual ~TestLOG_2()
Definition: TestLOG.C:70
virtual void ToLog_1()
Definition: TestLOG.C:45
virtual ~TestLOG_3()
Definition: TestLOG.C:108
LogMessage fLog
send meesages to the log system
Definition: TestLOG.C:10