Belle II Software  release-05-02-19
CprErrorMessage.cc
1 //+
2 // File : ErrorLog.h
3 // Description : Module to handle raw data from COPPER.
4 //
5 // Author : Satoru Yamada, IPNS, KEK
6 // Date : 2 - Aug - 2013
7 //-
8 //#include <framework/logging/Logger.h>
9 #include <daq/rawdata/CprErrorMessage.h>
10 // #include <time.h>
11 #include <syslog.h>
12 // #include <framework/core/Module.h>
13 
14 using namespace std;
15 using namespace Belle2;
16 
17 //REG_MODULE(CprErrorMessage)
18 // CprErrorMessage::CprErrorMessage( const char* entry_name )
19 // {
20 // // openlog( entry_name, LOG_PERROR, LOG_LOCAL0 );
21 // }
22 
23 CprErrorMessage::CprErrorMessage()
24 {
25  openlog("", LOG_PERROR , LOG_LOCAL0);
26 }
27 
28 CprErrorMessage::~CprErrorMessage()
29 {
30  closelog();
31 }
32 
33 
34 void CprErrorMessage::PrintError(const int shmflag, RunInfoBuffer* nsm_status, string err_str)
35 {
36  if (shmflag > 0) {
37  nsm_status->reportError(RunInfoBuffer::CPRFIFO_FULL);//need to implement error flag
38  }
39  PrintError(err_str.c_str());
40 }
41 
42 void CprErrorMessage::PrintError(const int shmflag, RunInfoBuffer* nsm_status, char* err_message,
43  const char* file, const char* func_name, const int line)
44 {
45  string err_str = err_message;
46  if (shmflag > 0) {
47  nsm_status->reportError(RunInfoBuffer::CPRFIFO_FULL);//need to implement error flag
48  }
49  PrintError(err_message, file, func_name, line);
50 }
51 
52 
53 void CprErrorMessage::PrintError(char* err_message, const char* file, const char* func_name, const int line)
54 {
55  char err_buf[500];
56  sprintf(err_buf, "%s : %s %s %d", err_message, file, func_name, line);
57  // fprintf( stderr, "[FATAL] %s", err_message);
58  printf("%s", err_buf); fflush(stdout);
59  // B2FATAL(err_buf);
60  // printf("AL] %s\n", err_buf);
61  exit(1);
62 
63 // time_t current;
64 // time(&current);
65 // printf("\033[31m");
66 // perror("[ERROR] 0: ");
67 // printf("[ERROR] 1: %s", ctime(&current));
68 // printf("[ERROR] 2: %s\n", err_message);
69 // printf("[ERROR] 3: [file] %s [Line] %d\n", file, line);
70 // printf("[ERROR] 4: [function] %s\n", func_name);
71 // printf("\033[0m");
72 // fflush(stdout);
73 // errmsg(LOG_LOCAL0|LOG_ERR,
74 // "CRITICAL : %s : init_shm() failed to get shmhead ( %p )\n",
75 // __PRETTY_FUNCTION__, shmhead );
76 
77  return;
78 }
79 
80 
81 
82 void CprErrorMessage::PrintError(const char* err_message)
83 {
84  printf("[DEBUG] %s", err_message);
85  fflush(stdout);
86  // B2FATAL(err_message);
87  printf("[FATAL] %s\n", err_message); exit(1);
88 
89 // printf("\033[31m");
90 // printf("\033[47m");
91 // // B2FATAL(err_message);
92 // perror("[ERROR] 0: ");
93 // printf("[ERROR] 1: %s", ctime(&current));
94 // printf("[ERROR] 2: %s\n", err_message);
95 // printf("\033[0m");
96 // printf("\033[40m");
97 // fflush(stdout);
98  return;
99 }
Belle2::RunInfoBuffer
Definition: RunInfoBuffer.h:15
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19