Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

formatting logs for structured data #70

Closed
wants to merge 7 commits into from
Closed

Conversation

sonjakhan
Copy link
Contributor

If the state of a log message is an ILoggerStructure, the console logger will display the result of GetValues, one KeyValuePair per line. It does this recursively for cases where the Value is an ILoggerStructure or an IEnumerable<ILoggerStructure>

consolestructuredoutput

@sonjakhan
Copy link
Contributor Author

@davidfowl @loudej @Tratcher

foreach (var kvp in values)
{
builder.Append("\r\n");
for (var i = 0; i < level; i++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

builder.Append(new string('\t', level))?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about this method, I like it 👍

foreach (var kvp in values)
{
builder.Append("\r\n");
builder.Append('\t', level);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs might be overkill, especially if you end up with a deeply nested object. How does it look with just two or three spaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow I didn't realize the default tab was like 8 spaces. That's insane!

@sonjakhan
Copy link
Contributor Author

@Tratcher this is what it looks like with 3 spaces
consolestructuredoutput2


namespace Microsoft.Framework.Logging.Console
{
public class ConsoleLogger : ILogger
{
private const int _indentation = 3;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat nitpicky, but 3 is such an odd number (literally!). 2 or 4 are more common indentation levels...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 is nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✌️ ❓

if (formatter != null)
if (state is ILoggerStructure)
{
var builder = FormatLoggerStructure(new StringBuilder(), (ILoggerStructure)state, 1, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

named parameters

@sonjakhan
Copy link
Contributor Author

@Tratcher @Eilon with bullets and indentation of 2 spaces
consolestructuredoutput3

{
if (value is ILoggerStructure)
{
builder = FormatLoggerStructure(builder, (ILoggerStructure)value, level + 1, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

named parameter for true

@NTaylorMullen
Copy link
Member

Just glazed over it, don't wait on me for anything though 😄

@@ -98,5 +111,60 @@ public IDisposable BeginScope(object state)
{
return null;
}

private StringBuilder FormatLoggerStructure(StringBuilder builder, ILoggerStructure structure, int level, bool bullet)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatted in person. This doesn't need to return the StringBuilder because it's always the same instance. Just pass it around as a parameter.

{
var builder = new StringBuilder();
FormatLoggerStructure(
builder: builder,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to provide a named parameter for the builder or state since their names state their purpose. General rule: If you can't decipher what a parameter to a method is, provide a named parameter. So things like true, 1234 etc. are just values with no information and don't inform the reader of anything. Same comment for other instances in this file.

@Eilon
Copy link
Member

Eilon commented Nov 25, 2014

:shipit: after @NTaylorMullen 's comments.

@sonjakhan sonjakhan closed this Nov 25, 2014
@sonjakhan sonjakhan deleted the console-structure branch December 12, 2014 19:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants