Skip to content

Commit

Permalink
Fixed bug where indentation got messed up if not writing a \n at end …
Browse files Browse the repository at this point in the history
…of every message
azonenberg committed Oct 24, 2016
1 parent d03242e commit cdfa8be
Showing 4 changed files with 31 additions and 1 deletion.
12 changes: 12 additions & 0 deletions FILELogSink.cpp
Original file line number Diff line number Diff line change
@@ -57,6 +57,12 @@ void FILELogSink::Log(Severity severity, const std::string &msg)
//Wrap/print it
string wrapped = WrapString(msg);
fputs(wrapped.c_str(), m_file);

//See if we printed a \n
if(wrapped.length() && (wrapped[wrapped.length() - 1] == '\n'))
m_lastMessageWasNewline = true;
else if(wrapped != "")
m_lastMessageWasNewline = false;
}

void FILELogSink::Log(Severity severity, const char *format, va_list va)
@@ -67,4 +73,10 @@ void FILELogSink::Log(Severity severity, const char *format, va_list va)
//Wrap/print it
string wrapped = WrapString(vstrprintf(format, va));
fputs(wrapped.c_str(), m_file);

//See if we printed a \n
if(wrapped.length() && (wrapped[wrapped.length() - 1] == '\n'))
m_lastMessageWasNewline = true;
else if(wrapped != "")
m_lastMessageWasNewline = false;
}
12 changes: 12 additions & 0 deletions STDLogSink.cpp
Original file line number Diff line number Diff line change
@@ -79,6 +79,12 @@ void STDLogSink::Log(Severity severity, const string &msg)
//Ensure that this message is displayed immediately even if we print lower severity stuff later
if(severity <= Severity::WARNING)
Flush();

//See if we printed a \n
if(wrapped.length() && (wrapped[wrapped.length() - 1] == '\n'))
m_lastMessageWasNewline = true;
else if(wrapped != "")
m_lastMessageWasNewline = false;
}

void STDLogSink::Log(Severity severity, const char *format, va_list va)
@@ -101,4 +107,10 @@ void STDLogSink::Log(Severity severity, const char *format, va_list va)
//Ensure that this message is displayed immediately even if we print lower severity stuff later
if(severity <= Severity::WARNING)
Flush();

//See if we printed a \n
if(wrapped.length() && (wrapped[wrapped.length() - 1] == '\n'))
m_lastMessageWasNewline = true;
else if(wrapped != "")
m_lastMessageWasNewline = false;
}
4 changes: 3 additions & 1 deletion log.cpp
Original file line number Diff line number Diff line change
@@ -72,7 +72,9 @@ string LogSink::WrapString(string str)
string indent = GetIndentString();

//Split the string into lines
string tmp = indent;
string tmp;
if(m_lastMessageWasNewline)
tmp = indent;
for(size_t i=0; i<str.length(); i++)
{
//Append it
4 changes: 4 additions & 0 deletions log.h
Original file line number Diff line number Diff line change
@@ -53,6 +53,7 @@ class LogSink
: m_indentSize(4)
, m_indentLevel(0)
, m_termWidth(120) //default if not using ioctls to check
, m_lastMessageWasNewline(true)
{}

virtual ~LogSink() {}
@@ -100,6 +101,9 @@ class LogSink

/// @brief Width of the console we're printing to
unsigned int m_termWidth;

/// @brief True if the last message ended in a \n character
bool m_lastMessageWasNewline;
};

/**

0 comments on commit cdfa8be

Please sign in to comment.