Changeset 16822 for trunk/FACT++


Ignore:
Timestamp:
06/13/13 13:26:40 (11 years ago)
Author:
tbretz
Message:
Removed the day-tag. It looks a bit odd, because we have night-wise files anyway. Added the possibility that begin is after end (e.g. when displaying data from 23:00 to 01:00. Added a conversion of numbers to paths for easy access of log files in standard locations.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/showlog.cc

    r16817 r16822  
    22
    33#include "Time.h"
     4#include "tools.h"
    45#include "WindowLog.h"
    56#include "Configuration.h"
     
    1718        ("begin,b",   var<string>(), "Start time to be displayed (e.g. 20:00:12)")
    1819        ("end,e",     var<string>(), "End time to be displayed (e.g. 21:00:13)")
    19         ("day,d",     var<int16_t>()->implicit_value(true)->default_value(-1), "Index of block between start and end time to be displayed.")
    2020        ("verbose,v", var<int16_t>()->implicit_value(true)->default_value(8), "Verbosity level (0:only fatal errors, 8:everything)")
    2121        ("color,c",   po_bool(false), "Process a file which already contains color codes")
     
    4141        "Use -c or --color to process color coded files.\n"
    4242        "\n"
    43         "The default is to read from stdin.\n"
    44         "\n"
    45         "Usage: showlog [-c] [-vN] [-b start] [-e end] [-d day] [file1 ...]\n";
     43        "The default is to read from stdin if no filoename as given. If, as "
     44        "a filename, just a number between 2000000 and 21000000 is given, "
     45        "e.g. 20111016 a log with the name /fact/aux/2011/10/16/20111016.log "
     46        "is read.\n"
     47        "\n"
     48        "Usage: showlog [-c] [-vN] [-b start] [-e end] [file1 ...]\n";
    4649    cout << endl;
    4750}
     
    6164
    6265
    63 void showlog(const string &fname, const Time &tbeg, const Time &tend, int16_t day, int16_t severity, bool color)
     66void showlog(string fname, const Time &tbeg, const Time &tend, int16_t severity, bool color)
    6467{
    6568    // Alternatives
     
    6972    const boost::regex reg("\x1B\[[0-9;]*[a-zA-Z]");
    7073
     74    const uint32_t night = atoi(fname.c_str());
     75    if (night>20000000 && night<21000000 &&to_string(night)==fname)
     76        fname = Tools::Form("/fact/aux/%04d/%02d/%02d/%d.log",
     77                            night/10000, (night/100)%100, night%100, night);
     78
     79    if (!fname.empty())
     80        cerr << "Reading " << fname << endl;
     81
    7182    ifstream fin(fname.empty() ? "/dev/stdin" : fname.c_str());
     83    if (!fin)
     84        throw runtime_error(strerror(errno));
    7285
    7386    string buffer;
     
    93106            const Time t("1970-01-01 "+tm);
    94107
    95             if (day>=0)
     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())
    96115            {
    97                 if (tprev<tbeg && t>tbeg)
    98                     counter++;
    99 
    100                 tprev = t;
    101 
    102                 if (day!=counter)
    103                     continue;
     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                }
    104130            }
    105 
    106             if (tbeg.IsValid() && t<tbeg)
    107                 continue;
    108 
    109             if (tend.IsValid() && t>tend)
    110                 continue;
    111131        }
    112132
     
    175195
    176196    if (files.size()==0)
    177         showlog("", tbeg, tend, conf.Get<int16_t>("day"), conf.Get<int16_t>("verbose"), conf.Get<bool>("color"));
     197        showlog("", tbeg, tend, conf.Get<int16_t>("verbose"), conf.Get<bool>("color"));
    178198
    179199    for (auto it=files.begin(); it!=files.end(); it++)
    180         showlog(*it, tbeg, tend, conf.Get<int16_t>("day"), conf.Get<int16_t>("verbose"), conf.Get<bool>("color"));
     200        showlog(*it, tbeg, tend, conf.Get<int16_t>("verbose"), conf.Get<bool>("color"));
    181201
    182202    return 0;
Note: See TracChangeset for help on using the changeset viewer.