Belle II Software  release-08-01-10
CprErrorMessage.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
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 #include <rawdata/switch_basf2_standalone.h>
14 
15 using namespace std;
16 using namespace Belle2;
17 
18 //REG_MODULE(CprErrorMessage)
19 // CprErrorMessage::CprErrorMessage( const char* entry_name )
20 // {
21 // // openlog( entry_name, LOG_PERROR, LOG_LOCAL0 );
22 // }
23 
24 CprErrorMessage::CprErrorMessage()
25 {
26  openlog("", LOG_PERROR, LOG_LOCAL0);
27 }
28 
29 CprErrorMessage::~CprErrorMessage()
30 {
31  closelog();
32 }
33 
34 
35 void CprErrorMessage::PrintError(const int shmflag, RunInfoBuffer* nsm_status, string err_str)
36 {
37  if (shmflag > 0) {
38  nsm_status->reportError(RunInfoBuffer::CPRFIFO_FULL);//need to implement error flag
39  }
40  PrintError(err_str.c_str());
41 }
42 
43 void CprErrorMessage::PrintError(const int shmflag, RunInfoBuffer* nsm_status, char* err_message,
44  const char* file, const char* func_name, const int line)
45 {
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 }
Abstract base class for different kinds of events.