129{
132
133 string hostname;
139
141
142 try {
143
144 JParser<> zap(
"Auxiliary program to save logger messages from ControlHost server.");
145
146 zap[
'H'] =
make_field(hostname) =
"localhost";
152
153 zap(argc, argv);
154 }
155 catch(const exception &error) {
156 FATAL(error.what() << endl);
157 }
158
159 if (happy_hour.empty()) {
160
161 WARNING(
"No happy hours (option -W); set to midnight." << endl);
162
163 happy_hour.insert(0);
164 }
165
166
168
169 try {
170
172
173 {
175
178 }
179
180 in.Subscribe(buffer);
181 in.SendMeAlways();
182 }
183
184
185 JLoggerFile out(path);
186
187 out.open();
188
189 DEBUG(
"Open file " << out.getFilename() << endl);
190
192 string buffer;
193
195
196 for (int number_of_messages; buffer.size() != stop.size() || string(buffer.data(), stop.size()) != stop; ) {
197
198 const int check = in.CheckHead(prefix, timeout);
199
200 DEBUG(
"Check head " << check << endl);
201
202 if (check < 0) {
203
204 FATAL(
"Error at JControlHost::CheckHead " << check << endl);
205
206 } else if (check == 1) {
207
208 in.GetFullString(buffer);
209
210 DEBUG(
"Message <" << buffer <<
">" << endl);
211
212 if (buffer == stop) {
213
214 break;
215
216 } else if (buffer == save) {
217
218 DEBUG(
"Close file " << out.getFilename() << endl);
219
220 out.close();
221 out.open();
222
223 DEBUG(
"Open file " << out.getFilename() << endl);
224
225 } else {
226
227 ++number_of_messages;
228
229 if ( ! (out << buffer << endl)) {
230 FATAL(
"Error writing to file " << out.getFilename() << endl);
231 }
232 }
233 }
234
235 if (check == 0 || number_of_messages > MINIMUM_NUMBER_OF_MESSAGES) {
236
237 number_of_messages = 0;
238
240
242
244
245 DEBUG(
"Close file " << out.getFilename() << endl);
246
247 out.close();
248 out.open();
249
250 DEBUG(
"Open file " << out.getFilename() << endl);
251 }
252 }
253 }
254
255 out.close();
256 }
258 ERROR(error << endl);
259 }
260}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Exception for ControlHost.
static void Throw(const bool option)
Auxiliary class for time values.
JSubscriptionList & add(const JSubscription &subscription)
Add subscription.
Utility class to parse command line options.
static const std::string MESSAGE_TAG
Message logging tag.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary class for all subscription.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Auxiliary class for date and time.
double getElapsedTime(const JDateAndTime &object) const
Get elapsed time to given date and time.
int getHour() const
hours after midnight [0-23]
void set(const bool utc=false)
Set to current local time.