kopia lustrzana https://github.com/weetmuts/wmbusmeters
Added --silent and test for stdin pipe close down.
rodzic
e73008ff65
commit
3b86b00b96
|
@ -185,6 +185,7 @@ As <options> you can use:
|
|||
--selectfields=id,timestamp,total_m3 select fields to be printed
|
||||
--separator=<c> change field separator to c
|
||||
--shell=<cmdline> invokes cmdline with env variables containing the latest reading
|
||||
--silent do not print informational messages nor warnings
|
||||
--useconfig=<dir> load config files from dir/etc
|
||||
--usestderr write notices/debug/verbose and other logging output to stderr (the default)
|
||||
--usestdoutforlogging write debug/verbose and logging output to stdout
|
||||
|
|
|
@ -73,8 +73,8 @@ shared_ptr<Configuration> parseCommandLine(int argc, char **argv) {
|
|||
c->need_help = true;
|
||||
return shared_ptr<Configuration>(c);
|
||||
}
|
||||
if (!strcmp(argv[i], "--silence")) {
|
||||
c->silence = true;
|
||||
if (!strcmp(argv[i], "--silent")) {
|
||||
c->silent = true;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -167,7 +167,7 @@ void handleLoglevel(Configuration *c, string loglevel)
|
|||
// Kick in trace immediately.
|
||||
traceEnabled(c->trace);
|
||||
}
|
||||
else if (loglevel == "silent") { c->silence = true; }
|
||||
else if (loglevel == "silent") { c->silent = true; }
|
||||
else if (loglevel == "normal") { }
|
||||
else {
|
||||
warning("No such log level: \"%s\"\n", loglevel.c_str());
|
||||
|
|
|
@ -52,7 +52,7 @@ struct Configuration
|
|||
std::string config_root;
|
||||
bool reload {};
|
||||
bool need_help {};
|
||||
bool silence {};
|
||||
bool silent {};
|
||||
bool verbose {};
|
||||
bool version {};
|
||||
bool license {};
|
||||
|
|
|
@ -1078,7 +1078,7 @@ bool start(Configuration *config)
|
|||
}
|
||||
|
||||
// Configure settings.
|
||||
warningSilenced(config->silence);
|
||||
silentLogging(config->silent);
|
||||
verboseEnabled(config->verbose);
|
||||
logTelegramsEnabled(config->logtelegrams);
|
||||
debugEnabled(config->debug);
|
||||
|
|
|
@ -188,6 +188,9 @@ protected:
|
|||
bool expecting_ascii_ {}; // If true, print using safeString instead if bin2hex
|
||||
bool is_file_ = false;
|
||||
bool is_stdin_ = false;
|
||||
// When feeding from stdin, to prevent early exit, we want
|
||||
// at least some data before leaving the loop!
|
||||
// I.e. do not exit before we have received something!
|
||||
bool no_callbacks_ = false;
|
||||
SerialCommunicationManagerImp *manager_;
|
||||
bool resetting_ {}; // Set to true while resetting.
|
||||
|
@ -227,11 +230,19 @@ int SerialDeviceImp::receive(vector<uchar> *data)
|
|||
}
|
||||
if (nr == 0)
|
||||
{
|
||||
if (is_stdin_ || is_file_)
|
||||
if (is_file_)
|
||||
{
|
||||
debug("(serial) no more data on fd=%d\n", fd_);
|
||||
debug("(serial) no more data on file fd=%d\n", fd_);
|
||||
close_me = true;
|
||||
}
|
||||
if (is_stdin_)
|
||||
{
|
||||
if (getchar() == EOF)
|
||||
{
|
||||
debug("(serial) no more data on stdin fd=%d\n", fd_);
|
||||
close_me = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (nr < 0)
|
||||
|
|
28
src/util.cc
28
src/util.cc
|
@ -278,7 +278,7 @@ string format3fdot3f(double v)
|
|||
|
||||
bool syslog_enabled_ = false;
|
||||
bool logfile_enabled_ = false;
|
||||
bool warning_enabled_ = true;
|
||||
bool logging_silenced_ = false;
|
||||
bool verbose_enabled_ = false;
|
||||
bool debug_enabled_ = false;
|
||||
bool trace_enabled_ = false;
|
||||
|
@ -288,8 +288,8 @@ bool internal_testing_enabled_ = false;
|
|||
|
||||
string log_file_;
|
||||
|
||||
void warningSilenced(bool b) {
|
||||
warning_enabled_ = !b;
|
||||
void silentLogging(bool b) {
|
||||
logging_silenced_ = b;
|
||||
}
|
||||
|
||||
void enableSyslog() {
|
||||
|
@ -418,21 +418,25 @@ void outputStuff(int syslog_level, const char *fmt, va_list args)
|
|||
}
|
||||
|
||||
void info(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
outputStuff(LOG_INFO, fmt, args);
|
||||
va_end(args);
|
||||
if (!logging_silenced_) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
outputStuff(LOG_INFO, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
||||
void notice(const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
outputStuff(LOG_NOTICE, fmt, args);
|
||||
va_end(args);
|
||||
if (!logging_silenced_) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
outputStuff(LOG_NOTICE, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
||||
void warning(const char* fmt, ...) {
|
||||
if (warning_enabled_) {
|
||||
if (!logging_silenced_) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
outputStuff(LOG_WARNING, fmt, args);
|
||||
|
|
|
@ -72,7 +72,7 @@ void warning(const char* fmt, ...);
|
|||
void info(const char* fmt, ...);
|
||||
void notice(const char* fmt, ...);
|
||||
|
||||
void warningSilenced(bool b);
|
||||
void silentLogging(bool b);
|
||||
void verboseEnabled(bool b);
|
||||
void debugEnabled(bool b);
|
||||
void traceEnabled(bool b);
|
||||
|
|
3
test.sh
3
test.sh
|
@ -90,6 +90,9 @@ if [ "$?" != "0" ]; then RC="1"; fi
|
|||
tests/test_ignore_duplicates.sh $PROG
|
||||
if [ "$?" != "0" ]; then RC="1"; fi
|
||||
|
||||
tests/test_pipe.sh $PROG
|
||||
if [ "$?" != "0" ]; then RC="1"; fi
|
||||
|
||||
if [ "$(uname)" = "Linux" ]
|
||||
then
|
||||
tests/test_alarm.sh $PROG
|
||||
|
|
|
@ -81,6 +81,8 @@ mqtt_publish) sent to a REST API (eg curl) or store it in a database
|
|||
|
||||
\fB\--shell=\fR<cmdline> invokes cmdline with env variables containing the latest reading
|
||||
|
||||
\fB\--silent\fR do not print informational messages nor warnings
|
||||
|
||||
\fB\--useconfig=\fR<dir> load config files from dir/etc
|
||||
|
||||
\fB\--usestderr\fR write notices/debug/verbose and other logging output to stderr (the default)
|
||||
|
|
Ładowanie…
Reference in New Issue