mirror of
https://github.com/KjellKod/g3log.git
synced 2025-02-24 07:21:30 +01:00
Some test_io FATAL unit tests were memory sensitive. Added robustness by making the fatal exit message static
This commit is contained in:
parent
afb55095ce
commit
0931a611ed
@ -12,6 +12,8 @@
|
||||
|
||||
namespace g2 {
|
||||
using namespace internal;
|
||||
|
||||
|
||||
FileSink::FileSink(const std::string& log_prefix, const std::string& log_directory)
|
||||
: _log_file_with_path(log_directory)
|
||||
, _log_prefix_backup(log_prefix)
|
||||
@ -35,6 +37,8 @@ FileSink::FileSink(const std::string& log_prefix, const std::string& log_directo
|
||||
assert(_outptr && "cannot open log file at startup");
|
||||
addLogFileHeader();
|
||||
}
|
||||
|
||||
|
||||
FileSink::~FileSink() {
|
||||
std::string exit_msg{"\ng2log g2FileSink shutdown at: "};
|
||||
exit_msg.append(localtime_formatted(systemtime_now(), internal::time_formatted));
|
||||
@ -43,6 +47,8 @@ FileSink::~FileSink() {
|
||||
exit_msg.append({"\nLog file at: ["}).append(_log_file_with_path).append({"]\n\n"});
|
||||
std::cerr << exit_msg << std::flush;
|
||||
}
|
||||
|
||||
// The actual log receiving function
|
||||
void FileSink::fileWrite(LogMessageMover message) {
|
||||
std::ofstream& out(filestream());
|
||||
out << message.get().toString();
|
||||
|
@ -60,15 +60,17 @@ namespace g2 {
|
||||
// Not crash scenario but LOG or CONTRACT
|
||||
auto level_value = _level.value;
|
||||
if (FATAL.value == level_value) {
|
||||
out.append("\n\t*******\tEXIT trigger caused by LOG(FATAL) entry: \n\t"
|
||||
+ '"' + message() + '"');
|
||||
static const std::string fatalExitReason = {"EXIT trigger caused by LOG(FATAL) entry: "};
|
||||
out.append("\n\t*******\t " + fatalExitReason + "\n\t" + '"' + message() + '"');
|
||||
} else if (internal::CONTRACT.value == level_value) {
|
||||
out.append("\n\t *******\tEXIT trigger caused by broken Contract: CHECK(" + _expression + ")\n\t"
|
||||
static const std::string contractExitReason = {"EXIT trigger caused by broken Contract:"};
|
||||
out.append("\n\t*******\t " + contractExitReason + " CHECK(" + _expression + ")\n\t"
|
||||
+ '"' + message() + '"');
|
||||
} else {
|
||||
out.append("\n\t*******\tUNKNOWN Log Message Type\n" + '"' + message() + '"');
|
||||
static const std::string errorUnknown = {"UNKNOWN Log Message Type"};
|
||||
out.append("\n\t*******" + errorUnknown + "\t\n" + '"' + message() + '"');
|
||||
}
|
||||
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ namespace testing_helpers {
|
||||
}
|
||||
|
||||
RestoreFileLogger::~RestoreFileLogger() {
|
||||
g2::internal::shutDownLogging();
|
||||
g2::internal::shutDownLogging(); // is done at reset. Added for test clarity
|
||||
reset();
|
||||
|
||||
if (!removeFile(_log_file))
|
||||
|
Loading…
x
Reference in New Issue
Block a user