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

Breaking out msg/time/level #33

Closed
wants to merge 2 commits into from
Closed

Conversation

rnapier
Copy link
Contributor

@rnapier rnapier commented May 27, 2014

The first commit (fe381bf) just adds some text_formatter unit tests.

7679f44 changes Entry to the structure I discuss in #29 and #30. It removes msg, time, and level from the Data map and makes them first-class Entry fields. This moves the mapping of level to string entirely into the formatters.

This modifies the default JSON format, causing it to encapsulate additional fields in a data sub-object. I believe this is a better JSON format because it doesn't have any magical fields. But it is trivial to implement the previous "flat" JSON in a formatter. Just copy the data map into a new map and merge-in the three magical fields, and marshal that. I'm happy to write a FlatJSONFormatter if you think it's useful to anyone.

I also changed the JSON encoding of Warn to "warn" rather than "warning" for consistency. That's trivially reverted in json_formatter.

I've added Unformat() methods on the formatters to assist in testing. I haven't added that as part of the Formatter interface, however. Unformat() may be very inconvenient to write for some formats, and I don't know if it's worth making it mandatory. It's probably worth adding an explicit Unformatter interface.

I haven't finished the text unformatter yet; I only handle the colorized case. Testing the other case is a bit of a headache currently because of how it checks for the terminal. It is probably worth reworking ForceColor to an enum (color/plain/auto). The whole auto-detect has a lot of tricky corner cases, anyway. If the log output isn't stdout, then it's not clear what to check. Personally, I'd like color/non-color to be split into separate formatters and let the caller work out what they want.

I'd also recommend that the formatters be moved into sub-packages like the hooks. There's no reason to build all the formatters (and their dependencies, like the JSON encoder) when you're likely to only use one of them. I have a custom formatter package, and don't use any of these. I can make that change if it's acceptable.

@sirupsen
Copy link
Owner

Thanks for your PR! I'll try to take a look this week.

jsonEntry.Level = "fatal"
case Panic:
jsonEntry.Level = "panic"
}
Copy link
Owner

Choose a reason for hiding this comment

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

What about making this a method on the Level?

Copy link
Owner

Choose a reason for hiding this comment

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

This one makes sense as a method on Level. The one for TextFormatter, not so much.

@sirupsen
Copy link
Owner

sirupsen commented Jun 9, 2014

I like this a lot more.

@sirupsen
Copy link
Owner

sirupsen commented Jun 9, 2014

Can you check out the tests?

jsonEntry := jsonEntry{
Time: entry.Time,
Msg: entry.Msg,
Data: entry.Data,
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure what I think about this as a default. Nested hashes aren't the greatest. I get where you're coming from though, since there's no way nice to have this work with keys with the same name.

@eapache eapache mentioned this pull request Jun 10, 2014
@sirupsen
Copy link
Owner

bump

@aybabtme
Copy link
Collaborator

An alternative is to serialize all the keys at the same level (not nested), but prefix all user supplied keys to avoid name collisions.

This would solve the problem of fields being silently overwritten.

@sirupsen
Copy link
Owner

@aybabtme not a fan of that, it breaks convenience of splunking etc.

@aybabtme
Copy link
Collaborator

I'm opening #44 to discuss solutions to this problem.

@sirupsen
Copy link
Owner

Closing in favor of #48.

@sirupsen sirupsen closed this Jul 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants