HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hmessagemgr.cc
Go to the documentation of this file.
1 //*-- Author : Joern Wuestenfeld
2 //*-- Modified : 15/04/2002 by Joern Wuestenfeld
3 //*-- Modified : 04/04/2002 by Joern Wuestenfeld
4 //*-- Modified : 28/03/2002 by Joern Wuestenfeld
5 //*-- Modified : 27/02/2003 by Joern Wuestenfeld
6 //*-- Modified : 07/05/2003 by Joern Wuestenfeld
7 
8 //_HADES_CLASS_DESCRIPTION
9 /////////////////////////////////////////
10 //
11 // HMessageMgr
12 //
13 // This class manages three different outputs for all kind of messages.
14 // Besides the standart output, which is the default, one can also
15 // write the messages to a file, or via a socket to a remote logging process.
16 //
17 // The usage of this class should be done via the four macros that are defined
18 // in the hmessagemgr.h file.
19 // DEBUG_msg(level, det, text)
20 // ERROR_msg(det, text)
21 // WARNING_msg(level, det, text)
22 // INFO_msg(level, det, text)
23 //
24 // The meaning of the parameters is:
25 // level - level of this message, never set it to zero because this means
26 // no message at all will be printed
27 // det - detector which sends this message, can be one of:
28 // DET_RICH DET_START DET_MDC DET_TOF DET_TOFINO DET_SHOWER
29 // DET_TRIGGER
30 // text - text to print
31 //
32 /////////////////////////////////////////////////////
33 using namespace std;
34 #include "TSystem.h"
35 #include "hmessagemgr.h"
36 #include <iostream>
37 #include <iomanip>
38 #include <cstdlib>
39 
40 
41 HMessageMgr::HMessageMgr(const Char_t *name, const Char_t *title)
42  : TNamed(name,title)
43 {
44  /// This is the default constructor inherited from TNamed.
45  //
46  // Sets default logging to stdout and stderr.
47  // The default levels are: no debugging, but all of error, warning and info.
48  // param name Name of the object
49  // param title Title of the object
50 
51 
52 
53 
54  msgFile = NULL;
55  errorFile = NULL;
56  msgSocket = NULL;
57  errorSocket = NULL;
58  file = NULL;
59 
60  debugLevel = 0;
64  line = 0;
65  screen = kFALSE;
66  file = new char[2000];
67 }
68 
70 {
71  // Resets the message logging to ist default.
72  // Closses all loggfiles or open sockets, and loggs further messages to
73  // stdout and stderr.
74  // Also the loglevels are set to the same values as in the constructor.
75  setDefault();
76  delete [] file;
77  file = NULL;
78 }
79 
81 {
82  // Closses all loggfiles or open sockets, and loggs further messages to
83  // stdout and stderr.
84  // Also the loglevels are set to the same values as in the constructor.
85  if(msgFile)
86  {
87  delete msgFile;
88  }
89  if(errorFile)
90  {
91  delete errorFile;
92  }
93  if(msgSocket)
94  {
95  msgSocket->Close();
96  delete msgSocket;
97  msgSocket = NULL;
98  }
99  if(errorSocket)
100  {
101  errorSocket->Close();
102  delete errorSocket;
103  errorSocket = NULL;
104  }
105 
106  debugLevel = 0;
110  screen = kFALSE;
111 
112  return kTRUE;
113 }
114 
115 Bool_t HMessageMgr::setFile(const Char_t *dir)
116 {
117  // Sets the logfile.
118  // Input is the directory to where to log to.
119  // The filename is derived from the name of this object, that is given
120  // when creating it.
121  // Two files are created. One with extension .msg for all messages of
122  // type info, warning and debug.
123  // The other one with extension .err fo the error messages.
124  // param dir Directory where to store the logfiles.
125  // retval setFile Returns kTRUE if file could be opened, otherwise kFALSE.
126 
127  Char_t *fname;
128 
129  fname = (Char_t *)calloc(1,2048);
130  if(msgFile)
131  {
132  delete msgFile;
133  msgFile = NULL;
134  }
135  if(errorFile)
136  {
137  delete errorFile;
138  errorFile = NULL;
139  }
140  if(!msgFile)
141  {
142  if((UInt_t)strlen(dir) > (UInt_t)(2048 - fName.Length() + 5))
143  {
144  free(fname);
145  return kFALSE;
146  }
147  else
148  {
149  sprintf(fname,"%s%s%s",dir,fName.Data(),".msg");
150  }
151  msgFile = new ofstream(fname,ios::out);
152  if(!msgFile)
153  {
154  free(fname);
155  return kFALSE;
156  }
157  }
158  else
159  {
160  free(fname);
161  return kFALSE;
162  }
163  if(!errorFile)
164  {
165  if((UInt_t )strlen(dir) > (UInt_t)(2048 - fName.Length() + 5))
166  {
167  free(fname);
168  return kFALSE;
169  }
170  else
171  {
172  sprintf(fname,"%s%s%s",dir,fName.Data(),".err");
173  }
174  errorFile = new ofstream(fname,ios::out);
175  if(!errorFile)
176  {
177  free(fname);
178  if(msgFile)
179  {
180  msgFile->close();
181  msgFile = NULL;
182  }
183  return kFALSE;
184  }
185  }
186  else
187  {
188  free(fname);
189  return kFALSE;
190  }
191 
192  return kTRUE;
193 }
194 
195 Bool_t HMessageMgr::setPort(const Char_t *host, Int_t port)
196 {
197  // Opens two socket connections to a logging server on the specified host.
198  // The passed port is used for the message logging. Errors are send to
199  // the portaddress port + 10.
200  // eventually opened logfiles are closed, if the connection could be opened.
201  // Otherwise the current logging stays active.
202  // param host Name of the host to send the logmessages to.
203  // param port Port to use for communication with remote process.
204  // retval setPort Returns kTRUE if remote process could be contacted, otherwise
205  // kFALSE is returned.
206 
207  msgSocket = new TSocket(host,port);
208  errorSocket = new TSocket(host,port+10);
209  thisHost = new TString(gSystem->HostName());
210  if(msgSocket->IsValid() && errorSocket->IsValid())
211  {
212  if(msgFile)
213  {
214  msgFile->close();
215  msgFile = NULL;
216  }
217  if(errorFile)
218  {
219  errorFile->close();
220  errorFile = NULL;
221  }
222  msgSocket->Send(thisHost->Data());
223  errorSocket->Send(thisHost->Data());
224  return kTRUE;
225  }
226  else
227  {
228  delete msgSocket;
229  delete errorSocket;
230  msgSocket = NULL;
231  errorSocket = NULL;
232  return kFALSE;
233  }
234 }
235 
237 {
238  // Switches of the logging completly by setting the output to /dev/null.
239  // Could probably done also by redirecting stdout and stderr to /dev/null.
240  // Currently opened files or sockets are closed.
241  // retval switchOff Returns kTRUE on succsess, kFALSE otherwise.
242 
243  Char_t *fname;
244 
245  fname = (Char_t *)calloc(1,2048);
246  setDefault();
247  if(msgFile)
248  {
249  delete msgFile;
250  msgFile = NULL;
251  }
252  if(errorFile)
253  {
254  delete errorFile;
255  errorFile = NULL;
256  }
257  if(!msgFile)
258  {
259  sprintf(fname,"%s","/dev/null");
260  }
261  msgFile = new ofstream(fname,ios::out);
262  if(!msgFile)
263  {
264  free(fname);
265  return kFALSE;
266  }
267  else
268  {
269  free(fname);
270  return kFALSE;
271  }
272  if(!errorFile)
273  {
274  sprintf(fname,"%s","/dev/null");
275  }
276  errorFile = new ofstream(fname,ios::out);
277  if(!errorFile)
278  {
279  free(fname);
280  return kFALSE;
281  }
282  else
283  {
284  free(fname);
285  return kFALSE;
286  }
287 
288  return kTRUE;
289 }
290 
291 void HMessageMgr::setDebugLevel(Char_t level)
292 {
293  // Sets the level of debug messages to level.
294  // param level Level of debugging, max 10 min 0.
295 
296  if(level > 10)
297  debugLevel = 10;
298  else
299  if(level <= 0)
300  debugLevel = 1;
301  else
302  debugLevel = level;
303 }
304 
305 void HMessageMgr::setInfoLevel(Char_t level)
306 {
307  // Sets the level of info messages to level.
308  // param level Level of information, max 10 min 0.
309 
310  if(level > 1)
311  infoLevel = 10;
312  else
313  if(level <= 0)
314  infoLevel = 1;
315  else
316  infoLevel = level;
317 }
318 
320 {
321  // Sets the level of warning messages to level.
322  // param level Level of warning, max 10 min 0.
323  if(level > 10)
324  warningLevel = 10;
325  else
326  if(level <= 0)
327  warningLevel = 1;
328  else
329  warningLevel = level;
330 }
331 
332 /// Selects for which detector messages should be displayed.
333 /**
334  \param det An or'd pattern of the DET_* constants.
335  */
337 {
338  // Selects for which detector messages should be displayed.
339  // param det An or'd pattern of the DET_* constants.
340  detectorMsg = det;
341 }
342 
343 void HMessageMgr::messageSeperator(const Char_t *seperator, Int_t num)
344 {
345  // This function prints a line with character seperator.
346  // The seperator character is repeated num times on this line.
347  // param seperator character to be used as seperator
348  // param num How often the character is to be repeated on the same line.
349  Int_t i;
350 
351  msg1 = (Char_t *)calloc(1,num+2);
352  for(i=0;i<num;i++)
353  {
354  strcat(msg1,seperator);
355  }
356  write(msg1);
357  free(msg1);
358 }
359 
360 void HMessageMgr::hydraErrorHandler(Int_t level, Bool_t abort, const Char_t *location, const Char_t *msg)
361 {
362  // Message handler for ROOT. Can be installed via gSystem->SetErrorHandler()
363  // Used by all ROOT classes to do message logging.
364  // Gives a common message layout.
365  // param level Level of logging
366  // param abort Wether to abort the execution after the printing of the message
367  // param location Location of the message
368  // param msg Text to be printed.
369  if (level < gErrorIgnoreLevel)
370  return;
371 
372  if((level >= kError) | (level >= kSysError) | (level >= kFatal))
373  {
374  gHades->getMsg()->error(10,DET_ALL,location,msg);
375  }
376  else
377  if(level >= kWarning)
378  {
379  gHades->getMsg()->warning(10,DET_ALL,location,msg);
380  }
381  else
382  if(level >= kInfo)
383  {
384  gHades->getMsg()->info(10,DET_ALL,location,msg);
385  }
386 }
387 
388 /// This function should never be called directly, use the DEBUG macro instead.
389 /**
390  This function writes a debug message to the output.
391  It looks like this example:<br>
392  debug <Hades >:No input specified<p>
393  \param level Level of message logging
394  \param det One of the DET_* constants that defines the detector printing this message.
395  \param className Name of the class that prints this message.
396  \param text Text to 'print.
397  */
398 void HMessageMgr::debug(Char_t level, Int_t det, const Char_t *className, const Char_t *text)
399 {
400  // This function should never be called directly, use the DEBUG macro instead.
401  // This function writes a debug message to the output.
402  // It looks like this example:<br>
403  // debug <Hades >:No input specified<p>
404  // param level Level of message logging
405  // param det One of the DET_* constants that defines the detector printing this message.
406  // param className Name of the class that prints this message.
407  // param text Text to 'print.
408  if(level <= 0)
409  level = 1;
410  if((level <= debugLevel) && (detectorMsg & det))
411  {
412  msg1 = (Char_t*)calloc(1,strlen((Char_t *)text)+30);
413  if(msg1)
414  {
415  if(line == 0)
416  sprintf(msg1,"%7s%s%s%s%s","debug","<",className,">: ",text);
417  else
418  sprintf(msg1,"%7s%s%s %s%s%d%s%s","debug","<",className,file,":",line,">:",text);
419  write(msg1);
420  free(msg1);
421  }
422  }
423 }
424 
425 void HMessageMgr::error(Char_t level, Int_t det, const Char_t *className, const Char_t *text)
426 {
427  // This function should never be called directly, use the ERROR macro instead.
428  // This function writes a error message to the output.
429  // It looks like this example:<br>
430  // error <Hades >:No input specified<p>
431  // param level Level of message logging
432  // param det One of the DET_* constants that defines the detector printing this message.
433  // param className Name of the class that prints this message.
434  // param text Text to print.
435  if(level <= 0)
436  level = 1;
437  if(detectorMsg & det)
438  {
439  msg1 = (Char_t*)calloc(1,strlen((Char_t *)text)+30);
440  if(msg1)
441  {
442  sprintf(msg1,"%7s%s%s%s%s","error","<",className,">: ",text);
443  ewrite(msg1);
444  free(msg1);
445  }
446  }
447 }
448 
449 void HMessageMgr::warning(Char_t level, Int_t det, const Char_t *className, const Char_t *text)
450 {
451  // This function should never be called directly, use the WARNING macro instead.
452  // This function writes a warning message to the output.
453  // It looks like this example:<br>
454  // warning<Hades >:No input specified<p>
455  // param level Level of message logging
456  // param det One of the DET_* constants that defines the detector printing this message.
457  // param className Name of the class that prints this message.
458  // param text Text to print.
459  if(level <= 0)
460  level = 1;
461  if((level <= warningLevel) && (detectorMsg & det))
462  {
463  msg1 = (Char_t*)calloc(1,strlen((Char_t *)text)+strlen(className)+15);
464  if(msg1)
465  {
466  sprintf(msg1,"%7s%s%s%s%s","warning","<",className,">: ",text);
467  write(msg1);
468  free(msg1);
469  }
470  }
471 }
472 
473 void HMessageMgr::info(Char_t level, Int_t det, const Char_t *className, const Char_t *text)
474 {
475  // This function should never be called directly, use the INFO macro instead.
476  // This function writes a info message to the output.
477  // It looks like this example:<br>
478  // info< Hades>:No input specified<p>
479  // param level Level of message logging
480  // param det One of the DET_* constants that defines the detector printing this message.
481  // param className Name of the class that prints this message.
482  // param text Text to print.
483  if(level <= 0)
484  level = 1;
485  if((level <= infoLevel) && (detectorMsg & det))
486  {
487  msg1 = (Char_t*)calloc(1,strlen((Char_t *)text)+30);
488  if(msg1)
489  {
490  sprintf(msg1,"%7s%s%s%s%s","info","<",className,">: ",text);
491  write(msg1);
492  free(msg1);
493  }
494  }
495 }
496 
497 void HMessageMgr::debug(Int_t level, Int_t det, const Char_t *className, const Char_t *text, ...)
498 {
499  // This function put out an error message including some variable arguments.
500  // The text parameter takes the standart parameters as in printf().
501  // The output looks like:<br>
502  // debug< Hades>:No input specified<p>
503  // param level Level of message logging
504  // param det One of the DET_* constants that defines the detector printing this message.
505  // param className Name of the class that prints this message.
506  // param text Text to print.
507  // param ... Variable number of arguments, that will be used to fill the text
508  va_list ap;
509 
510  if(level <= 0)
511  level = 1;
512  if((level <= debugLevel) && (detectorMsg & det))
513  {
514  msg1 = (Char_t *)calloc(1,2048);
515  msg2 = (Char_t *)calloc(1,2048);
516  if(line == 0)
517  sprintf(msg1,"%7s%s%s%s","debug","<",className,">:");
518  else
519  sprintf(msg1,"%7s%s%s %s%s%d%s","debug","<",className,file,":",line,">: ");
520  va_start(ap,text);
521  vsprintf(msg2,text,ap);
522  va_end(ap);
523  strcat(msg1,msg2);
524  write(msg1);
525  free(msg1);
526  free(msg2);
527  }
528 }
529 
530 void HMessageMgr::error(Int_t level, Int_t det, const Char_t *className, const Char_t *text, ...)
531 {
532  // This function put out an error message including some variable arguments.
533  // The text parameter takes the standart parameters as in printf().
534  // The output looks like:<br>
535  // error< Hades>:No input specified<p>
536  // param level Level of message logging
537  // param det One of the DET_* constants that defines the detector printing this message.
538  // param className Name of the class that prints this message.
539  // param text Text to print.
540  // param ... Variable number of arguments, that will be used to fill the text
541  va_list ap;
542 
543  if(level <= 0)
544  level = 1;
545  if(detectorMsg & det)
546  {
547  msg1 = (Char_t *)calloc(1,2048);
548  msg2 = (Char_t *)calloc(1,2048);
549  sprintf(msg1,"%7s%s%s%s","error","<",className,">: ");
550  va_start(ap,text);
551  vsprintf(msg2,text,ap);
552  va_end(ap);
553  strcat(msg1,msg2);
554  ewrite(msg1);
555  free(msg1);
556  free(msg2);
557  }
558 }
559 
560 void HMessageMgr::warning(Int_t level, Int_t det, const Char_t *className, const Char_t *text, ...)
561 {
562  // This function put out an warning message including some variable arguments.
563  // The text parameter takes the standart parameters as in printf().
564  // The output looks like:<br>
565  // warning< Hades>:No input specified<p>
566  // param level Level of message logging
567  // param det One of the DET_* constants that defines the detector printing this message.
568  // param className Name of the class that prints this message.
569  // param text Text to print.
570  // param ... Variable number of arguments, that will be used to fill the text
571  va_list ap;
572  UInt_t size1,size2;
573 
574  if(level <= 0)
575  level = 1;
576  if((level <= warningLevel) && (detectorMsg & det))
577  {
578  size2 = strlen(text)+2048;
579  size1 = strlen(className) + size2 + 15;
580  msg2 = (Char_t *)calloc(1,size2);
581  msg1 = (Char_t *)calloc(1,size1);
582  sprintf(msg1,"%7s%s%s%s","warning","<",className,">: ");
583  va_start(ap,text);
584  vsnprintf(msg2,size2,text,ap);
585  va_end(ap);
586  strcat(msg1,msg2);
587  write(msg1);
588  free(msg1);
589  free(msg2);
590  }
591 }
592 
593 void HMessageMgr::info(Int_t level, Int_t det, const Char_t *className, const Char_t *text, ...)
594 {
595  // This function put out an info message including some variable arguments.
596  // The text parameter takes the standart parameters as in printf().
597  // The output looks like:<br>
598  // info< Hades>:No input specified<p>
599  // param level Level of message logging
600  // param det One of the DET_* constants that defines the detector printing this message.
601  // param className Name of the class that prints this message.
602  // param text Text to print.
603  // param ... Variable number of arguments, that will be used to fill the text
604 
605  va_list ap;
606 
607  if(level <= 0)
608  level = 1;
609  if((level <= infoLevel) && (detectorMsg & det))
610  {
611 
612 
613  msg1 = (Char_t *)calloc(1,2048);
614  msg2 = (Char_t *)calloc(1,2048);
615  sprintf(msg1,"%7s%s%s%s","info","<",className,">: ");
616  va_start(ap,text);
617  vsprintf(msg2,text,ap);
618  va_end(ap);
619  strcat(msg1,msg2);
620  write(msg1);
621  free(msg1);
622  free(msg2);
623  }
624 }
625 
626 void HMessageMgr::debugB(Char_t level, Int_t det, const Char_t *text, ...)
627 {
628  // This function put out an error message including some variable arguments.
629  // The text parameter takes the standart parameters as in printf().
630  // The output looks like:<br>
631  // debug< Hades>:No input specified<p>
632  // param level Level of message logging
633  // param det One of the DET_* constants that defines the detector printing this message.
634  // param className Name of the class that prints this message.
635  // param file Filename that prints the message.
636  // param line Linenumber from where the message is printed.
637  // param text Text to print.
638  // param ... Variable number of arguments, that will be used to fill the text
639  va_list ap;
640 
641  if(level <= 0)
642  level = 1;
643  if((level <= debugLevel) && (detectorMsg & det))
644  {
645  msg1 = (Char_t *)calloc(1,2048);
646  msg2 = (Char_t *)calloc(1,2048);
647  sprintf(msg1,"%7s%s%s %s%d%s","debug","<",file,":",line,">: ");
648  va_start(ap,text);
649  vsprintf(msg2,text,ap);
650  va_end(ap);
651  strcat(msg1,msg2);
652  write(msg1);
653  free(msg1);
654  free(msg2);
655  }
656 }
657 
658 void HMessageMgr::errorB(Char_t level, Int_t det, const Char_t *text, ...)
659 {
660  // This function put out an error message including some variable arguments.
661  // The text parameter takes the standart parameters as in printf().
662  // The output looks like:<br>
663  // error< Hades>:No input specified<p>
664  // param level Level of message logging
665  // param det One of the DET_* constants that defines the detector printing this message.
666  // param text Text to print.
667  // param ... Variable number of arguments, that will be used to fill the text
668  va_list ap;
669 
670  if(level <= 0)
671  level = 1;
672  if(detectorMsg & det)
673  {
674  msg1 = (Char_t *)calloc(1,2048);
675  msg2 = (Char_t *)calloc(1,2048);
676  sprintf(msg1,"%7s","error :");
677  va_start(ap,text);
678  vsprintf(msg2,text,ap);
679  va_end(ap);
680  strcat(msg1,msg2);
681  ewrite(msg1);
682  free(msg1);
683  free(msg2);
684  }
685 }
686 
687 void HMessageMgr::warningB(Char_t level, Int_t det, const Char_t *text, ...)
688 {
689  // This function put out an warning message including some variable arguments.
690  // The text parameter takes the standart parameters as in printf().
691  // The output looks like:<br>
692  // warning< Hades>:No input specified<p>
693  // param level Level of message logging
694  // param det One of the DET_* constants that defines the detector printing this message.
695  // param text Text to print.
696  // param ... Variable number of arguments, that will be used to fill the text
697  va_list ap;
698  UInt_t size1,size2;
699 
700  if(level <= 0)
701  level = 1;
702  if((level <= warningLevel) && (detectorMsg & det))
703  {
704  size2 = strlen(text)+2048;
705  size1 = size2 + 15;
706  msg2 = (Char_t *)calloc(1,size2);
707  msg1 = (Char_t *)calloc(1,size1);
708  sprintf(msg1,"%7s","warning : ");
709  va_start(ap,text);
710  vsnprintf(msg2,size2,text,ap);
711  va_end(ap);
712  strcat(msg1,msg2);
713  write(msg1);
714  free(msg1);
715  free(msg2);
716  }
717 }
718 
719 void HMessageMgr::infoB(Char_t level, Int_t det, const Char_t *text, ...)
720 {
721  // This function put out an info message including some variable arguments.
722  // The text parameter takes the standart parameters as in printf().
723  // The output looks like:<br>
724  // info< Hades>:No input specified<p>
725  // param level Level of message logging
726  // param det One of the DET_* constants that defines the detector printing this message.
727  // param text Text to print.
728  // param ... Variable number of arguments, that will be used to fill the text
729  va_list ap;
730 
731  if(level <= 0)
732  level = 1;
733  if((level <= infoLevel) && (detectorMsg & det))
734  {
735  msg1 = (Char_t *)calloc(1,2048);
736  msg2 = (Char_t *)calloc(1,2048);
737  sprintf(msg1,"%7s","info : ");
738  va_start(ap,text);
739  vsprintf(msg2,text,ap);
740  va_end(ap);
741  strcat(msg1,msg2);
742  write(msg1);
743  free(msg1);
744  free(msg2);
745  }
746 }
747 
748 void HMessageMgr::debug(Int_t level, Int_t det, const Char_t * className, const Char_t *file, Int_t line, const Char_t *text, ...)
749 {
750  // This function put out an error message including some variable arguments.
751  // The text parameter takes the standart parameters as in printf().
752  // The output looks like:<br>
753  // debug< Hades>:No input specified<p>
754  // param level Level of message logging
755  // param det One of the DET_* constants that defines the detector printing this message.
756  // param file Filename that prints the message.
757  // param line Linenumber from where the message is printed.
758  // param text Text to print.
759  // param ... Variable number of arguments, that will be used to fill the text
760  va_list ap;
761 
762  if(level <= 0)
763  level = 1;
764  if((level <= debugLevel) && (detectorMsg & det))
765  {
766  msg1 = (Char_t *)calloc(1,2048);
767  msg2 = (Char_t *)calloc(1,2048);
768  sprintf(msg1,"%7s%s%s %s%s%d%s","debug","<",className,file,":",line,">: ");
769  va_start(ap,text);
770  vsprintf(msg2,text,ap);
771  va_end(ap);
772  strcat(msg1,msg2);
773  write(msg1);
774  free(msg1);
775  free(msg2);
776  }
777 }
778 
779 
780 void HMessageMgr::write(const Char_t *text)
781 {
782  // Internal function used to write to the correct output.
783  // Used for info, warning and debug messages.
784  // Adds the name of the host the code is running on, if output is send via
785  // socket to a remote logging process.
786  // If screen is set to kTRUE the output is writen to stdout in addition to
787  // the logfile.
788  // param text Text to be writen to specified target.
789  Char_t *msg;
790 
791  if(msgFile)
792  {
793  msgFile->write(text,strlen(text));
794  if(screen)
795  cout << text << endl;
796  }
797  else
798  {
799  if(msgSocket)
800  {
801  msg =(Char_t *)calloc(1,strlen(text) + 20);
802  sprintf(msg,"<%10s>%s",thisHost->Data(),text);
803  msgSocket->Send(msg);
804  free(msg);
805  }
806  else
807  {
808  cout << text << endl;
809  }
810  }
811 }
812 
813 void HMessageMgr::ewrite(const Char_t *text)
814 {
815  // Internal function used to write to the correct output.
816  // Used for error messages.
817  // Adds the name of the host the code is running on, if output is send via
818  // socket to a remote logging process.
819  // If screen is set to kTRUE the output is writen to stdout in addition to
820  // the logfile.
821  // param text Text to be writen to specified target.
822  Char_t *msg;
823 
824  if(errorFile)
825  {
826  errorFile->write(text,strlen(text));
827  if(screen)
828  cout << text << endl;
829  }
830  else
831  {
832  if(errorSocket)
833  {
834  msg =(Char_t *)calloc(1,strlen(text) + 20);
835  sprintf(msg,"<%10s>%s",thisHost->Data(),text);
836  errorSocket->Send(msg);
837  free(msg);
838  }
839  else
840  {
841  cerr << text << endl;
842  }
843  }
844 }
845 
846 void HMessageMgr::setF(const Char_t *name)
847 {
848  // Sets the filename for the debug messages.
849  // The filenames are printed when the debug level is set.
850  // param name Name of the file that wants to print a message soon.
851  if(name && (strlen(name) != 0))
852  strncpy(file, name,1999);
853  else strcpy(file, "");
854 }
855 
856 void HMessageMgr::setL(Int_t num)
857 {
858  // Sets the linenumber for the debug message.
859  // The linenumber is printed when the debug level is set.
860  // param num Linenumber of message.
861  line = num;
862 }
863 
void warning(Char_t level, Int_t det, const Char_t *className, const Char_t *text)
Definition: hmessagemgr.cc:449
void errorB(Char_t level, Int_t det, const Char_t *text,...)
Definition: hmessagemgr.cc:658
Bool_t setPort(const Char_t *host, Int_t port)
Definition: hmessagemgr.cc:195
~HMessageMgr(void)
Definition: hmessagemgr.cc:69
TString * thisHost
Name of this host.
Definition: hmessagemgr.h:166
void messageSeperator(const Char_t *seperator, Int_t num)
Definition: hmessagemgr.cc:343
TSocket * errorSocket
Socket to send error messages to.
Definition: hmessagemgr.h:165
Message manager class to send messages to different outputs.
Definition: hmessagemgr.h:90
Char_t debugLevel
Level up to which the messages wil be printed.
Definition: hmessagemgr.h:157
ClassImp(HDbColumn) HDbColumn
Definition: hdbcolumn.cc:18
#define LEVELMAX
Definition: hmessagemgr.h:14
HMessageMgr(const Char_t *name, const Char_t *title)
Definition: hmessagemgr.cc:41
void info(Char_t level, Int_t det, const Char_t *className, const Char_t *text)
Definition: hmessagemgr.cc:473
Int_t line
line in file where message comes from
Definition: hmessagemgr.h:172
void infoB(Char_t level, Int_t det, const Char_t *text,...)
Definition: hmessagemgr.cc:719
void debug(Char_t level, Int_t det, const Char_t *className, const Char_t *text)
This function should never be called directly, use the DEBUG macro instead.
Definition: hmessagemgr.cc:398
Char_t * msg2
internal message variable
Definition: hmessagemgr.h:170
Bool_t switchOff(void)
Definition: hmessagemgr.cc:236
void enableDetectorMsg(Int_t det)
Selects for which detector messages should be displayed.
Definition: hmessagemgr.cc:336
Int_t detectorMsg
Bitmask fo which detector to print messages.
Definition: hmessagemgr.h:168
TSocket * msgSocket
Socket to send messages to (debug,warning,info)
Definition: hmessagemgr.h:164
Char_t * msg1
internal message variable
Definition: hmessagemgr.h:169
Hades * gHades
Definition: hades.cc:1213
ofstream * errorFile
File to write error messages to.
Definition: hmessagemgr.h:162
void setInfoLevel(Char_t level)
Definition: hmessagemgr.cc:305
void setWarningLevel(Char_t level)
Definition: hmessagemgr.cc:319
void error(Char_t level, Int_t det, const Char_t *className, const Char_t *text)
Definition: hmessagemgr.cc:425
Char_t warningLevel
Level up to which the messages wil be printed.
Definition: hmessagemgr.h:158
void debugB(Char_t level, Int_t det, const Char_t *text,...)
Definition: hmessagemgr.cc:626
void ewrite(const Char_t *text)
Definition: hmessagemgr.cc:813
void setL(Int_t num)
Definition: hmessagemgr.cc:856
Char_t fname[]
Definition: drawAccCuts.C:3
void setF(const Char_t *name)
Definition: hmessagemgr.cc:846
void setDebugLevel(Char_t level)
Definition: hmessagemgr.cc:291
Bool_t screen
write to stdout in addition to file or socket
Definition: hmessagemgr.h:173
void write(const Char_t *text)
Definition: hmessagemgr.cc:780
Char_t infoLevel
Level up to which the messages wil be printed.
Definition: hmessagemgr.h:159
ofstream * msgFile
File to write messages to (debug,warning,info)
Definition: hmessagemgr.h:161
Bool_t setDefault(void)
Definition: hmessagemgr.cc:80
Char_t * file
pointer to store name of file where message comes from
Definition: hmessagemgr.h:171
Bool_t setFile(const Char_t *dir)
Definition: hmessagemgr.cc:115
void warningB(Char_t level, Int_t det, const Char_t *text,...)
Definition: hmessagemgr.cc:687
static void hydraErrorHandler(Int_t level, Bool_t abort, const Char_t *location, const Char_t *msg)
Definition: hmessagemgr.cc:360
HMessageMgr * getMsg(void)
Definition: hades.h:113