Skip to content

Commit

Permalink
corrected initializing list format
Browse files Browse the repository at this point in the history
  • Loading branch information
KjellKod committed Nov 30, 2023
1 parent d95dd8f commit 645e486
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 15 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
PackConstructorInitializers: Never
BreakBeforeBraces: Attach
BraceWrapping:
AfterCaseLabel: false
Expand Down
9 changes: 8 additions & 1 deletion src/filesink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ namespace g3 {
using namespace internal;

FileSink::FileSink(const std::string& log_prefix, const std::string& log_directory, const std::string& logger_id, size_t write_to_log_every_x_message) :
_log_details_func(&LogMessage::DefaultLogDetailsToString), _log_file_with_path(log_directory), _log_prefix_backup(log_prefix), _outptr(new std::ofstream), _header("\t\tLOG format: [YYYY/MM/DD hh:mm:ss uuu* LEVEL FILE->FUNCTION:LINE] message\n\n\t\t(uuu*: microseconds fractions of the seconds value)\n\n"), _firstEntry(true), _write_counter(0), _write_to_log_every_x_message(write_to_log_every_x_message) {
_log_details_func(&LogMessage::DefaultLogDetailsToString),
_log_file_with_path(log_directory),
_log_prefix_backup(log_prefix),
_outptr(new std::ofstream),
_header("\t\tLOG format: [YYYY/MM/DD hh:mm:ss uuu* LEVEL FILE->FUNCTION:LINE] message\n\n\t\t(uuu*: microseconds fractions of the seconds value)\n\n"),
_firstEntry(true),
_write_counter(0),
_write_to_log_every_x_message(write_to_log_every_x_message) {
_log_prefix_backup = prefixSanityFix(log_prefix);
if (!isValidFilename(_log_prefix_backup)) {
std::cerr << "g3log: forced abort due to illegal log prefix [" << log_prefix << "]" << std::endl;
Expand Down
18 changes: 12 additions & 6 deletions src/g3log/loglevels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ struct LEVELS {
// "dynamic, runtime loading of shared libraries"

LEVELS(const LEVELS& other) :
value(other.value), text(other.text.c_str()) {}
value(other.value),
text(other.text.c_str()) {}

LEVELS(int id, const std::string& idtext) :
value(id), text(idtext) {}
value(id),
text(idtext) {}

bool operator==(const LEVELS& rhs) const {
return (value == rhs.value && text == rhs.text);
Expand Down Expand Up @@ -104,13 +106,17 @@ namespace g3 {

// default operator needed for std::map compliance
LoggingLevel() :
status(false), level(INFO){};
status(false),
level(INFO){};
LoggingLevel(const LoggingLevel& lvl) :
status(lvl.status), level(lvl.level) {}
status(lvl.status),
level(lvl.level) {}
LoggingLevel(const LEVELS& lvl) :
status(true), level(lvl){};
status(true),
level(lvl){};
LoggingLevel(const LEVELS& lvl, bool enabled) :
status(enabled), level(lvl){};
status(enabled),
level(lvl){};
~LoggingLevel() = default;

LoggingLevel& operator=(const LoggingLevel& other) {
Expand Down
7 changes: 6 additions & 1 deletion src/logcapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ LogCapture::LogCapture(const LEVELS& level, g3::SignalType fatal_signal, const c
*/
LogCapture::LogCapture(const char* file, const int line, const char* function, const LEVELS& level,
const char* expression, g3::SignalType fatal_signal, const char* dump) :
_file(file), _line(line), _function(function), _level(level), _expression(expression), _fatal_signal(fatal_signal) {
_file(file),
_line(line),
_function(function),
_level(level),
_expression(expression),
_fatal_signal(fatal_signal) {

if (g3::internal::wasFatal(level)) {
_stack_trace = std::string{"\n*******\tSTACKDUMP *******\n"};
Expand Down
32 changes: 27 additions & 5 deletions src/logmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ namespace g3 {

LogMessage::LogMessage(std::string file, const int line,
std::string function, const LEVELS level) :
_logDetailsToStringFunc(LogMessage::DefaultLogDetailsToString), _timestamp(std::chrono::high_resolution_clock::now()), _call_thread_id(std::this_thread::get_id())
_logDetailsToStringFunc(LogMessage::DefaultLogDetailsToString),
_timestamp(std::chrono::high_resolution_clock::now()),
_call_thread_id(std::this_thread::get_id())
#if defined(G3_LOG_FULL_FILENAME)
,
_file(file)
Expand All @@ -141,11 +143,29 @@ namespace g3 {
}

LogMessage::LogMessage(const LogMessage& other) :
_logDetailsToStringFunc(other._logDetailsToStringFunc), _timestamp(other._timestamp), _call_thread_id(other._call_thread_id), _file(other._file), _file_path(other._file_path), _line(other._line), _function(other._function), _level(other._level), _expression(other._expression), _message(other._message) {
_logDetailsToStringFunc(other._logDetailsToStringFunc),
_timestamp(other._timestamp),
_call_thread_id(other._call_thread_id),
_file(other._file),
_file_path(other._file_path),
_line(other._line),
_function(other._function),
_level(other._level),
_expression(other._expression),
_message(other._message) {
}

LogMessage::LogMessage(LogMessage&& other) :
_logDetailsToStringFunc(other._logDetailsToStringFunc), _timestamp(other._timestamp), _call_thread_id(other._call_thread_id), _file(std::move(other._file)), _file_path(std::move(other._file_path)), _line(other._line), _function(std::move(other._function)), _level(other._level), _expression(std::move(other._expression)), _message(std::move(other._message)) {
_logDetailsToStringFunc(other._logDetailsToStringFunc),
_timestamp(other._timestamp),
_call_thread_id(other._call_thread_id),
_file(std::move(other._file)),
_file_path(std::move(other._file_path)),
_line(other._line),
_function(std::move(other._function)),
_level(other._level),
_expression(std::move(other._expression)),
_message(std::move(other._message)) {
}

std::string LogMessage::threadID() const {
Expand All @@ -155,10 +175,12 @@ namespace g3 {
}

FatalMessage::FatalMessage(const LogMessage& details, g3::SignalType signal_id) :
LogMessage(details), _signal_id(signal_id) {}
LogMessage(details),
_signal_id(signal_id) {}

FatalMessage::FatalMessage(const FatalMessage& other) :
LogMessage(other), _signal_id(other._signal_id) {}
LogMessage(other),
_signal_id(other._signal_id) {}

LogMessage FatalMessage::copyToLogMessage() const {
return LogMessage(*this);
Expand Down
3 changes: 2 additions & 1 deletion test_unit/test_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,8 @@ TEST(CHECK, CHECK_runtimeError) {

public:
explicit dynamic_int_array(int size) :
data_{std::make_unique<int[]>(size)}, size_(size) {}
data_{std::make_unique<int[]>(size)},
size_(size) {}

int& at(int i) {
CHECK(i < size_);
Expand Down
3 changes: 2 additions & 1 deletion test_unit/testing_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ namespace testing_helpers {
}

RestoreFileLogger::RestoreFileLogger(std::string directory) :
_scope(new ScopedLogger), _handle(_scope->get()->addSink(std::make_unique<g3::FileSink>("UNIT_TEST_LOGGER", directory, "g3log", kFlushToDiskWithThisInterval), &g3::FileSink::fileWrite)) {
_scope(new ScopedLogger),
_handle(_scope->get()->addSink(std::make_unique<g3::FileSink>("UNIT_TEST_LOGGER", directory, "g3log", kFlushToDiskWithThisInterval), &g3::FileSink::fileWrite)) {
using namespace g3;
g3::initializeLogging(_scope->_currentWorker.get());
clearMockFatal();
Expand Down

0 comments on commit 645e486

Please sign in to comment.