Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix copy constructor of the logger #266

Merged
merged 2 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/common/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,31 @@ LoggerBuffer::LoggerBuffer(std::size_t bufferSize)
setFileEnabled(false);
}

/*!
Copy constructor.

\param other is another logger buffer, whose contents will be used to
initialize the current logger buffer
*/
LoggerBuffer::LoggerBuffer(const LoggerBuffer &other)
: std::streambuf(),
m_buffer(other.m_buffer),
m_context(other.m_context),
m_padding(other.m_padding),
m_consoleEnabled(other.m_consoleEnabled),
m_consoleTimestampEnabled(other.m_consoleTimestampEnabled),
m_console(other.m_console),
m_consolePrefix(other.m_consolePrefix),
m_fileEnabled(other.m_fileEnabled),
m_fileTimestampEnabled(other.m_fileTimestampEnabled),
m_file(other.m_file),
m_filePrefix(other.m_filePrefix)
{
// Set the buffer
char *bufferBegin = &m_buffer.front();
setp(bufferBegin, bufferBegin + m_buffer.size() - 1);
}

/*!
Destructor
*/
Expand Down Expand Up @@ -492,6 +517,11 @@ Logger::Logger(const Logger &other)
m_fileDisabledThreshold(other.m_fileDisabledThreshold),
m_fileVerbosityThreshold(other.m_fileVerbosityThreshold)
{
// Copy buffer properties
copyfmt(other);
exceptions(other.exceptions());
clear(other.rdstate());
basic_ios<char>::rdbuf(other.rdbuf());
}

/*!
Expand Down
1 change: 1 addition & 0 deletions src/common/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class LoggerBuffer : public std::streambuf

public:
LoggerBuffer(std::size_t bufferSize = 256);
LoggerBuffer(LoggerBuffer const &other);
~LoggerBuffer();

bool isConsoleTimestampEnabled() const;
Expand Down