diff options
author | Peter Rajnoha <prajnoha@redhat.com> | 2016-05-19 12:19:48 +0200 |
---|---|---|
committer | Peter Rajnoha <prajnoha@redhat.com> | 2016-06-20 11:33:42 +0200 |
commit | f50d4011cdd3ef38c15b9dea05e73321592d93c2 (patch) | |
tree | d3231d97b4f24232bf19a70b1429814264426c22 /lib/log | |
parent | fe63715f25cf156b07e144a2e7b5cce56d32e39e (diff) | |
download | lvm2-f50d4011cdd3ef38c15b9dea05e73321592d93c2.tar.gz |
log: also pass log_print through report and add log_print_bypass_report for use in libdm-report for direct print without report
log_print is used during cmd line processing to log the result of the
operation (e.g. "Volume group vg successfully changed" and similar).
We don't want output from log_print to be interleaved with current
reports from group where log is reported as well. Also, the information
printed by log_print belongs to the log report too, so it should be
rerouted to log report if it's set.
Since the code in libdm-report which is responsible for doing the report
output uses log_print too, we need to use a different kind of log_print
which bypasses any log report currently used for logging (...simply,
we can't call log_print to output the log report itself which in turn
would again reroute to report - the report would never get on output
this way).
Diffstat (limited to 'lib/log')
-rw-r--r-- | lib/log/log.c | 16 | ||||
-rw-r--r-- | lib/log/log.h | 2 |
2 files changed, 11 insertions, 7 deletions
diff --git a/lib/log/log.c b/lib/log/log.c index 3181fdd61..0bd2de963 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -270,7 +270,7 @@ void reset_log_duplicated(void) { } } -static const char *_get_log_level_name(int level) +static const char *_get_log_level_name(int use_stderr, int level) { static const char *log_level_names[] = {"", /* unassigned */ "", /* unassigned */ @@ -281,7 +281,9 @@ static const char *_get_log_level_name(int level) "info", /* _LOG_INFO */ "debug" /* _LOG_DEBUG */ }; - level &= ~_LOG_STDERR; + if (level == _LOG_WARN && !use_stderr) + return "print"; + return log_level_names[level]; } @@ -312,6 +314,7 @@ void print_log(int level, const char *file, int line, int dm_errno_or_class, char *newbuf; int use_stderr = level & _LOG_STDERR; int log_once = level & _LOG_ONCE; + int log_bypass_report = level & _LOG_BYPASS_REPORT; int fatal_internal_error = 0; size_t msglen; const char *indent_spaces = ""; @@ -322,7 +325,7 @@ void print_log(int level, const char *file, int line, int dm_errno_or_class, struct dm_report *orig_report; int logged_via_report = 0; - level &= ~(_LOG_STDERR|_LOG_ONCE); + level &= ~(_LOG_STDERR|_LOG_ONCE|_LOG_BYPASS_REPORT); if (_abort_on_internal_errors_env_present < 0) { if ((env_str = getenv("DM_ABORT_ON_INTERNAL_ERRORS"))) { @@ -353,7 +356,7 @@ void print_log(int level, const char *file, int line, int dm_errno_or_class, if (_lvm2_log_fn || (_store_errmsg && (level <= _LOG_ERR)) || - (_log_report.report && (use_stderr || (level <=_LOG_ERR))) || + (_log_report.report && !log_bypass_report && (use_stderr || (level <=_LOG_WARN))) || log_once) { va_start(ap, format); n = vsnprintf(message, sizeof(message), trformat, ap); @@ -401,11 +404,10 @@ void print_log(int level, const char *file, int line, int dm_errno_or_class, } } - if (_log_report.report && (use_stderr || (level <= _LOG_ERR))) { + if (_log_report.report && !log_bypass_report && (use_stderr || (level <= _LOG_WARN))) { orig_report = _log_report.report; _log_report.report = NULL; - - if (!report_cmdlog(orig_report, _get_log_level_name(level), + if (!report_cmdlog(orig_report, _get_log_level_name(use_stderr, level), log_get_report_context_name(_log_report.context), log_get_report_object_type_name(_log_report.object_type), _log_report.object_name, _log_report.object_id, diff --git a/lib/log/log.h b/lib/log/log.h index 222a1adba..15d363e68 100644 --- a/lib/log/log.h +++ b/lib/log/log.h @@ -44,6 +44,7 @@ #define _LOG_STDERR 128 /* force things to go to stderr, even if loglevel would make them go to stdout */ #define _LOG_ONCE 256 /* downgrade to NOTICE if this has been already logged */ +#define _LOG_BYPASS_REPORT 512 /* do not log through report even if report available */ #define _LOG_DEBUG 7 #define _LOG_INFO 6 #define _LOG_NOTICE 5 @@ -93,6 +94,7 @@ #define log_very_verbose(args...) log_info(args) #define log_verbose(args...) log_notice(args) #define log_print(args...) LOG_LINE(_LOG_WARN, args) +#define log_print_bypass_report(args...) LOG_LINE(_LOG_WARN | _LOG_BYPASS_REPORT, args) #define log_print_unless_silent(args...) LOG_LINE(silent_mode() ? _LOG_NOTICE : _LOG_WARN, args) #define log_error(args...) log_err(args) #define log_error_suppress(s, args...) log_err_suppress(s, args) |