Commit Graph

73 Commits

Author SHA1 Message Date
dmathieu 325575f181 fix golint issues in formatters 2017-07-26 14:26:30 +02:00
dmathieu 211aba39c8 use buffer length to avoid generating strings every time 2017-07-25 09:39:35 +02:00
dmathieu 159e991025 only add a space between text entries if there is already content
So we don't have a trailing space at the end of each log line
2017-07-21 16:14:28 +02:00
dmathieu 2727ac94b0 remove QuoteCharacter option
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.
2017-07-13 13:46:35 +02:00
Paul Seiffert b019ab48c5
Error is not a special case anymore 2017-07-12 17:54:01 +02:00
Paul Seiffert 4c4851c96a
Reduce duplicate code 2017-07-12 17:16:13 +02:00
Paul Seiffert b9cfd82645
Quote non-string values if necessary 2017-07-12 17:15:13 +02:00
Damien Mathieu 6f87387fae Merge pull request #563 from meatballhat/unquote-more-chars
Allow more chars in unquoted text formatter output
2017-07-12 13:55:30 +02:00
Damien Mathieu 398dd088c2 Merge pull request #399 from pkieltyka/master
TextFormatter: brighten up the blue
2017-07-12 13:42:20 +02:00
Paul Seiffert 0025402362
Extract quoting into separate method 2017-07-10 14:18:45 +02:00
Paul Seiffert 0383f49850
Use custom quote char and escape it 2017-07-10 14:09:37 +02:00
kpcyrd f78f8d07f6
Safely format data when printing
Fixes #531
2017-07-10 13:12:47 +02:00
Dan Buch 5d67428857
Allow more chars in unquoted text formatter output 2017-06-18 09:48:52 -04:00
Ben Brooks e98cd92ccf
Address PR comments 2017-02-15 13:08:26 +00:00
Ben Brooks b545aee819
Add TextFormatter config for custom quote runes 2017-02-14 11:51:23 +00:00
Ben Brooks cfca98e6d9
Add 'QuoteEmptyFields' option to TextFormatter 2017-02-14 10:53:03 +00:00
Simon Eskildsen 11fbf0fa42 text_formatter: fix race 2017-02-06 19:16:49 -05:00
Simon Eskildsen 1726e1744a text_formatter: detect tty based on fd 2017-02-06 19:16:49 -05:00
Stephen Day 61e43dc76f Merge pull request #467 from bengadbois/small_code_cleanup
Small var declaration cleanup
2017-01-12 17:19:11 -08:00
Ben Gadbois f761cee910 Small var declaration cleanup 2017-01-11 19:19:12 +01:00
at15 5ed3e7dc93
Remove miniTS in TextFormatter
- 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`
2017-01-10 21:43:36 -08:00
Stephen Day 9b48ece7fc Merge pull request #400 from carolynvs/disable-color-timestamp
Allow disabling timestamps with colored output
2017-01-06 14:16:01 -08:00
Aaron Lehmann f76d643702 Fix formatting of wrapped errors when colors are used
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.
2016-09-28 13:48:28 +01:00
Carolyn Van Slyck 98b74aac5b Allow disabling timestamps with colored output 2016-08-24 17:24:54 -05:00
Peter Kieltyka b97e8d402d TextFormatter: brighten up the blue 2016-08-23 13:23:35 -04:00
plan 69df0d2ed7 Use Buffer pool to allocate bytes.Buffer for formatter
Entry.Reader() seams not necessary, removed
2016-08-11 01:35:34 +08:00
Antoine Grondin 754bfa9e83 match name to semantic in `needsQuoting`
fixes #196
2016-04-16 13:48:56 +05:30
Edward Muller 9ca7d9fefe Don't emit a msg if there is none to emit 2015-09-08 14:21:17 -07:00
Peng Zhai a8127fd485 Change printColored to use timestampFormat. 2015-07-20 10:43:12 -07:00
Peng Zhai 570db1b0b9 Fix data race issue in TextFormatter. Fix for https://github.com/Sirupsen/logrus/issues/217. 2015-07-16 21:02:46 -04:00
Peter Fern 62bd221be1 Print struct keys for struct log fields
Can be useful for debugging, saves a lot of referring to source code
2015-07-05 17:08:19 +10:00
Anton Tiurin e35e0e00b8 [TextFormatter] Speed up. Fprintf is changed to buffer.Write*
As Fprintf is slower than buffer.WriteString, it's replaced
to faster call.

Signed-off-by: Anton Tiurin <noxiouz@yandex.ru>
2015-06-28 12:36:14 +03:00
Alexander F Rødseth 29d30d9f63 Terminals on Windows may not have colors 2015-05-12 16:31:17 +02:00
Stephen J Day e14471f8f2 Allow configuration of timestamp layout
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2015-04-06 12:18:40 -07:00
Tiffany Low 3e3e87a165 allow custom time format string in TextFormatter
- fixes examples in README.md that incorrectly state usage of
  RFC3339Nano format instead of RFC3339
2015-03-26 16:15:06 -07:00
Simon Eskildsen 7495181ab1 text_formatter: remove unneeded regexp 2015-03-19 09:59:55 -04:00
Simon Eskildsen bbf1b22f08 Merge pull request #131 from lvillani/debuglevel-gray
Change DebugLevel color to gray
2015-03-09 11:39:16 -04:00
Simon Eskildsen 538395b333 text_formatter: add field to disable sorting 2015-03-09 15:19:51 +00:00
Simon Eskildsen a020ac2471 Merge pull request #143 from henrikhodne/do-not-quote-9
Text formatter: Do not quote 9
2015-03-04 10:45:58 -05:00
Henrik Hodne cd4266df0e text-formatter: do not quote 9 2015-03-04 14:04:50 +00:00
Simon Eskildsen c0f7e35ed2 text_formatter: improve comments 2015-02-25 19:01:02 +00:00
Steeve Lennmark ccaf6983d9 Add option to show full timestamp in TextFormatter
Sometimes elapsed seconds just aren't enough.
2015-02-20 18:43:24 +02:00
Lorenzo Villani 4fbdf5948e Change DebugLevel color to gray 2015-02-20 16:32:47 +01:00
Anton Tiurin d1dfe8db73 [TextFormatter] Preallocate enough memory for keys to speedup.
Benchmarks:
 * BenchmarkSmallTextFormatter: 6140/5943 ~3%
 * BenchmarkLargeTextFormatter: 28050/24789 ~11%

Signed-off-by: Anton Tiurin <noxiouz@yandex.ru>
2015-02-17 19:08:32 +03:00
Simon Eskildsen 58f778a886 Revert "Merge pull request #100 from crquan/patch-1"
This reverts commit c6a969a0de, reversing
changes made to 3c5b048a9d.
2015-01-15 13:40:48 -05:00
Derek Che dcbe8d66af make sure no leading or trailing spaces
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>
2015-01-04 00:19:36 -08:00
Derek Che a243bbaa0b share common calling path in printKeyValue
Signed-off-by: Derek Che <drc@yahoo-inc.com>
2015-01-04 00:01:49 -08:00
Derek Che 03377c6168 rename f.appendKeyValue to printKeyValue
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>
2015-01-03 23:56:39 -08:00
Simon Eskildsen 51fe59aca1 Merge pull request #92 from rasky/no-extra-quoting
Avoid extra quotes where not strictly necessary.
2014-12-18 10:52:14 -05:00
Giovanni Bajo 15b296befc Avoid using regexp 2014-12-18 15:09:01 +01:00