127{
  130 
  131  string          hostname;
  133  string          path;
  137 
  139  
  140  try {
  141 
  142    JParser<> zap(
"Auxiliary program to save logger messages from ControlHost server.");
 
  143 
  144    zap[
'H'] = 
make_field(hostname)        = 
"localhost";
 
  150 
  151    zap(argc, argv);
  152  }
  153  catch(const exception &error) {
  154    FATAL(error.what() << endl);
 
  155  }
  156 
  157  if (happy_hour.empty()) {
  158 
  159    WARNING(
"No happy hours (option -W); set to midnight." << endl);
 
  160 
  161    happy_hour.insert(0);
  162  }
  163 
  164 
  166  
  167  try {
  168 
  170 
  171    {
  173      
  176      }
  177 
  178      in.Subscribe(buffer);
  179      in.SendMeAlways();
  180    }
  181 
  182 
  183    JLoggerFile out(path);
  184 
  185    out.open();
  186 
  187    DEBUG(
"Open file  " << out.getFilename() << endl);
 
  188 
  190    string  buffer;
  191 
  193 
  194    for (int number_of_messages; buffer.size() != stop.size() || string(buffer.data(), stop.size()) != stop; ) {
  195 
  196      const int check = in.CheckHead(prefix, timeout);
  197 
  198      DEBUG(
"Check head " << check << endl);
 
  199 
  200      if        (check  < 0) {
  201 
  202        FATAL(
"Error at JControlHost::CheckHead " << check << endl);
 
  203 
  204      } else if (check == 1) {
  205 
  206        in.GetFullString(buffer);
  207 
  208        DEBUG(
"Message <" << buffer << 
">" << endl);
 
  209 
  210        if        (buffer == stop) {
  211 
  212          break;
  213 
  214        } else if (buffer == save) {
  215 
  216          DEBUG(
"Close file " << out.getFilename() << endl);
 
  217 
  218          out.close();
  219          out.open();
  220 
  221          DEBUG(
"Open file  " << out.getFilename() << endl);
 
  222 
  223        } else {
  224 
  225          ++number_of_messages;
  226 
  227          if ( ! (out << buffer << endl)) {
  228            FATAL(
"Error writing to file " << out.getFilename() << endl);
 
  229          }
  230        }
  231      }
  232 
  233      if (check == 0 || number_of_messages > MINIMUM_NUMBER_OF_MESSAGES) {
  234 
  235        number_of_messages = 0;
  236 
  238 
  240 
  242 
  243          DEBUG(
"Close file " << out.getFilename() << endl);
 
  244 
  245          out.close();
  246          out.open();
  247 
  248          DEBUG(
"Open file " << out.getFilename() << endl);
 
  249        }
  250      }
  251    }
  252 
  253    out.close();
  254  }    
  256    ERROR(error << endl);
 
  257  }
  258}
#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.