aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/common
diff options
context:
space:
mode:
authorGravatar bunnei <bunneidev@gmail.com>2015-03-09 15:42:18 -0400
committerGravatar bunnei <bunneidev@gmail.com>2015-03-09 15:42:18 -0400
commit3da94a597b5642c1b586700d72255589cf5a0cdf (patch)
tree9f73ded034bceaab1f7e41cf19fe987d19b2e083 /src/common
parentf2a7c2b3b74df6b1977392a5ad7e91bae4a8a5b6 (diff)
parent0aa44e238db7a72f4fb8b347168ec76c3ce48ad5 (diff)
Merge pull request #634 from linkmauve/logging-performances
Apply the logging filter before sending the message to the queue
Diffstat (limited to 'src/common')
-rw-r--r--src/common/logging/backend.cpp9
-rw-r--r--src/common/logging/backend.h3
-rw-r--r--src/common/logging/filter.h2
-rw-r--r--src/common/logging/text_formatter.cpp7
-rw-r--r--src/common/logging/text_formatter.h3
5 files changed, 17 insertions, 7 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 7c1010b2..7b479b56 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -135,9 +135,18 @@ Entry CreateEntry(Class log_class, Level log_level,
return std::move(entry);
}
+static Filter* filter;
+
+void SetFilter(Filter* new_filter) {
+ filter = new_filter;
+}
+
void LogMessage(Class log_class, Level log_level,
const char* filename, unsigned int line_nr, const char* function,
const char* format, ...) {
+ if (!filter->CheckMessage(log_class, log_level))
+ return;
+
va_list args;
va_start(args, format);
Entry entry = CreateEntry(log_class, log_level,
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h
index 1c44c929..3114f864 100644
--- a/src/common/logging/backend.h
+++ b/src/common/logging/backend.h
@@ -10,6 +10,7 @@
#include "common/concurrent_ring_buffer.h"
+#include "common/logging/filter.h"
#include "common/logging/log.h"
namespace Log {
@@ -131,4 +132,6 @@ Entry CreateEntry(Class log_class, Level log_level,
/// Initializes the default Logger.
std::shared_ptr<Logger> InitGlobalLogger();
+void SetFilter(Filter* filter);
+
}
diff --git a/src/common/logging/filter.h b/src/common/logging/filter.h
index c3da9989..b53e4e63 100644
--- a/src/common/logging/filter.h
+++ b/src/common/logging/filter.h
@@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#pragma once
+
#include <array>
#include <string>
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp
index ef5739d8..36c91c4f 100644
--- a/src/common/logging/text_formatter.cpp
+++ b/src/common/logging/text_formatter.cpp
@@ -11,7 +11,6 @@
#endif
#include "common/logging/backend.h"
-#include "common/logging/filter.h"
#include "common/logging/log.h"
#include "common/logging/text_formatter.h"
@@ -116,7 +115,7 @@ void PrintColoredMessage(const Entry& entry) {
#endif
}
-void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter) {
+void TextLoggingLoop(std::shared_ptr<Logger> logger) {
std::array<Entry, 256> entry_buffer;
while (true) {
@@ -126,9 +125,7 @@ void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter) {
}
for (size_t i = 0; i < num_entries; ++i) {
const Entry& entry = entry_buffer[i];
- if (filter->CheckMessage(entry.log_class, entry.log_level)) {
- PrintColoredMessage(entry);
- }
+ PrintColoredMessage(entry);
}
}
}
diff --git a/src/common/logging/text_formatter.h b/src/common/logging/text_formatter.h
index 2f05794f..8474a190 100644
--- a/src/common/logging/text_formatter.h
+++ b/src/common/logging/text_formatter.h
@@ -11,7 +11,6 @@ namespace Log {
class Logger;
struct Entry;
-class Filter;
/**
* Attempts to trim an arbitrary prefix from `path`, leaving only the part starting at `root`. It's
@@ -36,6 +35,6 @@ void PrintColoredMessage(const Entry& entry);
* Logging loop that repeatedly reads messages from the provided logger and prints them to the
* console. It is the baseline barebones log outputter.
*/
-void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter);
+void TextLoggingLoop(std::shared_ptr<Logger> logger);
}