Commit Graph

163 Commits

Author SHA1 Message Date
Olivier Poitrey 509d727fba Add the Err function to ease the log errors. 2019-04-19 15:24:32 -07:00
Mike Camp 651d361cfe Add CallerWithSkipFrameCount to the Context (#98) (#135)
Add the ability to skip a specified number of stack frames
on a per context basis. Before this toe CallerSkipFrameCount
could only be set globally.
2019-03-04 16:41:18 -08:00
Soloman Weng 8e5449ab35 Allow using custom level field format (#136) 2019-03-01 16:08:23 -08:00
Olivier Poitrey 6d6350a511 Fix go1.12 test regression
Breakage is due to this change in go 1.12:

Tracebacks, runtime.Caller, and runtime.Callers no longer include compiler-generated initialization functions. Doing a traceback during the initialization of a global variable will now show a function named PKG.init.ializers.

Fix #137
2019-02-27 12:02:51 -08:00
mikeyrcamp 299ff038c1 Add support for customizing caller field format (#133) (#134) 2019-02-20 11:39:29 -08:00
Kevin McConnell 4daee2b758 Don't use faint text in colorized console output (#131)
The faint text style doesn't seem to be supported by all terminals,
which means the default console output loses most of its coloring on
them.

This commit changes the color scheme to more widely-supported colors.
This also matches how it looked in earlier versions of this library.
2019-02-07 07:45:02 -08:00
Olivier Poitrey aa55558e4c
Add support for stack trace extration of error fields (#35) 2019-01-03 11:04:23 -08:00
Ingmar Stein c482b20623 ConsoleWriter: fix race condition (#120)
Alternative approach to #118: fix the race condition by replacing the package-level customization settings with curried functions.
2018-12-07 09:59:01 -08:00
Ingmar Stein 7179aeef58 ConsoleWriter: reset buffer before returning it to the pool (#119)
The buffers put back into the pool should be equivalent to those generated by the `New` function.
2018-12-05 07:46:12 +00:00
Olivier Poitrey 8747b7b3a5 Add ErrorHandler global to allow handling of write errors 2018-11-20 10:56:21 -08:00
Olivier Poitrey 848482bc3d Fix "could not write" error missing carriage return (again) 2018-11-12 17:50:30 -08:00
Yongzheng Lai 7bcaa1a99e fix: console ts with json number (#115) 2018-11-12 00:50:17 -08:00
Olivier Poitrey 8e30c71369 Revert the wrapping of write errors
All errors generated by Go libraries on stderr won't be json encoded
anyway, so it does not make sense to have such a treatment for this one.
2018-11-08 14:49:44 -08:00
Olivier Poitrey 3f112dae87 Fix "could not write" error missing carriage return 2018-11-07 15:21:38 -08:00
Karel Minarik a4c54e5d8b Fix the ConsoleWriter default parts order (#113)
In order to prevent incorrect output when somebody uses a different name eg. for the "MessageFieldName",
the `consoleDefaultPartsOrder` variable has been switched to a function, which is called in `Write()`,
in order to pick up the custom name.

Related: rs/zerolog#92
2018-11-07 09:39:38 -08:00
Karel Minarik 96f91bb4f5 Refactored zerolog.ConsoleWriter to allow customization (#92)
* Added a simple benchmarking test for the ConsoleWriter
* Refactored `zerolog.ConsoleWriter` to allow customization

Closes #84
2018-11-05 02:15:13 -08:00
Olivier Poitrey 51c79ca476 Fix com typo 2018-11-02 13:06:29 -07:00
Olivier Poitrey e7627a4f73 diode: let use a waiter instead of a poller by using 0 as a poolInterval 2018-10-31 16:57:15 -07:00
anthony baa31cfa85 Fix nil pointer dereference when call Fields with a typed nil value (#112) 2018-10-31 10:40:46 -07:00
Vojtech Vitek 8e36cbf881 Don't call panic() and os.Exit(1) on .WithLevel() (#110)
* Don't call panic() and os.Exit(1) on .WithLevel()
* Explain behavior of WithLevel(), compared to Panic() & Fatal()
2018-09-27 18:11:43 -07:00
Olivier Poitrey 20ad1708e7 Fix nil pointer exception on Discard when called with nil logger
Fixes #108
2018-09-26 09:52:52 -07:00
Olivier Poitrey 338f9bc140 Fix typo 2018-09-19 07:40:00 -07:00
Olivier Poitrey e0f8de6c35 Fix usage of sync.Pool
The current usage of sync.Pool is leaky because it stores an arbitrary
sized buffer into the pool. However, sync.Pool assumes that all items in the
pool are interchangeable from a memory cost perspective. Due to the unbounded
size of a buffer that may be added, it is possible for the pool to eventually
pin arbitrarily large amounts of memory in a live-lock situation.

As a simple fix, we just set a maximum size that we permit back into the pool.
2018-09-19 00:20:01 -07:00
Olivier Poitrey 972f27185c Remove unused hook field on event 2018-09-19 00:20:01 -07:00
Thiago Caiubi 624b3116d8 Fix sub-logger by context example (#106)
Not quite sure but looks like the example is using the wrong API.
2018-09-18 07:57:53 -07:00
Olivier Poitrey 785a567b10 Add a mention to logbench 2018-09-18 02:18:32 -07:00
Olivier Poitrey 84794124e9 Use gh-readme template for zerolog.io 2018-09-17 10:28:18 -07:00
Olivier Poitrey fc5bbcd9d6 Create CNAME 2018-09-16 19:21:46 -07:00
Olivier Poitrey 1c8b5945b1 Set theme jekyll-theme-hacker 2018-09-16 19:21:33 -07:00
Olivier Poitrey 2da253048d Fix binary test too 2018-09-16 19:15:55 -07:00
jayven 8aa660046f Add hlog.IDFromCtx 2018-09-16 19:00:10 -07:00
Olivier Poitrey 470da8d0bb Fix failing test introduced by last commit 2018-09-16 18:53:09 -07:00
Olivier Poitrey 1dde226d45 BasicSampler prints first message (fix #104) 2018-09-16 15:54:54 -07:00
Duncan Hall b6f076edc8 Add note for default writing to os.Stderr (#97) 2018-08-31 09:46:32 -07:00
Marcelo Aymone 85255a5e26 Fix typo on documentation (#94) 2018-08-14 19:23:11 -07:00
Olivier Poitrey 71e1f5e052 Add the ability to discard an event from a hook
The Discard method has been added to the Event type so it can be called
from a hook to prevent the event from behing printed. This new method
works outside of the context of a hook too.

Fixes #90
2018-07-26 15:53:02 -07:00
Dave McCormick bae001d86b Allow devs to change the width of the logging level column in consolewriter (#87)
* Allow user to change the width of the logging level column
* Change default level width to 0 (no dynamic width)
2018-07-25 10:05:55 -07:00
su21 e8a8508f09 fix caller file and line number in context hook (#89)
* fix caller file and line number report in context hook

* update comment

* update comment
2018-07-25 02:48:22 -07:00
Dušan Kasan 372015deb4 add linter to check for missing finishers (#85) 2018-07-20 08:05:08 -07:00
Olivier Poitrey 9cd6f6eef2
ctx: store logger in context when missing or different that stored one (#81)
Current implementation stores a copy of the logger as a pointer and
update its content, which is now unecessary since the introduction of
WithContext.

The new WithContext now takes the pointer and store it in the context if
none is stored already or if the last one stored is a different pointer.
This way it is still possible to update the context of a logger stored
in the context, but it is also possible to store a copy of the logger in
a sub-context.

Fix #80
2018-07-02 18:23:53 -07:00
Dušan Kasan 1c6d99b455 Add custom error serialization support and provide sane defaults (#78)
As per https://github.com/rs/zerolog/issues/9 and to offer a different approach from  https://github.com/rs/zerolog/pull/11 and https://github.com/rs/zerolog/pull/35 this PR introduces custom error serialization with sane defaults without breaking the existing APIs.

This is just a first draft and is missing tests. Also, a bit of code duplication which I feel could be reduced but it serves to get the idea across.

It provides global error marshalling by exposing a `var ErrorMarshalFunc func(error) interface{}` in zerolog package that by default is  a function that returns the passed argument. It should be overriden if you require custom error marshalling.

Then in every function that accept error or array of errors `ErrorMarshalFunc` is called on the error and then the result of it is processed like this:
- if it implements `LogObjectMarshaler`, serialize it as an object
- if it is a string serialize as a string
- if it is an error, serialize as a string with the result of `Error()`
- else serialize it as an interface

The side effect of this change is that the encoders don't need the `AppendError/s` methods anymore, as the errors are serialized directly to other types.
2018-07-02 12:46:01 -07:00
Josh Rendek 1a88fbfdd0 Update readme at example for Caller() (#76)
* Update readme at example for Caller()
2018-06-03 22:57:37 -07:00
Pichugin Dmitry dabc72c15b fix README (#74) 2018-05-31 10:33:44 -07:00
Rafael Passos c19f1e5eed Diode module Documentation update (#71)
* Updated Diode example to match new style

* DOC: changed w to wr in assigment to reduce ambiguity
2018-05-25 14:45:33 -07:00
Olivier Poitrey 77db4b4f35 Embed the diode lib to avoid test dependencies
This commit introduces a breaking change in the diode API in order to
hide the diodes package interface. This removes a good number of
dependencies introduced by the test framework used by the diodes
package.
2018-05-24 19:15:40 -07:00
Olivier Poitrey 64faaa6980 Add go.mod file 2018-05-23 09:50:46 -07:00
Olivier Poitrey 80d6806aae Fix comments (bis) 2018-05-21 11:01:34 -07:00
Olivier Poitrey ea197802eb Fix comments 2018-05-17 16:48:29 -07:00
Olivier Poitrey c62533f761 Fix ConsoleWriter test 2018-05-17 16:35:57 -07:00
Olivier Poitrey fb469685aa Fix ConsoleWriter when zerolog is configured to use UNIX timestamp 2018-05-17 16:10:49 -07:00