|
|
@ -11,8 +11,10 @@ class ArgParser
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
ArgParser()
|
|
|
|
ArgParser()
|
|
|
|
: m_print_to_console(false)
|
|
|
|
: m_print_to_console(false)
|
|
|
|
, m_print_timestamp(false)
|
|
|
|
|
|
|
|
, m_logFile()
|
|
|
|
, m_logFile()
|
|
|
|
|
|
|
|
, m_timestamp(false)
|
|
|
|
|
|
|
|
, m_hostname(false)
|
|
|
|
|
|
|
|
, m_username(false)
|
|
|
|
{}
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void printUsage(bool cout = true)
|
|
|
|
void printUsage(bool cout = true)
|
|
|
@ -23,12 +25,14 @@ public:
|
|
|
|
<< "Logs the input (till EOF) to the console or to a file.\n"
|
|
|
|
<< "Logs the input (till EOF) to the console or to a file.\n"
|
|
|
|
<< "\n"
|
|
|
|
<< "\n"
|
|
|
|
<< "Options:\n"
|
|
|
|
<< "Options:\n"
|
|
|
|
<< " -t, prefix lines with timestamp\n"
|
|
|
|
|
|
|
|
<< " -c, log to console\n"
|
|
|
|
<< " -c, log to console\n"
|
|
|
|
<< " -f FILE log to FILE\n"
|
|
|
|
<< " -f FILE log to FILE\n"
|
|
|
|
|
|
|
|
<< " -t, prefix lines with timestamp\n"
|
|
|
|
|
|
|
|
<< " -n, prefix lines with hostname\n"
|
|
|
|
|
|
|
|
<< " -u, prefix lines with user name\n"
|
|
|
|
<< " -h print this help\n"
|
|
|
|
<< " -h print this help\n"
|
|
|
|
<< "\n"
|
|
|
|
<< "\n"
|
|
|
|
<< "Option -c and -f are mutually exclusive.\n"
|
|
|
|
<< "Option -c and -f are mutually exclusive, specify one.\n"
|
|
|
|
<< "\n"
|
|
|
|
<< "\n"
|
|
|
|
<< "Denes Matetelki <denes@matetelki.com>\n";
|
|
|
|
<< "Denes Matetelki <denes@matetelki.com>\n";
|
|
|
|
|
|
|
|
|
|
|
@ -41,13 +45,13 @@ public:
|
|
|
|
int parse(int argc, char* argv[])
|
|
|
|
int parse(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int c;
|
|
|
|
while ((c = getopt (argc, argv, "ctf:h")) != -1) {
|
|
|
|
while ((c = getopt (argc, argv, "cf:tnuh")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
case 'c':
|
|
|
|
m_print_to_console = true;
|
|
|
|
m_print_to_console = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
case 't':
|
|
|
|
m_print_timestamp = true;
|
|
|
|
m_timestamp = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
case 'f':
|
|
|
|
m_logFile = std::string(optarg);
|
|
|
|
m_logFile = std::string(optarg);
|
|
|
@ -69,7 +73,9 @@ public:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool printToConsole() const { return m_print_to_console; }
|
|
|
|
bool printToConsole() const { return m_print_to_console; }
|
|
|
|
bool printTimestamp() const { return m_print_timestamp; }
|
|
|
|
bool printTimestamp() const { return m_timestamp; }
|
|
|
|
|
|
|
|
bool printHostname() const { return m_hostname; }
|
|
|
|
|
|
|
|
bool printUsername() const { return m_username; }
|
|
|
|
std::string logFile() const { return m_logFile; }
|
|
|
|
std::string logFile() const { return m_logFile; }
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
@ -77,10 +83,12 @@ private:
|
|
|
|
char** m_argv;
|
|
|
|
char** m_argv;
|
|
|
|
|
|
|
|
|
|
|
|
bool m_print_to_console;
|
|
|
|
bool m_print_to_console;
|
|
|
|
bool m_print_timestamp;
|
|
|
|
|
|
|
|
std::string m_logFile;
|
|
|
|
std::string m_logFile;
|
|
|
|
|
|
|
|
bool m_timestamp;
|
|
|
|
|
|
|
|
bool m_hostname;
|
|
|
|
|
|
|
|
bool m_username;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define LOG *Logger::getInstance()->getStream()
|
|
|
|
// #define LOG *Logger::getInstance()->getStream()
|
|
|
|
|
|
|
|
|
|
|
|
#endif // ARGPARSER_HPP
|
|
|
|
#endif // ARGPARSER_HPP
|
|
|
|