fix console TILE_FATAL to stderr
Some checks failed
android / build (push) Failing after 10s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Debug) (push) Failing after 7s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Release) (push) Failing after 7s
linux-arm-gcc / linux-gcc-arm (Debug) (push) Failing after 6s
linux-arm-gcc / linux-gcc-arm (Release) (push) Failing after 7s
linux-arm-gcc / linux-gcc-armhf (Debug) (push) Failing after 6s
linux-arm-gcc / linux-gcc-armhf (Release) (push) Failing after 7s
linux-mips-gcc / linux-gcc-mipsel (Debug) (push) Failing after 7s
linux-mips-gcc / linux-gcc-mipsel (Release) (push) Failing after 7s
android / build (pull_request) Failing after 7s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Failing after 7s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Failing after 12s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Debug) (pull_request) Failing after 13s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Release) (pull_request) Failing after 6s
linux-riscv64-gcc / linux-gcc-riscv64 (Debug) (push) Failing after 6s
linux-riscv64-gcc / linux-gcc-riscv64 (Release) (push) Failing after 7s
linux-arm-gcc / linux-gcc-arm (Debug) (pull_request) Failing after 7s
linux-arm-gcc / linux-gcc-arm (Release) (pull_request) Failing after 7s
linux-arm-gcc / linux-gcc-armhf (Debug) (pull_request) Failing after 8s
linux-arm-gcc / linux-gcc-armhf (Release) (pull_request) Failing after 8s
linux-x64-clang / linux-clang (Debug) (push) Failing after 7s
linux-x64-clang / linux-clang (Release) (push) Failing after 7s
linux-x64-gcc / linux-gcc (Debug) (push) Failing after 6s
linux-x64-gcc / linux-gcc (Release) (push) Failing after 7s
linux-mips-gcc / linux-gcc-mipsel (Debug) (pull_request) Failing after 7s
linux-mips-gcc / linux-gcc-mipsel (Release) (pull_request) Failing after 7s
linux-x86-gcc / linux-gcc (Debug) (push) Failing after 8s
linux-x86-gcc / linux-gcc (Release) (push) Failing after 7s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (pull_request) Failing after 7s
linux-mips64-gcc / linux-gcc-mips64el (Release) (pull_request) Failing after 12s
linux-riscv64-gcc / linux-gcc-riscv64 (Debug) (pull_request) Failing after 7s
linux-riscv64-gcc / linux-gcc-riscv64 (Release) (pull_request) Failing after 7s
linux-x64-clang / linux-clang (Debug) (pull_request) Failing after 8s
linux-x64-clang / linux-clang (Release) (pull_request) Failing after 8s
linux-x64-gcc / linux-gcc (Debug) (pull_request) Failing after 7s
linux-x64-gcc / linux-gcc (Release) (pull_request) Failing after 8s
linux-x86-gcc / linux-gcc (Debug) (pull_request) Failing after 7s
linux-x86-gcc / linux-gcc (Release) (pull_request) Failing after 8s
Some checks failed
android / build (push) Failing after 10s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Debug) (push) Failing after 7s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Release) (push) Failing after 7s
linux-arm-gcc / linux-gcc-arm (Debug) (push) Failing after 6s
linux-arm-gcc / linux-gcc-arm (Release) (push) Failing after 7s
linux-arm-gcc / linux-gcc-armhf (Debug) (push) Failing after 6s
linux-arm-gcc / linux-gcc-armhf (Release) (push) Failing after 7s
linux-mips-gcc / linux-gcc-mipsel (Debug) (push) Failing after 7s
linux-mips-gcc / linux-gcc-mipsel (Release) (push) Failing after 7s
android / build (pull_request) Failing after 7s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Failing after 7s
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Failing after 12s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Debug) (pull_request) Failing after 13s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (Release) (pull_request) Failing after 6s
linux-riscv64-gcc / linux-gcc-riscv64 (Debug) (push) Failing after 6s
linux-riscv64-gcc / linux-gcc-riscv64 (Release) (push) Failing after 7s
linux-arm-gcc / linux-gcc-arm (Debug) (pull_request) Failing after 7s
linux-arm-gcc / linux-gcc-arm (Release) (pull_request) Failing after 7s
linux-arm-gcc / linux-gcc-armhf (Debug) (pull_request) Failing after 8s
linux-arm-gcc / linux-gcc-armhf (Release) (pull_request) Failing after 8s
linux-x64-clang / linux-clang (Debug) (push) Failing after 7s
linux-x64-clang / linux-clang (Release) (push) Failing after 7s
linux-x64-gcc / linux-gcc (Debug) (push) Failing after 6s
linux-x64-gcc / linux-gcc (Release) (push) Failing after 7s
linux-mips-gcc / linux-gcc-mipsel (Debug) (pull_request) Failing after 7s
linux-mips-gcc / linux-gcc-mipsel (Release) (pull_request) Failing after 7s
linux-x86-gcc / linux-gcc (Debug) (push) Failing after 8s
linux-x86-gcc / linux-gcc (Release) (push) Failing after 7s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (pull_request) Failing after 7s
linux-mips64-gcc / linux-gcc-mips64el (Release) (pull_request) Failing after 12s
linux-riscv64-gcc / linux-gcc-riscv64 (Debug) (pull_request) Failing after 7s
linux-riscv64-gcc / linux-gcc-riscv64 (Release) (pull_request) Failing after 7s
linux-x64-clang / linux-clang (Debug) (pull_request) Failing after 8s
linux-x64-clang / linux-clang (Release) (pull_request) Failing after 8s
linux-x64-gcc / linux-gcc (Debug) (pull_request) Failing after 7s
linux-x64-gcc / linux-gcc (Release) (pull_request) Failing after 8s
linux-x86-gcc / linux-gcc (Debug) (pull_request) Failing after 7s
linux-x86-gcc / linux-gcc (Release) (pull_request) Failing after 8s
This commit is contained in:
parent
cbb103fd02
commit
681a5e9a7d
@ -84,7 +84,7 @@ public:
|
||||
}
|
||||
|
||||
num_chars_to_log_ = stream_.pcount();
|
||||
bool append_newline = message_text_[num_chars_to_log_ - 1] != '\n';
|
||||
const bool append_newline = message_text_[num_chars_to_log_ - 1] != '\n';
|
||||
char original_final_char = '\0';
|
||||
|
||||
if (append_newline) {
|
||||
@ -143,16 +143,17 @@ private:
|
||||
if (sink_) {
|
||||
sink_->Send(severity_, fullname(), basename(), line(), time(),
|
||||
message_text_ + num_prefix_chars_,
|
||||
num_chars_to_log_ - num_prefix_chars_ - 1);
|
||||
num_chars_to_log_ - num_prefix_chars_);
|
||||
}
|
||||
}
|
||||
void SendToLog() {
|
||||
if (g_sink_count.load(std::memory_order_relaxed) == 0) {
|
||||
ColoredWriteToStdout(severity_, message_text_, num_chars_to_log_);
|
||||
ColoredWriteToStdout(severity_, message_text_ + num_prefix_chars_,
|
||||
num_chars_to_log_ - num_chars_to_log_);
|
||||
}
|
||||
LogToSinks(severity_, fullname(), basename(), line(), time(),
|
||||
message_text_ + num_prefix_chars_,
|
||||
num_chars_to_log_ - num_prefix_chars_ - 1);
|
||||
num_chars_to_log_ - num_prefix_chars_);
|
||||
}
|
||||
void SendToSinkAndLog() {
|
||||
SendToSink();
|
||||
|
@ -706,7 +706,8 @@ public:
|
||||
const LogMessageTime &logmsgtime, const char *message,
|
||||
size_t message_len);
|
||||
virtual void Flush();
|
||||
std::string ToString(LogSeverity severity, const char *file, int line,
|
||||
std::string ToString(LogSeverity severity, const char *file,
|
||||
const char *base_file, int line,
|
||||
const LogMessageTime &logmsgtime, const char *message,
|
||||
size_t message_len);
|
||||
};
|
||||
|
@ -13,7 +13,7 @@ struct AwesomeLogSink : public tile::LogSink {
|
||||
const char *base_filename, int line,
|
||||
const tile::LogMessageTime &logmsgtime, const char *message,
|
||||
size_t message_len) override {
|
||||
msgs.emplace_back(message, message_len);
|
||||
msgs.emplace_back(std::string(message, message_len));
|
||||
}
|
||||
std::vector<std::string> msgs;
|
||||
};
|
||||
|
@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "tile/base/internal/logging.h"
|
||||
#include "tile/base/logging/basic_file_sink.h"
|
||||
#include "tile/base/logging/splitter_sink.h"
|
||||
|
||||
// #define TILE_VLOG(n, ...)
|
||||
|
@ -1,6 +1,11 @@
|
||||
#include "tile/base/logging/basic_file_sink.h"
|
||||
|
||||
namespace tile {
|
||||
BasicFileSink::Ptr BasicFileSink::Create(const std::string &filepath) {
|
||||
auto sink = std::shared_ptr<BasicFileSink>(new BasicFileSink());
|
||||
sink->set_filepath(filepath);
|
||||
return sink;
|
||||
}
|
||||
BasicFileSink::BasicFileSink() {}
|
||||
BasicFileSink::~BasicFileSink() {}
|
||||
void BasicFileSink::Send(LogSeverity severity, const char *full_filename,
|
||||
@ -8,7 +13,7 @@ void BasicFileSink::Send(LogSeverity severity, const char *full_filename,
|
||||
const LogMessageTime &logmsgtime, const char *message,
|
||||
size_t message_len) {
|
||||
TILE_CHECK(!filepath_.empty(), "filepath is empty");
|
||||
ofs_ << message << std::endl;
|
||||
ofs_ << std::string(message, message_len) << std::endl;
|
||||
}
|
||||
std::string BasicFileSink::filepath() const { return filepath_; }
|
||||
void BasicFileSink::set_filepath(const std::string &filepath) {
|
||||
|
@ -10,7 +10,9 @@
|
||||
namespace tile {
|
||||
class BasicFileSink : public LogSink {
|
||||
public:
|
||||
BasicFileSink();
|
||||
using Ptr = std::shared_ptr<BasicFileSink>;
|
||||
static Ptr Create(const std::string &filepath);
|
||||
|
||||
~BasicFileSink() override;
|
||||
void Send(LogSeverity severity, const char *full_filename,
|
||||
const char *base_filename, int line,
|
||||
@ -21,6 +23,9 @@ public:
|
||||
std::string filepath() const;
|
||||
void set_filepath(const std::string &filepath);
|
||||
|
||||
protected:
|
||||
BasicFileSink();
|
||||
|
||||
private:
|
||||
std::string filepath_;
|
||||
std::ofstream ofs_;
|
||||
|
@ -9,19 +9,23 @@ ConsoleSink::Ptr ConsoleSink::Create() {
|
||||
|
||||
ConsoleSink::~ConsoleSink() {}
|
||||
|
||||
void ConsoleSink::send(LogSeverity severity, const char *full_filename,
|
||||
void ConsoleSink::Send(LogSeverity severity, const char *full_filename,
|
||||
const char *base_filename, int line,
|
||||
const LogMessageTime &logmsgtime, const char *message,
|
||||
size_t message_len) {
|
||||
auto msg = ToString(severity, full_filename, base_filename, line, logmsgtime,
|
||||
message, message_len);
|
||||
while (!msg.empty() && msg.back() == '\n') {
|
||||
msg.pop_back();
|
||||
}
|
||||
if (severity >= TILE_FATAL) {
|
||||
fprintf(stderr, "%s\n", msg.c_str());
|
||||
} else {
|
||||
fprintf(stdout, "%s\n", msg.c_str());
|
||||
}
|
||||
msg.pop_back();
|
||||
fprintf(stdout, "%s\n", msg.c_str());
|
||||
}
|
||||
|
||||
void ConsoleSink::WaitTillSent() {}
|
||||
void ConsoleSink::Flush() {}
|
||||
|
||||
ConsoleSink::ConsoleSink() {}
|
||||
|
||||
|
@ -11,11 +11,11 @@ public:
|
||||
static Ptr Create();
|
||||
|
||||
~ConsoleSink() override;
|
||||
void send(LogSeverity severity, const char *full_filename,
|
||||
void Send(LogSeverity severity, const char *full_filename,
|
||||
const char *base_filename, int line,
|
||||
const LogMessageTime &logmsgtime, const char *message,
|
||||
size_t message_len) override;
|
||||
void WaitTillSent() override;
|
||||
void Flush() override;
|
||||
|
||||
protected:
|
||||
ConsoleSink();
|
||||
|
@ -6,20 +6,20 @@ class SimpleSink : public LogSink {
|
||||
public:
|
||||
using Ptr = std::shared_ptr<SimpleSink>;
|
||||
static Ptr Create() { return std::shared_ptr<SimpleSink>(new SimpleSink()); }
|
||||
void send(LogSeverity severity, const char *full_filename,
|
||||
void Send(LogSeverity severity, const char *full_filename,
|
||||
const char *base_filename, int line,
|
||||
const LogMessageTime &logmsgtime, const char *message,
|
||||
size_t message_len) override {
|
||||
message_ = std::string(message, message_len);
|
||||
}
|
||||
void WaitTillSent() override {}
|
||||
void Flush() override {}
|
||||
std::string message_;
|
||||
};
|
||||
|
||||
TEST(SplitterSink, One) {
|
||||
auto sink = SimpleSink::Create();
|
||||
auto splitter = SplitterSink::Create({sink});
|
||||
splitter->send(LogSeverity::TILE_INFO, nullptr, nullptr, 0, LogMessageTime(),
|
||||
splitter->Send(LogSeverity::TILE_INFO, nullptr, nullptr, 0, LogMessageTime(),
|
||||
"message", 7);
|
||||
ASSERT_EQ(sink->message_, "message");
|
||||
}
|
||||
@ -28,7 +28,7 @@ TEST(SplitterSink, Two) {
|
||||
auto sink1 = SimpleSink::Create();
|
||||
auto sink2 = SimpleSink::Create();
|
||||
auto splitter = SplitterSink::Create({sink1, sink2});
|
||||
splitter->send(LogSeverity::TILE_INFO, nullptr, nullptr, 0, LogMessageTime(),
|
||||
splitter->Send(LogSeverity::TILE_INFO, nullptr, nullptr, 0, LogMessageTime(),
|
||||
"message", 7);
|
||||
ASSERT_EQ(sink1->message_, "message");
|
||||
ASSERT_EQ(sink2->message_, "message");
|
||||
@ -44,7 +44,7 @@ TEST(SplitterSink, Multi) {
|
||||
std::stringstream ss;
|
||||
ss << "message" << i;
|
||||
auto msg = ss.str();
|
||||
splitter->send(LogSeverity::TILE_INFO, nullptr, nullptr, 0,
|
||||
splitter->Send(LogSeverity::TILE_INFO, nullptr, nullptr, 0,
|
||||
LogMessageTime(), msg.data(), msg.size());
|
||||
|
||||
for (auto &sink : splitter->sinks()) {
|
||||
|
Loading…
Reference in New Issue
Block a user