mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-02 08:25:07 +01:00
Merge pull request #634 from linkmauve/logging-performances
Apply the logging filter before sending the message to the queue
This commit is contained in:
commit
3da94a597b
@ -22,7 +22,8 @@
|
|||||||
int __cdecl main(int argc, char **argv) {
|
int __cdecl main(int argc, char **argv) {
|
||||||
std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger();
|
std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger();
|
||||||
Log::Filter log_filter(Log::Level::Debug);
|
Log::Filter log_filter(Log::Level::Debug);
|
||||||
std::thread logging_thread(Log::TextLoggingLoop, logger, &log_filter);
|
Log::SetFilter(&log_filter);
|
||||||
|
std::thread logging_thread(Log::TextLoggingLoop, logger);
|
||||||
SCOPE_EXIT({
|
SCOPE_EXIT({
|
||||||
logger->Close();
|
logger->Close();
|
||||||
logging_thread.join();
|
logging_thread.join();
|
||||||
|
@ -316,7 +316,8 @@ int __cdecl main(int argc, char* argv[])
|
|||||||
{
|
{
|
||||||
std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger();
|
std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger();
|
||||||
Log::Filter log_filter(Log::Level::Info);
|
Log::Filter log_filter(Log::Level::Info);
|
||||||
std::thread logging_thread(Log::TextLoggingLoop, logger, &log_filter);
|
Log::SetFilter(&log_filter);
|
||||||
|
std::thread logging_thread(Log::TextLoggingLoop, logger);
|
||||||
SCOPE_EXIT({
|
SCOPE_EXIT({
|
||||||
logger->Close();
|
logger->Close();
|
||||||
logging_thread.join();
|
logging_thread.join();
|
||||||
|
@ -135,9 +135,18 @@ Entry CreateEntry(Class log_class, Level log_level,
|
|||||||
return std::move(entry);
|
return std::move(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Filter* filter;
|
||||||
|
|
||||||
|
void SetFilter(Filter* new_filter) {
|
||||||
|
filter = new_filter;
|
||||||
|
}
|
||||||
|
|
||||||
void LogMessage(Class log_class, Level log_level,
|
void LogMessage(Class log_class, Level log_level,
|
||||||
const char* filename, unsigned int line_nr, const char* function,
|
const char* filename, unsigned int line_nr, const char* function,
|
||||||
const char* format, ...) {
|
const char* format, ...) {
|
||||||
|
if (!filter->CheckMessage(log_class, log_level))
|
||||||
|
return;
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
Entry entry = CreateEntry(log_class, log_level,
|
Entry entry = CreateEntry(log_class, log_level,
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "common/concurrent_ring_buffer.h"
|
#include "common/concurrent_ring_buffer.h"
|
||||||
|
|
||||||
|
#include "common/logging/filter.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
|
|
||||||
namespace Log {
|
namespace Log {
|
||||||
@ -131,4 +132,6 @@ Entry CreateEntry(Class log_class, Level log_level,
|
|||||||
/// Initializes the default Logger.
|
/// Initializes the default Logger.
|
||||||
std::shared_ptr<Logger> InitGlobalLogger();
|
std::shared_ptr<Logger> InitGlobalLogger();
|
||||||
|
|
||||||
|
void SetFilter(Filter* filter);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "common/logging/backend.h"
|
#include "common/logging/backend.h"
|
||||||
#include "common/logging/filter.h"
|
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/logging/text_formatter.h"
|
#include "common/logging/text_formatter.h"
|
||||||
|
|
||||||
@ -116,7 +115,7 @@ void PrintColoredMessage(const Entry& entry) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter) {
|
void TextLoggingLoop(std::shared_ptr<Logger> logger) {
|
||||||
std::array<Entry, 256> entry_buffer;
|
std::array<Entry, 256> entry_buffer;
|
||||||
|
|
||||||
while (true) {
|
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) {
|
for (size_t i = 0; i < num_entries; ++i) {
|
||||||
const Entry& entry = entry_buffer[i];
|
const Entry& entry = entry_buffer[i];
|
||||||
if (filter->CheckMessage(entry.log_class, entry.log_level)) {
|
PrintColoredMessage(entry);
|
||||||
PrintColoredMessage(entry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ namespace Log {
|
|||||||
|
|
||||||
class Logger;
|
class Logger;
|
||||||
struct Entry;
|
struct Entry;
|
||||||
class Filter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to trim an arbitrary prefix from `path`, leaving only the part starting at `root`. It's
|
* 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
|
* Logging loop that repeatedly reads messages from the provided logger and prints them to the
|
||||||
* console. It is the baseline barebones log outputter.
|
* 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user