Skip to content

Commit

Permalink
libcore|Log: Improved monospaced log entry formatting
Browse files Browse the repository at this point in the history
Prefer to align consecutive entries with whitespace for improved
readability.
  • Loading branch information
skyjake committed Dec 18, 2015
1 parent 52649ee commit 7e6c7a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 8 additions & 4 deletions doomsday/sdk/libcore/src/core/log.cpp
Expand Up @@ -38,7 +38,7 @@ char const *MAIN_SECTION = "";

/// If the section is longer than this, it will be alone on one line while
/// the rest of the entry continues after a break.
static int const LINE_BREAKING_SECTION_LENGTH = 35;
static int const LINE_BREAKING_SECTION_LENGTH = 30;

namespace internal {

Expand Down Expand Up @@ -475,13 +475,17 @@ String LogEntry::asText(Flags const &formattingFlags, int shortenSection) const

if(flags.testFlag(SectionSameAsBefore))
{
if(!shortenSection || sect.isEmpty())
int visibleSectLen = (!sect.isEmpty() && shortenSection? sect.size() : 0);
int fillLen = de::max(shortenSection, _section.size()) - visibleSectLen;
if(fillLen > LINE_BREAKING_SECTION_LENGTH) fillLen = 2;
output << String(fillLen, QChar(' '));
if(visibleSectLen)
{
output << "^ : ";
output << sect << ": ";
}
else
{
output << "^" << sect << ": ";
output << " ";
}
}
else
Expand Down
12 changes: 7 additions & 5 deletions doomsday/sdk/libcore/src/core/monospacelogsinkformatter.cpp
Expand Up @@ -13,7 +13,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/MonospaceLogSinkFormatter"
Expand Down Expand Up @@ -225,11 +225,11 @@ nextStop:;
};

MonospaceLogSinkFormatter::MonospaceLogSinkFormatter()
: _maxLength(89), _minimumIndent(0), _sectionDepthOfPreviousLine(0)
: _maxLength(100), _minimumIndent(0), _sectionDepthOfPreviousLine(0)
{
#ifdef DENG2_DEBUG
// Debug builds include a timestamp and msg type indicator.
_maxLength = 110;
_maxLength = 130;
_minimumIndent = 21;
#endif
}
Expand Down Expand Up @@ -354,10 +354,12 @@ QList<String> MonospaceLogSinkFormatter::logEntryToTextLines(LogEntry const &ent

// Indent to colons automatically (but not too deeply).
if(lineText[w] == ':' && w < lineText.size() - 1 && lineText[w + 1].isSpace())
firstNonSpace = (w < int(_maxLength)*2/3? -1 : _minimumIndent);
{
firstNonSpace = (w < _minimumIndent + 30? -1 : _minimumIndent);
}
}

nextWrapIndent = qMax(_minimumIndent, firstNonSpace);
nextWrapIndent = qMax(_minimumIndent + 4, firstNonSpace);
}

// Check for formatting symbols.
Expand Down

0 comments on commit 7e6c7a8

Please sign in to comment.