mirror of
https://github.com/Zygo/bees.git
synced 2025-05-18 05:45:45 +02:00
bees: configurable log verbosity
Log messages were already labelled with log levels, but there was no way to filter by log level at run time. Implement the filter inside the bees process so it can skip evaluation of the BEESLOG* arguments if the log messages would not be emitted. Fixes: https://github.com/Zygo/bees/issues/67 Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
parent
b22db12390
commit
041ad717a5
@ -561,6 +561,8 @@ Command Line Options
|
|||||||
* --strip-paths (-P)
|
* --strip-paths (-P)
|
||||||
* Paths in log output will have the working directory at Bees startup
|
* Paths in log output will have the working directory at Bees startup
|
||||||
stripped.
|
stripped.
|
||||||
|
* --verbose (-v)
|
||||||
|
* Set log verbosity (0 = no output, 8 = all output, default 8).
|
||||||
|
|
||||||
|
|
||||||
Bug Reports and Contributions
|
Bug Reports and Contributions
|
||||||
|
52
src/bees.cc
52
src/bees.cc
@ -30,6 +30,8 @@
|
|||||||
using namespace crucible;
|
using namespace crucible;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
int bees_log_level = 8;
|
||||||
|
|
||||||
int
|
int
|
||||||
do_cmd_help(char *argv[])
|
do_cmd_help(char *argv[])
|
||||||
{
|
{
|
||||||
@ -48,6 +50,7 @@ do_cmd_help(char *argv[])
|
|||||||
"\t-T, --no-timestamps\tOmit timestamps in log output\n"
|
"\t-T, --no-timestamps\tOmit timestamps in log output\n"
|
||||||
"\t-p, --absolute-paths\tShow absolute paths (default)\n"
|
"\t-p, --absolute-paths\tShow absolute paths (default)\n"
|
||||||
"\t-P, --strip-paths\tStrip $CWD from beginning of all paths in the log\n"
|
"\t-P, --strip-paths\tStrip $CWD from beginning of all paths in the log\n"
|
||||||
|
"\t-v, --verbose\tSet maximum log level (0..8, default 8)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Optional environment variables:\n"
|
"Optional environment variables:\n"
|
||||||
"\tBEESHOME\tPath to hash table and configuration files\n"
|
"\tBEESHOME\tPath to hash table and configuration files\n"
|
||||||
@ -655,43 +658,54 @@ bees_main(int argc, char *argv[])
|
|||||||
while (1) {
|
while (1) {
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{ "thread-count", required_argument, NULL, 'c' },
|
|
||||||
{ "thread-factor", required_argument, NULL, 'C' },
|
{ "thread-factor", required_argument, NULL, 'C' },
|
||||||
{ "scan-mode", required_argument, NULL, 'm' },
|
|
||||||
{ "timestamps", no_argument, NULL, 't' },
|
|
||||||
{ "no-timestamps", no_argument, NULL, 'T' },
|
|
||||||
{ "absolute-paths", no_argument, NULL, 'p' },
|
|
||||||
{ "strip-paths", no_argument, NULL, 'P' },
|
{ "strip-paths", no_argument, NULL, 'P' },
|
||||||
{ "help", no_argument, NULL, 'h' }
|
{ "no-timestamps", no_argument, NULL, 'T' },
|
||||||
|
{ "thread-count", required_argument, NULL, 'c' },
|
||||||
|
{ "help", no_argument, NULL, 'h' },
|
||||||
|
{ "scan-mode", required_argument, NULL, 'm' },
|
||||||
|
{ "absolute-paths", no_argument, NULL, 'p' },
|
||||||
|
{ "timestamps", no_argument, NULL, 't' },
|
||||||
|
{ "verbose", required_argument, NULL, 'v' },
|
||||||
};
|
};
|
||||||
|
|
||||||
c = getopt_long(argc, argv, "c:C:m:TtPph", long_options, &option_index);
|
c = getopt_long(argc, argv, "C:PTc:hm:ptv:", long_options, &option_index);
|
||||||
if (-1 == c) {
|
if (-1 == c) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'c':
|
|
||||||
thread_count = stoul(optarg);
|
|
||||||
break;
|
|
||||||
case 'C':
|
case 'C':
|
||||||
thread_factor = stod(optarg);
|
thread_factor = stod(optarg);
|
||||||
break;
|
break;
|
||||||
case 'm':
|
|
||||||
BeesRoots::set_scan_mode(static_cast<BeesRoots::ScanMode>(stoul(optarg)));
|
|
||||||
break;
|
|
||||||
case 'T':
|
|
||||||
chatter_prefix_timestamp = false;
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
chatter_prefix_timestamp = true;
|
|
||||||
break;
|
|
||||||
case 'P':
|
case 'P':
|
||||||
crucible::set_relative_path(cwd);
|
crucible::set_relative_path(cwd);
|
||||||
break;
|
break;
|
||||||
|
case 'T':
|
||||||
|
chatter_prefix_timestamp = false;
|
||||||
|
break;
|
||||||
|
case 'c':
|
||||||
|
thread_count = stoul(optarg);
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
BeesRoots::set_scan_mode(static_cast<BeesRoots::ScanMode>(stoul(optarg)));
|
||||||
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
crucible::set_relative_path("");
|
crucible::set_relative_path("");
|
||||||
break;
|
break;
|
||||||
|
case 't':
|
||||||
|
chatter_prefix_timestamp = true;
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
{
|
||||||
|
int new_log_level = stoul(optarg);
|
||||||
|
THROW_CHECK1(out_of_range, new_log_level, new_log_level >= 0 || new_log_level <= 8);
|
||||||
|
bees_log_level = new_log_level;
|
||||||
|
BEESLOGNOTICE("log level set to " << bees_log_level);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
do_cmd_help(argv); // fallthrough
|
do_cmd_help(argv); // fallthrough
|
||||||
default:
|
default:
|
||||||
|
@ -127,7 +127,7 @@ const int FLAGS_OPEN_FANOTIFY = O_RDWR | O_NOATIME | O_CLOEXEC | O_LARGEFILE;
|
|||||||
|
|
||||||
// macros ----------------------------------------
|
// macros ----------------------------------------
|
||||||
|
|
||||||
#define BEESLOG(lv,x) do { Chatter c(lv, BeesNote::get_name()); c << x; } while (0)
|
#define BEESLOG(lv,x) do { if (lv < bees_log_level) { Chatter c(lv, BeesNote::get_name()); c << x; } } while (0)
|
||||||
#define BEESLOGTRACE(x) do { BEESLOG(LOG_DEBUG, x); BeesTracer::trace_now(); } while (0)
|
#define BEESLOGTRACE(x) do { BEESLOG(LOG_DEBUG, x); BeesTracer::trace_now(); } while (0)
|
||||||
|
|
||||||
#define BEESTRACE(x) BeesTracer SRSLY_WTF_C(beesTracer_, __LINE__) ([&]() { BEESLOG(LOG_ERR, x); })
|
#define BEESTRACE(x) BeesTracer SRSLY_WTF_C(beesTracer_, __LINE__) ([&]() { BEESLOG(LOG_ERR, x); })
|
||||||
@ -136,7 +136,7 @@ const int FLAGS_OPEN_FANOTIFY = O_RDWR | O_NOATIME | O_CLOEXEC | O_LARGEFILE;
|
|||||||
|
|
||||||
#define BEESLOGERR(x) BEESLOG(LOG_ERR, x)
|
#define BEESLOGERR(x) BEESLOG(LOG_ERR, x)
|
||||||
#define BEESLOGWARN(x) BEESLOG(LOG_WARNING, x)
|
#define BEESLOGWARN(x) BEESLOG(LOG_WARNING, x)
|
||||||
#define BEESLOGNOTE(x) BEESLOG(LOG_NOTICE, x)
|
#define BEESLOGNOTICE(x) BEESLOG(LOG_NOTICE, x)
|
||||||
#define BEESLOGINFO(x) BEESLOG(LOG_INFO, x)
|
#define BEESLOGINFO(x) BEESLOG(LOG_INFO, x)
|
||||||
#define BEESLOGDEBUG(x) BEESLOG(LOG_DEBUG, x)
|
#define BEESLOGDEBUG(x) BEESLOG(LOG_DEBUG, x)
|
||||||
|
|
||||||
@ -825,6 +825,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// And now, a giant pile of extern declarations
|
// And now, a giant pile of extern declarations
|
||||||
|
extern int bees_log_level;
|
||||||
extern const char *BEES_VERSION;
|
extern const char *BEES_VERSION;
|
||||||
string pretty(double d);
|
string pretty(double d);
|
||||||
void bees_sync(int fd);
|
void bees_sync(int fd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user