Belle II Software  release-06-01-15
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  string err_str = err_message;
47  if (shmflag > 0) {
48  nsm_status->reportError(RunInfoBuffer::CPRFIFO_FULL);//need to implement error flag
49  }
50  PrintError(err_message, file, func_name, line);
51 }
52 
53 
54 void CprErrorMessage::PrintError(char* err_message, const char* file, const char* func_name, const int line)
55 {
56  char err_buf[500];
57  sprintf(err_buf, "%s : %s %s %d", err_message, file, func_name, line);
58  // fprintf( stderr, "[FATAL] %s", err_message);
59  printf("%s", err_buf); fflush(stdout);
60  // B2FATAL(err_buf);
61  // printf("AL] %s\n", err_buf);
62  exit(1);
63 
64 // time_t current;
65 // time(&current);
66 // printf("\033[31m");
67 // perror("[ERROR] 0: ");
68 // printf("[ERROR] 1: %s", ctime(&current));
69 // printf("[ERROR] 2: %s\n", err_message);
70 // printf("[ERROR] 3: [file] %s [Line] %d\n", file, line);
71 // printf("[ERROR] 4: [function] %s\n", func_name);
72 // printf("\033[0m");
73 // fflush(stdout);
74 // errmsg(LOG_LOCAL0|LOG_ERR,
75 // "CRITICAL : %s : init_shm() failed to get shmhead ( %p )\n",
76 // __PRETTY_FUNCTION__, shmhead );
77 
78  return;
79 }
80 
81 
82 
83 void CprErrorMessage::PrintError(const char* err_message)
84 {
85  printf("[DEBUG] %s", err_message);
86  fflush(stdout);
87  // B2FATAL(err_message);
88  printf("[FATAL] %s\n", err_message); exit(1);
89 
90 // printf("\033[31m");
91 // printf("\033[47m");
92 // // B2FATAL(err_message);
93 // perror("[ERROR] 0: ");
94 // printf("[ERROR] 1: %s", ctime(&current));
95 // printf("[ERROR] 2: %s\n", err_message);
96 // printf("\033[0m");
97 // printf("\033[40m");
98 // fflush(stdout);
99  return;
100 }
Abstract base class for different kinds of events.