27 const std::string save =
"save";
28 const std::string stop =
"stop";
31 const int MINIMUM_NUMBER_OF_MESSAGES = 100;
32 const double MINIMUM_ELAPSED_TIME_S = 60*60;
42 static const int MAXIMUM_FILE_NUMBER = 100;
49 JLoggerFile(
const std::string& path) :
74 for (
int i = 0; !this->is_open() && i != MAXIMUM_FILE_NUMBER; ++i) {
80 <<
"_" << this->getYear() <<
'-' <<
FILL(2,
'0') << this->getMonth() <<
'-' <<
FILL(2,
'0') << this->getDay();
92 if (!filesystem::is_regular_file(file_name, error)) {
113 std::string file_name;
128int main(
int argc,
const char *argv[])
144 JParser<> zap(
"Auxiliary program to save logger messages from ControlHost server.");
146 zap[
'H'] =
make_field(hostname) =
"localhost";
155 catch(
const exception &error) {
156 FATAL(error.what() << endl);
159 if (happy_hour.empty()) {
161 WARNING(
"No happy hours (option -W); set to midnight." << endl);
163 happy_hour.insert(0);
185 JLoggerFile out(path);
189 DEBUG(
"Open file " << out.getFilename() << endl);
196 for (
int number_of_messages; buffer.size() != stop.size() ||
string(buffer.data(), stop.size()) != stop; ) {
198 const int check = in.
CheckHead(prefix, timeout);
200 DEBUG(
"Check head " << check << endl);
204 FATAL(
"Error at JControlHost::CheckHead " << check << endl);
206 }
else if (check == 1) {
210 DEBUG(
"Message <" << buffer <<
">" << endl);
212 if (buffer == stop) {
216 }
else if (buffer == save) {
218 DEBUG(
"Close file " << out.getFilename() << endl);
223 DEBUG(
"Open file " << out.getFilename() << endl);
227 ++number_of_messages;
229 if ( ! (out << buffer << endl)) {
230 FATAL(
"Error writing to file " << out.getFilename() << endl);
235 if (check == 0 || number_of_messages > MINIMUM_NUMBER_OF_MESSAGES) {
237 number_of_messages = 0;
245 DEBUG(
"Close file " << out.getFilename() << endl);
250 DEBUG(
"Open file " << out.getFilename() << endl);
258 ERROR(error << endl);
General purpose message reporting.
General purpose messaging.
#define DEBUG(A)
Message macros.
Utility class to parse command line options.
#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.
int GetFullString(std::string &buffer)
Receive string.
int CheckHead(JPrefix &prefix, JTimeval timeout=JTimeval::min())
Check for header, without waiting.
int SendMeAlways()
Tell server to send messages forever.
int Subscribe(const JSubscription &subscription)
Subscribe to single tag.
JSubscriptionList & add(const JSubscription &subscription)
Add subscription.
Utility class to parse command line options.
void open(const char *name, int open_mode=std::ios::out)
std::string getFullPath(const std::string &path)
Get full path, i.e. add JEEP::PATHNAME_SEPARATOR if necessary.
void close(std::istream *pf)
Close file.
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
T * open(const std::string &file_name)
Open file.
static const std::string MESSAGE_TAG
Message logging tag.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for sequence of same character.
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.