1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

logging: add more log macros

Introduce macros:

log_level(), log_stderr(), log_once(), log_bypass_report()

For easier and more consisten way how to 'decoder' bits
of info from passed 'level'.

This patch fixes potential problem when 'level' of message
might not have always masked right bits.
This commit is contained in:
Zdenek Kabelac 2016-11-02 14:39:13 +01:00
parent 96118a2508
commit 6af26273cb
5 changed files with 15 additions and 10 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.136 -
======================================
Use log_level() macro to consistently decode message log level in dmeventd.
Still produce output when dmsetup dependency tree building finds dev missing.
Check and report pthread_sigmask() failure in dmeventd.
Check mem alloc fail in _canonicalize_field_ids().

View File

@ -868,11 +868,11 @@ void dm_event_log(const char *subsys, int level, const char *file,
static pthread_mutex_t _log_mutex = PTHREAD_MUTEX_INITIALIZER;
static time_t start = 0;
const char *indent = "";
FILE *stream = stdout;
FILE *stream = log_stderr(level) ? stderr : stdout;
int prio;
time_t now;
switch (level & ~(_LOG_STDERR | _LOG_ONCE)) {
switch (log_level(level)) {
case _LOG_DEBUG:
if (_debug_level < 3)
return;

View File

@ -476,9 +476,9 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
int bufused, n;
const char *trformat; /* Translated format string */
char *newbuf;
int use_stderr = level & _LOG_STDERR;
int log_once = level & _LOG_ONCE;
int log_bypass_report = level & _LOG_BYPASS_REPORT;
int use_stderr = log_stderr(level);
int log_once = log_once(level);
int log_bypass_report = log_bypass_report(level);
int fatal_internal_error = 0;
size_t msglen;
const char *indent_spaces = "";
@ -489,7 +489,7 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
struct dm_report *orig_report;
int logged_via_report = 0;
level &= ~(_LOG_STDERR|_LOG_ONCE|_LOG_BYPASS_REPORT);
level = log_level(level);
if (_abort_on_internal_errors_env_present < 0) {
if ((env_str = getenv("DM_ABORT_ON_INTERNAL_ERRORS"))) {
@ -715,8 +715,8 @@ void print_log_libdm(int level, const char *file, int line, int dm_errno_or_clas
* LOG_WARN level and it's not going to stderr (so we're
* printing common message that is not an error/warning).
*/
if (!(level & _LOG_STDERR) &&
((level & ~(_LOG_STDERR|_LOG_ONCE|_LOG_BYPASS_REPORT)) == _LOG_WARN))
if (!log_stderr(level) &&
(log_level(level) == _LOG_WARN))
level |= _LOG_BYPASS_REPORT;
_log_stream.out.stream = report_stream;

View File

@ -50,6 +50,10 @@
#define _LOG_STDERR 0x0080 /* force things to go to stderr, even if loglevel would make them go to stdout */
#define _LOG_ONCE 0x0100 /* downgrade to NOTICE if this has been already logged */
#define _LOG_BYPASS_REPORT 0x0200 /* do not log through report even if report available */
#define log_level(x) ((x) & 0x0f) /* obtain message level */
#define log_stderr(x) ((x) & _LOG_STDERR) /* obtain stderr bit */
#define log_once(x) ((x) & _LOG_ONCE) /* obtain once bit */
#define log_bypass_report(x) ((x) & _LOG_BYPASS_REPORT)/* obtain bypass bit */
#define INTERNAL_ERROR "Internal error: "

View File

@ -114,9 +114,9 @@ static void _default_log_line(int level,
const char *f, va_list ap)
{
static int _abort_on_internal_errors = -1;
FILE *out = (level & _LOG_STDERR) ? stderr : stdout;
FILE *out = log_stderr(level) ? stderr : stdout;
level &= ~(_LOG_STDERR | _LOG_BYPASS_REPORT);
level = log_level(level);
if (level <= _LOG_WARN || _verbose) {
if (level < _LOG_WARN)