Commit Graph

116 Commits

Author SHA1 Message Date
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
Dave Clendenan bc6d984670 add caller logic to DisableTimestamp case 2017-02-03 15:08:53 -08:00
Dave Clendenan 41d9b87f18 Merge branch 'master' of https://github.com/sirupsen/logrus
Conflicts:
	text_formatter.go
2017-02-03 14:56:03 -08:00
Tony Lee 31c0a5e6d9 Merge github.com/sirupsen/logrus into github.com/roganartu/logrus 2017-01-24 22:52:54 +11: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
Dave Clendenan 88dd8df1f8 responses to code review
- field rename to be more properly generic
 - drop rewrite of main.main
2016-12-06 12:53:21 -08:00
Dave Clendenan 65f3af38f7 simplify hasCaller check 2016-11-30 15:15:38 -08:00
Dave Clendenan a5c845c224 responses to review comments
- empty string as marker for failure to discover calling function
 - tighten up logger usage - don't rely on std logger internally

Also fix ordering of expected/got in logrus_test.go to ensure correct
output form test failures.
2016-11-30 14:07:10 -08:00
Dave Clendenan 348bace269 doc updates, and relabel ReportMethod
in the Logrus context it's the caller, so use that internally.  Label
stays as 'method' since in the context of the log event that seems more
correct.
2016-11-29 09:35:34 -08:00
Dave Clendenan 93af604ba7 First cut at adding calling method
If log.SetReportMethod(true) then method=PACKAGE.FUNCTION will be added
as a field to log lines.
eg: time="2016-11-25T19:04:43-08:00" level=info method=main msg="log
testing"

TODO: documentation, examples
2016-11-25 19:02:56 -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
Tony Lee 7a1f601cfd Added ability to disable level text truncation. Fixes #406 2016-08-31 23:55:04 +10: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
Simon Eskildsen 7096056d3c Merge pull request #91 from rasky/disable-timestamp
Allow disabling timestamp in non-tty output.
2014-12-15 16:09:30 -05:00
Giovanni Bajo f0a637a834 Document new option 2014-12-15 21:58:26 +01:00
Giovanni Bajo a3ef049df9 Avoid extra quotes where not strictly necessary.
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.
2014-12-15 20:20:33 +01:00
Giovanni Bajo 3e9d38f80d Allow disabling timestamp in non-tty output.
This is useful if the output is already being piped to a logger
daemon that will prefix the timestamp by itself (eg: on heroku).
2014-12-15 20:02:02 +01:00
Antoine Grondin 2835e150d9 fixes #88 2014-12-09 21:57:50 -05:00
Antoine Grondin acf1c0d583 textformatter: errors should be in quotes like strings are 2014-10-03 11:58:24 -04:00
Antoine Grondin c4cc714937 fix duplication of msg/time/level keys, add benchmarks. 2014-09-16 20:19:42 -04:00
Antoine Grondin d35b1c983e text-formatter: assume that IsTerminal doesn't change during execution 2014-09-16 17:19:03 -04:00
Matt Price e2a44689a6 updated README and added reference 2014-08-13 13:36:59 -04:00
Matt Price af9d545893 can completely disable colors on text formatter 2014-08-13 13:30:25 -04:00
Simon Eskildsen 2c0db7c868 formatter: drop internalFormatter 2014-07-26 22:22:39 -04:00
Simon Eskildsen 40069a98d6 entry: break out time, level and message from data 2014-07-26 21:34:29 -04:00
Aaron L 0d1e231957 Clean up text_formatter code with a byte.Buffer 2014-05-24 07:48:57 -07:00
Simon Eskildsen 13600d2325 text_formatter: move relative time logic from entry 2014-05-03 20:43:55 -04:00
Rob Napier d32bfc962c Add Windows/FreeBSD support 2014-04-23 19:38:56 -04:00
Dan Buch 79b3145302 Switching non-TTY text formatter to use %q instead of '%v'
so that the output becomes l2met compatible yey!
2014-04-20 15:29:03 -04:00
Simon Eskildsen f9af352362 Merge pull request #10 from pushrax/add-forced-colors
Add option to force TextFormatter to use colors
2014-03-16 16:17:15 -07:00
Justin Li 436d68deda Add option to force TextFormatter to use colors 2014-03-15 23:41:05 -04:00
Justin Li c999e7c963 Set color to red for error level output 2014-03-15 23:34:03 -04:00
Simon Eskildsen 0998f68ad5 text_formatter: ensure quoting of strings 2014-03-14 13:32:49 -04:00
Simon Eskildsen 52eb1c0f57 text_formatter: use %v instead 2014-03-14 13:15:01 -04:00
Simon Eskildsen 1000975e52 text_formatter: change to simpler k-v when no tty 2014-03-14 13:01:06 -04:00
Simon Eskildsen 53371e3664 Add features from README 2014-03-10 19:22:08 -04:00