This seems to be one of the most reported issues, as it makes it a lot
harder to safely escape strings.
This option is very much an edge case, and it's causing too much issues
compared to what it provide.
- Related issues: https://github.com/sirupsen/logrus/issues/457
- miniTS use current time instead of time the log function is called,
which is inaccurate when hook takes a long time
- `miniTS` is removed and replaced by
`int(entry.Time.Sub(baseTimestamp)/time.Second)` in `printColored`
which is the only usage of `miniTS`
There are two different code paths for rendering a key/value pair. The
non-color version uses a type switch that handles specific types such as
"error", and the color version uses the %+v printf format specifier.
This causes an inconsistency between the two formats. In particular,
errors created using the github.com/pkg/errors package will include a
stack trace of where the error was created when printed to the terminal,
but not to a file. Printing the stack trace as part of the log field is
probably not the right behavior.
The output is also inconsistent between the two forms because strings
are not quoted/escaped when colors are used. This can make log output
unparseable.
Fix this by making both code paths use the type switch and escaping
rules. Fix the escaping code to pass the error value to Fprintf, not the
error itself, which seems to be necessary to avoid blank output with
errors created by github.com/pkg/errors.
This changed printColored and printKeyValue to print in same way
with prefix space instead of trailing space, to make it easier
to slice out when returning in Format;
The test cases are to make sure msg formartting doesn't include
leading or trailing spaces;
Closes#99
Signed-off-by: Derek Che <drc@yahoo-inc.com>
printKeyValue is working similar like printColored, not using
any fields of TextFormatter, should be a util func instead of
a method of TextFormatter.
Signed-off-by: Derek Che <drc@yahoo-inc.com>
It's not necessary to enclose in quotes every single string value
in log2met format; when using basic words, it's possible to not
quote it (as heroku does for its own logging). This keeps the
logs easier on the human eye.