|
|
4b6aa8 |
From c362b6a9c4abb2f4185f5c88b90aecfebd6c67cb Mon Sep 17 00:00:00 2001
|
|
|
4b6aa8 |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
4b6aa8 |
Date: Thu, 24 Jul 2014 13:34:50 +0200
|
|
|
4b6aa8 |
Subject: [LIBREPORT PATCH 73/93] logging: test log level at first step
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
Return from the logger immediately if message's log level is not
|
|
|
4b6aa8 |
sufficient to write it to the log.
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
This patch is a workaround for rhbz#1122690 where we try to log a
|
|
|
4b6aa8 |
'post'ed string which has 18MB of size. It is not worth to try to fix it
|
|
|
4b6aa8 |
properly. We do not log such a big amount of data in non-debug mode, we
|
|
|
4b6aa8 |
need to have the logging extremely fast and we can live with crashes in
|
|
|
4b6aa8 |
debug mode.
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
Resolves: #1142380
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
4b6aa8 |
---
|
|
|
4b6aa8 |
src/lib/logging.c | 26 +++++++++++---------------
|
|
|
4b6aa8 |
1 file changed, 11 insertions(+), 15 deletions(-)
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
diff --git a/src/lib/logging.c b/src/lib/logging.c
|
|
|
4b6aa8 |
index 259a634..4b9dd87 100644
|
|
|
4b6aa8 |
--- a/src/lib/logging.c
|
|
|
4b6aa8 |
+++ b/src/lib/logging.c
|
|
|
4b6aa8 |
@@ -66,7 +66,7 @@ static void log_handler(int level,
|
|
|
4b6aa8 |
int line,
|
|
|
4b6aa8 |
const char *func)
|
|
|
4b6aa8 |
{
|
|
|
4b6aa8 |
- if (!logmode)
|
|
|
4b6aa8 |
+ if (!logmode || !should_log(level))
|
|
|
4b6aa8 |
return;
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
/* This is ugly and costs +60 bytes compared to multiple
|
|
|
4b6aa8 |
@@ -122,29 +122,25 @@ static void log_handler(int level,
|
|
|
4b6aa8 |
strcpy(&msg[used], msg_eol);
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
if (flags & LOGMODE_STDIO) {
|
|
|
4b6aa8 |
- if(should_log(level))
|
|
|
4b6aa8 |
- full_write(STDERR_FILENO, msg, used + msgeol_len);
|
|
|
4b6aa8 |
+ full_write(STDERR_FILENO, msg, used + msgeol_len);
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
msg[used] = '\0'; /* remove msg_eol (usually "\n") */
|
|
|
4b6aa8 |
if (flags & LOGMODE_SYSLOG) {
|
|
|
4b6aa8 |
- if(should_log(level))
|
|
|
4b6aa8 |
- syslog(level, "%s", msg + prefix_len);
|
|
|
4b6aa8 |
+ syslog(level, "%s", msg + prefix_len);
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
if ((flags & LOGMODE_CUSTOM) && g_custom_logger) {
|
|
|
4b6aa8 |
- if(should_log(level))
|
|
|
4b6aa8 |
- g_custom_logger(msg + prefix_len);
|
|
|
4b6aa8 |
+ g_custom_logger(msg + prefix_len);
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
if (flags & LOGMODE_JOURNAL) {
|
|
|
4b6aa8 |
- if(should_log(level))
|
|
|
4b6aa8 |
- sd_journal_send("MESSAGE=%s", msg + prefix_len,
|
|
|
4b6aa8 |
- "PRIORITY=%d", level,
|
|
|
4b6aa8 |
- "CODE_FILE=%s", file,
|
|
|
4b6aa8 |
- "CODE_LINE=%d", line,
|
|
|
4b6aa8 |
- "CODE_FUNC=%s", func,
|
|
|
4b6aa8 |
- "SYSLOG_FACILITY=1",
|
|
|
4b6aa8 |
- NULL);
|
|
|
4b6aa8 |
+ sd_journal_send("MESSAGE=%s", msg + prefix_len,
|
|
|
4b6aa8 |
+ "PRIORITY=%d", level,
|
|
|
4b6aa8 |
+ "CODE_FILE=%s", file,
|
|
|
4b6aa8 |
+ "CODE_LINE=%d", line,
|
|
|
4b6aa8 |
+ "CODE_FUNC=%s", func,
|
|
|
4b6aa8 |
+ "SYSLOG_FACILITY=1",
|
|
|
4b6aa8 |
+ NULL);
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
--
|
|
|
4b6aa8 |
1.8.3.1
|
|
|
4b6aa8 |
|