Commit Graph

293 Commits

Author SHA1 Message Date
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
Ravi Raju a025d45231 EmbedObject() API and knob to change caller frames (#66)
* Fix for a bug in cbor decodeFloat
* Add EmbedObject() method
* knob to change the depth of caller frames to skip
* removed EmbedObj() for array - since it is same as Object()
2018-05-16 18:42:33 -07:00
Olivier Poitrey b5207c012d
Fix type in README (fix #62) 2018-05-12 22:12:35 -07:00
Ravi Raju 533ee32d5d fix needed after calling encoder via interface (#60) 2018-05-10 18:21:30 -07:00
Olivier Poitrey ea1184be2b Get back some ns by removing the extra inferance added by binary support
benchstat old new
name                                   old time/op    new time/op    delta
LogEmpty-8                               15.2ns ±14%    13.4ns ± 3%  -12.11%  (p=0.008 n=5+5)
Disabled-8                               2.50ns ± 1%    2.28ns ± 6%   -8.81%  (p=0.008 n=5+5)
Info-8                                   44.4ns ± 1%    36.4ns ± 4%  -17.99%  (p=0.008 n=5+5)
ContextFields-8                          47.6ns ± 1%    39.4ns ± 7%  -17.30%  (p=0.008 n=5+5)
ContextAppend-8                          18.9ns ± 4%    15.2ns ± 4%  -19.68%  (p=0.008 n=5+5)
LogFields-8                               181ns ± 2%     173ns ± 2%   -4.63%  (p=0.008 n=5+5)
LogArrayObject-8                          530ns ± 3%     487ns ± 3%   -8.11%  (p=0.008 n=5+5)
LogFieldType/Int-8                       29.5ns ± 3%    28.8ns ± 2%     ~     (p=0.167 n=5+5)
LogFieldType/Interface-8                  180ns ± 7%     175ns ± 4%     ~     (p=0.579 n=5+5)
LogFieldType/Interface(Object)-8         87.8ns ± 3%    80.5ns ± 1%   -8.29%  (p=0.008 n=5+5)
LogFieldType/Object-8                    83.7ns ± 2%    77.2ns ± 3%   -7.76%  (p=0.008 n=5+5)
LogFieldType/Bools-8                     34.6ns ± 3%    32.3ns ± 6%   -6.64%  (p=0.032 n=5+5)
LogFieldType/Float-8                     43.0ns ± 4%    40.5ns ± 4%   -5.86%  (p=0.016 n=5+5)
LogFieldType/Str-8                       29.8ns ± 2%    26.5ns ± 5%  -11.01%  (p=0.008 n=5+5)
LogFieldType/Err-8                       32.8ns ± 2%    29.8ns ± 4%   -9.21%  (p=0.008 n=5+5)
LogFieldType/Durs-8                       309ns ± 3%     304ns ± 3%     ~     (p=0.238 n=5+5)
LogFieldType/Floats-8                     175ns ± 2%     174ns ± 3%     ~     (p=0.968 n=5+5)
LogFieldType/Strs-8                      51.0ns ± 3%    48.4ns ± 6%   -5.06%  (p=0.032 n=5+5)
LogFieldType/Dur-8                       44.5ns ± 3%    41.3ns ± 3%   -7.11%  (p=0.008 n=5+5)
LogFieldType/Interface(Objects)-8         758ns ± 3%     760ns ± 6%     ~     (p=1.000 n=5+5)
LogFieldType/Interfaces-8                 772ns ± 5%     762ns ± 4%     ~     (p=0.794 n=5+5)
LogFieldType/Bool-8                      28.0ns ± 6%    26.5ns ± 9%     ~     (p=0.143 n=5+5)
LogFieldType/Ints-8                      49.6ns ± 2%    46.2ns ± 2%   -6.70%  (p=0.008 n=5+5)
LogFieldType/Errs-8                      46.5ns ±11%    40.9ns ± 4%  -11.92%  (p=0.008 n=5+5)
LogFieldType/Time-8                       115ns ± 3%     113ns ± 3%     ~     (p=0.167 n=5+5)
LogFieldType/Times-8                      810ns ± 1%     811ns ± 3%     ~     (p=0.889 n=5+5)
ContextFieldType/Errs-8                   158ns ± 6%     156ns ±12%     ~     (p=1.000 n=5+5)
ContextFieldType/Times-8                  165ns ±11%     173ns ± 9%     ~     (p=0.651 n=5+5)
ContextFieldType/Interface-8              289ns ±13%     287ns ±11%     ~     (p=0.690 n=5+5)
ContextFieldType/Interface(Object)-8      285ns ±12%     297ns ± 6%     ~     (p=0.238 n=5+5)
ContextFieldType/Interface(Objects)-8     941ns ± 6%     941ns ± 5%     ~     (p=1.000 n=5+5)
ContextFieldType/Object-8                 201ns ± 5%     210ns ±12%     ~     (p=0.262 n=5+5)
ContextFieldType/Ints-8                   173ns ±10%     165ns ± 9%     ~     (p=0.198 n=5+5)
ContextFieldType/Floats-8                 297ns ± 6%     292ns ± 7%     ~     (p=0.579 n=5+5)
ContextFieldType/Timestamp-8              174ns ± 9%     174ns ±11%     ~     (p=0.810 n=5+5)
ContextFieldType/Durs-8                   445ns ± 9%     425ns ± 3%     ~     (p=0.151 n=5+5)
ContextFieldType/Interfaces-8             944ns ± 6%     876ns ±10%     ~     (p=0.095 n=5+5)
ContextFieldType/Strs-8                   179ns ±11%     165ns ±13%     ~     (p=0.135 n=5+5)
ContextFieldType/Dur-8                    158ns ± 8%     160ns ±19%     ~     (p=1.000 n=5+5)
ContextFieldType/Time-8                   152ns ±15%     148ns ±14%     ~     (p=0.952 n=5+5)
ContextFieldType/Str-8                    146ns ±12%     147ns ±16%     ~     (p=0.841 n=5+5)
ContextFieldType/Err-8                    138ns ±12%     145ns ±17%     ~     (p=0.595 n=5+5)
ContextFieldType/Int-8                    145ns ±10%     146ns ±13%     ~     (p=0.873 n=5+5)
ContextFieldType/Float-8                  181ns ± 9%     162ns ±12%     ~     (p=0.151 n=5+5)
ContextFieldType/Bool-8                   153ns ±10%     131ns ±19%     ~     (p=0.063 n=5+5)
ContextFieldType/Bools-8                  149ns ±11%     160ns ±16%     ~     (p=0.500 n=5+5)
2018-05-10 15:01:41 -07:00
Olivier Poitrey a572c9d1f6 Add missing support for zerolog marshable objects to Fields 2018-05-09 03:52:30 -07:00
Olivier Poitrey 79281e4bf6 Fix Event.Times when format is set to UNIX time 2018-05-09 03:52:30 -07:00
Ravi Raju 57da509ee1 Add JournalD Writer (#57)
JournalD writer decodes each log event and map fields to journald fields. The JSON payload is kept in the `JSON` field.
2018-04-26 23:15:29 -07:00
Olivier Poitrey 89162918d0
Add grpc-zerolog reference (fix #58) 2018-04-26 13:41:11 -07:00
Olivier Poitrey d2b7a51951 Do not print large ints using scientific notation with ConsoleWriter
Fixes #55
2018-04-19 13:13:40 -07:00
Dan Gillis 711d95f5f1 Some new readability updates (#54) 2018-04-18 20:29:59 -07:00
Ilya Galimyanov 1e2ce57d98 Make GlobalLevel a public function (#53) 2018-04-17 15:52:22 -07:00
Ravi Raju 70bea47cc0 Fix for a bug in cbor decodeFloat (#51) 2018-04-13 00:13:41 -07:00
Ravi Raju 2ccfab3e07 Support for adding IP Address/Prefix + stream based decoder (#49)
* added IPAddr, IPPrefix and stream based cbor decoder
* Update README with cbor decoder tool info
* Update README in cbor with comparison data
2018-04-03 23:07:18 +02:00
Olivier Poitrey 05eafee0eb Update README with instruction about binary encoding 2018-03-28 11:59:26 -07:00
Ravi Raju ddfae1b613 Binary format support (#37)
Adds support for binary logging (with cbor encoding) in addition to JSON. Use the binary_log compile tag to enable the feature.
2018-03-28 11:49:41 -07:00
Olivier Poitrey 3ab376bc30
Add "Who uses zerolog" wiki page link 2018-03-25 22:34:03 -07:00
Olivier Poitrey d0ca9bbceb Add support for pointer values in Fields
Fixes #46
2018-03-25 20:18:47 -07:00
Olivier Poitrey 24cc441b11 Add more json type tests 2018-03-23 09:58:31 -07:00
Olivier Poitrey 4ea03de40d Optimize JSON string encoding using a lookup table
benchstat old new
name                             old time/op    new time/op    delta
AppendString/MultiBytesFirst-8     77.9ns ± 5%    70.2ns ± 1%   -9.88%  (p=0.008 n=5+5)
AppendString/MultiBytesMiddle-8    64.2ns ± 1%    56.3ns ± 5%  -12.19%  (p=0.008 n=5+5)
AppendString/MultiBytesLast-8      51.2ns ± 2%    45.2ns ± 4%  -11.65%  (p=0.008 n=5+5)
AppendString/NoEncoding-8          36.2ns ± 4%    34.0ns ± 6%     ~     (p=0.087 n=5+5)
AppendString/EncodingFirst-8       67.7ns ± 2%    59.4ns ± 2%  -12.26%  (p=0.008 n=5+5)
AppendString/EncodingMiddle-8      56.5ns ± 2%    50.6ns ± 5%  -10.54%  (p=0.008 n=5+5)
AppendString/EncodingLast-8        41.3ns ± 1%    39.6ns ± 5%   -4.11%  (p=0.024 n=5+5)
AppendBytes/MultiBytesLast-8       53.5ns ± 6%    45.6ns ± 4%  -14.79%  (p=0.008 n=5+5)
AppendBytes/NoEncoding-8           36.3ns ± 3%    28.6ns ± 3%  -21.10%  (p=0.008 n=5+5)
AppendBytes/EncodingFirst-8        67.3ns ± 4%    62.1ns ± 4%   -7.75%  (p=0.008 n=5+5)
AppendBytes/EncodingMiddle-8       59.2ns ± 7%    51.0ns ± 6%  -13.85%  (p=0.008 n=5+5)
AppendBytes/EncodingLast-8         43.7ns ± 6%    34.4ns ± 2%  -21.32%  (p=0.008 n=5+5)
AppendBytes/MultiBytesFirst-8      77.7ns ± 2%    71.2ns ± 3%   -8.37%  (p=0.008 n=5+5)
AppendBytes/MultiBytesMiddle-8     63.6ns ± 3%    57.8ns ± 5%   -9.12%  (p=0.008 n=5+5)
2018-03-23 04:24:50 -07:00
Johan Sim Jian An 5250a1ba2d Check nil in RawJSON. (#45) 2018-03-22 21:08:22 -07:00