FACT++  1.0
void showlog ( string  fname,
const Time tbeg,
const Time tend,
int16_t  severity,
bool  color,
bool  strip 
)

Definition at line 68 of file showlog.cc.

References buffer, Tools::Form(), Time::IsValid(), kBlink, kBlue, kBold, kDefault, kGreen, kRed, kYellow, and t.

Referenced by main().

69 {
70  // Alternatives
71  // \x1B\[[0-9;]*[mK]
72  // \x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]
73  // \x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]
74  const boost::regex reg("\x1B\[([0-9]{1,3}(;[0-9]{1,3})?[a-zA-Z]");
75 
76  const uint32_t night = atoi(fname.c_str());
77  if (night>20000000 && night<21000000 &&to_string(night)==fname)
78  fname = Tools::Form("/fact/aux/%04d/%02d/%02d/%d.log",
79  night/10000, (night/100)%100, night%100, night);
80 
81  if (!fname.empty())
82  cerr << "Reading " << fname << endl;
83 
84  ifstream fin(fname.empty() ? "/dev/stdin" : fname.c_str());
85  if (!fin)
86  throw runtime_error(strerror(errno));
87 
88  string buffer;
89 
90  WindowLog log;
91 
92  Time tprev;
93 
94  while (getline(fin, buffer, '\n'))
95  {
96  if (color || strip)
97  buffer = boost::regex_replace(buffer, reg, "");
98 
99  if (buffer.size()==0)
100  continue;
101 
102  if (buffer.size()>18)
103  {
104  const string tm = buffer.substr(4, 15);
105 
106  const Time t("1970-01-01 "+tm);
107 
108  if (tbeg.IsValid() && !tend.IsValid() && t<tbeg)
109  continue;
110 
111  if (tend.IsValid() && !tbeg.IsValid() && t>tend)
112  continue;
113 
114  if (tbeg.IsValid() && tend.IsValid())
115  {
116  if (tend>tbeg)
117  {
118  if (t<tbeg)
119  continue;
120  if (t>tend)
121  continue;
122  }
123  else
124  {
125  if (t>tbeg)
126  continue;
127  if (t<tend)
128  continue;
129  }
130  }
131  }
132 
133  if (buffer.size()>1 && !strip)
134  {
135  int16_t lvl = -1;
136  switch (buffer[1])
137  {
138  case ' ': lvl = 7; break; // kDebug
139  case '#': lvl = 6; break; // kComment
140  case '-': lvl = 5; break; // kMessage
141  case '>': lvl = 4; break;
142  case 'I': lvl = 3; break; // kInfo
143  case 'W': lvl = 2; break; // kWarn
144  case 'E': lvl = 1; break; // kError/kAlarm
145  case '!': lvl = 0; break; // kFatal
146  }
147 
148  if (lvl>severity)
149  continue;
150 
151  switch (buffer[1])
152  {
153  case ' ': log << kBlue; break; // kDebug
154  case '#': log << kDefault; break; // kComment
155  case '-': log << kDefault; break; // kMessage
156  case '>': log << kBold; break;
157  case 'I': log << kGreen; break; // kInfo
158  case 'W': log << kYellow; break; // kWarn
159  case 'E': log << kRed; break; // kError/kAlarm
160  case '!': log << kRed << kBlink; break; // kFatal
161  }
162  }
163 
164  (strip?cout:log) << buffer << endl;
165  }
166 }
Set color Green.
Definition: WindowLog.h:18
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
A C++ ostream to an ncurses window supporting attributes and colors.
Definition: WindowLog.h:50
Set color Yellow.
Definition: WindowLog.h:19
Set attribute Blink.
Definition: WindowLog.h:34
Set color Red.
Definition: WindowLog.h:17
Set default colors.
Definition: WindowLog.h:16
Set color Blue.
Definition: WindowLog.h:20
bool IsValid() const
Definition: Time.h:90
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
std::string Form(const char *fmt,...)
Definition: tools.cc:45
TT t
Definition: test_client.c:26
function color(col)
Definition: color.js:31
Set attribute Bold.
Definition: WindowLog.h:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function: