summaryrefslogtreecommitdiff
path: root/src/common/logging/text_formatter.cpp
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2014-10-28 05:36:00 -0200
committerGravatar Yuri Kunde Schlesner2014-12-13 01:59:52 -0200
commit616d87444313db865c60fbeee36ebe5250ef301e (patch)
treefb99bf8bebfdf8c825c5d3e4f01fb4779ceaba68 /src/common/logging/text_formatter.cpp
parentAdd SCOPE_EXIT macro to conveniently execute cleanup actions (diff)
downloadyuzu-616d87444313db865c60fbeee36ebe5250ef301e.tar.gz
yuzu-616d87444313db865c60fbeee36ebe5250ef301e.tar.xz
yuzu-616d87444313db865c60fbeee36ebe5250ef301e.zip
New logging system
Diffstat (limited to 'src/common/logging/text_formatter.cpp')
-rw-r--r--src/common/logging/text_formatter.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp
new file mode 100644
index 000000000..01c355bb6
--- /dev/null
+++ b/src/common/logging/text_formatter.cpp
@@ -0,0 +1,47 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2+
3// Refer to the license.txt file included.
4
5#include <array>
6#include <cstdio>
7
8#include "common/logging/backend.h"
9#include "common/logging/log.h"
10#include "common/logging/text_formatter.h"
11
12namespace Log {
13
14void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len) {
15 unsigned int time_seconds = static_cast<unsigned int>(entry.timestamp.count() / 1000000);
16 unsigned int time_fractional = static_cast<unsigned int>(entry.timestamp.count() % 1000000);
17
18 const char* class_name = Logger::GetLogClassName(entry.log_class);
19 const char* level_name = Logger::GetLevelName(entry.log_level);
20
21 snprintf(out_text, text_len, "[%4u.%06u] %s <%s> %s: %s",
22 time_seconds, time_fractional, class_name, level_name,
23 entry.location.c_str(), entry.message.c_str());
24}
25
26void PrintMessage(const Entry& entry) {
27 std::array<char, 4 * 1024> format_buffer;
28 FormatLogMessage(entry, format_buffer.data(), format_buffer.size());
29 fputs(format_buffer.data(), stderr);
30 fputc('\n', stderr);
31}
32
33void TextLoggingLoop(std::shared_ptr<Logger> logger) {
34 std::array<Entry, 256> entry_buffer;
35
36 while (true) {
37 size_t num_entries = logger->GetEntries(entry_buffer.data(), entry_buffer.size());
38 if (num_entries == Logger::QUEUE_CLOSED) {
39 break;
40 }
41 for (size_t i = 0; i < num_entries; ++i) {
42 PrintMessage(entry_buffer[i]);
43 }
44 }
45}
46
47}