Commit Graph

244 Commits

Author SHA1 Message Date
Steve Carlson fad20d83d3
docs: sampler typo (#342)
fix BasicSampler docstring typo

Co-authored-by: Steve Carlson <steve.carlson@crowdstrike.com>
2021-08-10 21:43:41 +02:00
hn8 164ec91b0c
Add logr implementation to README and json.RawMessage to Fields() (#337) 2021-08-03 11:31:54 +02:00
Spike^ekipS c1533bd5f8
patched; panic Event.Object() and Event.EmbedObject() with nil (#338) 2021-08-01 17:24:18 +02:00
adw1n 0872592ea2
Make default console formatter work with customized level names (#330) 2021-07-15 22:04:15 +02:00
Eugene Klimov da1cb97713
Update x/tools dependency 2021-06-23 17:16:12 +02:00
adw1n 117cb53bc6
Fix copying stack setting in logger's Output method (#325)
Minimum example to reproduce the problem:
```go
package main

import (
	"os"

	"github.com/pkg/errors"
	"github.com/rs/zerolog"
	"github.com/rs/zerolog/log"
	"github.com/rs/zerolog/pkgerrors"
)

func main() {
	log.Logger = log.With().Caller().Stack().Logger().Output(zerolog.ConsoleWriter{Out: os.Stderr})
	zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack

	log.Info().Err(errors.New("test")).Send()
}
```
Without my changes `stack` isn't printed.
2021-06-07 12:16:53 +02:00
Mitsuo Heijo e05605c215
Use github.com/coreos/go-systemd/v22 (#322) 2021-05-23 10:29:31 +02:00
Olivier Poitrey 6ed1127758 Fix panic on disabled event with CallerSkipFrame
Fixes #319
2021-05-20 18:40:53 +02:00
povsister 47a03bc5eb
Add ability to customize internal json marshaler (#318)
Added a package level variable "InterfaceMarshalFunc".
It's used to marshal interface to JSON encoded byte slice,
mostly when event.Interface("key", v) is called.
2021-05-20 14:46:36 +02:00
Marcus Watkins ffbd37b8d7
Add Func log method (#321)
This adds the Func log method to log using an anonymous function
only if the level is currently enabled.

The use case is for when you don't own an object and therefore can't
create your own marshaller but need to do some translation prior to
logging.

For example, this:

msg := log.Debug()
if msg.Enabled() {
  msg.Str("complicated_thing", makeBinaryThingLoggable(thing))
}
msg.Msg("Sending complicated thing")

Turns into this:

log.Debug().
  Func(func(e *Event) { e.Str("complicated_thing", makeBinaryThingLoggable(thing)) }).
  Msg("Sending complicated thing")
2021-05-20 01:33:11 +02:00
Olivier Poitrey 3c3b4a354e Add ability to customize level values 2021-05-14 00:07:21 +02:00
Zephaniah Loss-Cutler-Hull 4de2fcc128
Fix handling of printing caller with Write, Print, and Printf. (#315)
* Add event.CallerSkipFrame(skip int)

This indicates that, for this event, we should skip an additional
specified number of frames.

This is cumulative, calling it twice for the same event will add both
numbers together, and this is in addition to any skip frame settings set
through the context, or globally.

The indended purpose is for wrappers to Msg or Msgf, so that the actual
caller is always printed correctly.

* Use CallerSkipFrame for Print, Printf, and Write.

This allows us to use the correct caller when using these 3 functions.

Co-authored-by: Zephaniah E. Loss-Cutler-Hull <warp@aehallh.com>
2021-05-13 17:22:27 +02:00
Olivier Poitrey f09463fbe1 Migrate to github actions 2021-05-05 15:10:23 +02:00
Tabitha 19c98f6d3e
If LevelFieldName is empty don't log level (#313) 2021-05-05 14:40:45 +02:00
Jack Christensen 0f923d7926
Fix: mutil.fancyWriter.ReadFrom records number of bytes written (#256)
Without this hlog.AccessHnalder reports a size written of 0 when the
ReadFrom method is used. This is easily visible when using
http.FileServer where all files are served with a logged size of 0.
2021-04-22 03:22:35 +02:00
Dan Gillis 582f0cf0e3
add Disabled to String and ParseLevel; add tests (#307) 2021-04-13 07:32:06 +02:00
Olivier Poitrey 98f889fcde Revert "Fix Typo (#306)"
This reverts commit f85e803cc5.
2021-04-07 19:58:46 +02:00
Redha Juanda f85e803cc5
Fix Typo (#306) 2021-04-07 16:12:54 +02:00
Ben Visness f2cc3cf8b7
Fix Context.Stack() (#303) 2021-03-23 23:01:01 +01:00
Emre Arslan 72b5b1ea58
added overlog to related project (#302)
Co-authored-by: Emre Arslan <emre.arslan@trendyol.com>
2021-03-18 16:21:38 +01:00
Jean Morais 7ccd4c940b
Bump golang.org/x/tools to v0.1.0 (#295)
Fixes #291: There is a known vulnerability in one of the golang.org/x/tools dependencies [CVE-2019-11840].
2021-03-03 00:42:31 +01:00
Dan Gillis 7a3aa8746f
Allow setting context using idKey. Assist for issue #293. (#296) 2021-03-02 11:01:32 +01:00
Nuno Diegues a8f5328bb7
Make MultiLevelWriter resilient to individual log failure (#282)
Fixes #281

Currently MultiLevelWriter would give up if any individual backing logger
failed. This could result in no logging ever happening if the bad logger
was set up in the first position.

As a motivating factor, this can happen in "normal" circumstances, such
as running as a Windows Service where stderr is not available and therefore
the ConsoleWriter will fail. If you happen to set it as the first logger,
then no logging ever takes place. To make matters worse, connecting a
debugger creates an stderr, so it made it a pretty daunting situation
to overcome.

The proposed solution is to go through all underlying loggers and return
the last error obtained, if any. In practice there isn't much being done
with those errors anyway, as the best way to address logging errors is
to hook a ErrorHandler, which will still be triggered despite this change.

Co-authored-by: Nuno Diegues <nuno@cloudflare.com>
2021-01-20 17:03:52 +01:00
Eng Zer Jun 4f50ae2ed0
build: update github.com/pkg/errors from 0.8.1 to 0.9.1 (#280)
* [ImgBot] Optimize images

/pretty.png -- 141.30kb -> 82.09kb (41.9%)

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

* build: update pkg/errors from 0.8.1 to 0.9.1

According to pkg/errors 0.9.0 release[1], they have reduced the
allocations for stacktrace.

[1]: https://github.com/pkg/errors/releases/tag/v0.9.0

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

Co-authored-by: ImgBotApp <ImgBotHelp@gmail.com>
2021-01-11 11:12:13 +01:00
Dan Gillis 0aba2e4ae5
Add Error logging section and section links (#275) 2020-12-30 00:57:10 +01:00
Jason McVetta a3b272d512
Test newer Go versions (#276) 2020-12-29 21:23:45 +01:00
Jason McVetta b7e31f4fe7
Log relative path for caller when using `ConsoleWriter` (#267)
* use relative file path
2020-12-28 22:38:24 +01:00
CrazyMax 29d8dac5e8
Allow to exclude parts from console output (#272)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
2020-11-29 10:13:56 +01:00
Jason McVetta cac3894be4
don't trim leading slash on callers outside cwd (#266)
Fixes https://github.com/rs/zerolog/issues/265
2020-11-02 13:52:51 +01:00
Dionisio Romero Díaz 9336c4d0ed
Fix AppendFloats64 first element as 32 (#263) 2020-10-27 17:05:59 +01:00
mathew e11d470c08
Add syslog CEE support (#262) 2020-10-12 15:16:04 +02:00
Mikhail Lukianchenko 72acd6cfe8
Fix typo in diode.NewWriter argument name (#254) 2020-08-06 12:19:27 +02:00
Eugene 9e51190d47
Fix some tests (#245)
* TestUpdateEmptyContext for CBOR
* Properly name CBOR 64 bit tests
2020-06-25 14:48:07 -07:00
Eugene 1b763497ee
Fix UpdateContext panic with empty Context (#244) 2020-06-24 16:11:26 -07:00
Chris Camel 7248ae2fb4
add stringer support for sub-logger (#241)
Same than #185 but for zerolog.Context.
2020-06-17 20:42:03 -07:00
Dima 7825d86337
stringer event method (#185) 2020-05-28 10:43:18 -07:00
Fred Muya 63767a55ec
Add Example for Multiple Outputs using Multiwriter (#198)
Fixes #73
2020-05-28 10:41:39 -07:00
Giuseppe f83de79b81
Improve documentation wording for SyncWriter (#235)
There is already a lock in place for both POSIX (Linux/Unix/Darwin) and Windows, see:

https://github.com/golang/go/blob/go1.14.3/src/internal/poll/fd_windows.go#L684
https://github.com/golang/go/blob/go1.14.3/src/internal/poll/fd_unix.go#L255
2020-05-25 10:57:14 -07:00
Stig Otnes Kolstad 663cbb4c84
docs: minor typos (#234) 2020-05-14 08:27:19 -07:00
Giuseppe e027a834ab
Typo fix (#233) 2020-05-14 01:29:30 -07:00
Ravi Raju 50ffd2b67d
Moved 8btye integer tests to a different file (#231)
and that file has a build tag to be excluded from 386 arch

Signed-off-by: Ravi Raju <toravir@yahoo.com>

Co-authored-by: Ravi Raju <toravir@yahoo.com>
2020-05-12 01:24:15 -07:00
Jean-Sébastien Didierlaurent e86e8f2f49
fix(diode): atomic.AddUint64 in 32-bit cause panic (#229)
see: https://golang.org/pkg/sync/atomic/#pkg-note-BUG
2020-05-11 11:49:43 -07:00
Emir Ribić de5a95dced
Remove duplicate comment (#227) 2020-05-10 21:54:46 -07:00
Eugene 14dcf38e7d
Make AppendKey in json inlinable (#226)
This change increase performance by inlining this frequently called function

Benchmark:

| name                                   | old time/op |    new time/op |    delta | params |
|---|---|---|---|---|
| LogEmpty-8                               | 14.1ns ±10% |    15.6ns ±13% |  +10.43% |  (p=0.003 n=10+10) |
| Disabled-8                               | 1.27ns ± 0% |    1.35ns ± 1% |   +6.54% |  (p=0.000 n=9+10) |
| Info-8                                   | 39.8ns ± 5% |    37.9ns ± 2% |   -4.55% |  (p=0.000 n=10+10) |
| ContextFields-8                          | 42.2ns ± 4% |    39.7ns ± 3% |   -6.04% |  (p=0.000 n=10+10) |
| ContextAppend-8                          | 15.3ns ± 0% |    14.5ns ± 0% |   -5.23% |  (p=0.000 n=9+10) |
| LogFields-8                              |  179ns ± 0% |     176ns ± 1% |   -1.23% |  (p=0.000 n=10+10) |
| LogArrayObject-8                         |  526ns ± 1% |     491ns ± 1% |   -6.65% |  (p=0.000 n=9+10) |
| LogFieldType/Bools-8                     | 34.5ns ± 2% |    33.3ns ± 4% |   -3.63% |  (p=0.000 n=9+10) |
| LogFieldType/Int-8                       | 29.7ns ± 4% |    28.3ns ± 6% |   -4.71% |  (p=0.003 n=10+10) |
| LogFieldType/Str-8                       | 29.6ns ± 3% |    27.1ns ± 2% |   -8.19% |  (p=0.000 n=10+10) |
| LogFieldType/Time-8                      |  119ns ± 0% |     118ns ± 0% |   -0.84% |  (p=0.000 n=9+9) |
| LogFieldType/Interfaces-8                |  504ns ± 1% |     516ns ± 1% |   +2.46% |  (p=0.000 n=10+10) |
| LogFieldType/Object-8                    | 73.7ns ± 2% |    71.6ns ± 1% |   -2.94% |  (p=0.000 n=10+10) |
| LogFieldType/Bool-8                      | 28.9ns ± 6% |    25.9ns ± 3% |  -10.35% |  (p=0.000 n=9+10) |
| LogFieldType/Strs-8                      | 53.7ns ± 2% |    51.6ns ± 1% |   -3.95% |  (p=0.000 n=9+10) |
| LogFieldType/Err-8                       | 39.2ns ± 2% |    38.1ns ± 4% |   -2.66% |  (p=0.006 n=10+10) |
| LogFieldType/Interface-8                 |  147ns ± 1% |     145ns ± 1% |   -1.22% |  (p=0.001 n=10+10) |
| LogFieldType/Interface(Object)-8         | 78.8ns ± 1% |    76.9ns ± 1% |   -2.43% |  (p=0.000 n=10+10) |
| LogFieldType/Interface(Objects)-8        |  516ns ± 0% |     507ns ± 1% |   -1.66% |  (p=0.000 n=8+10) |
| LogFieldType/Ints-8                      | 52.4ns ± 1% |    48.1ns ± 1% |   -8.28% |  (p=0.000 n=10+10) |
| LogFieldType/Float-8                     | 39.8ns ± 1% |    38.4ns ± 2% |   -3.33% |  (p=0.000 n=10+9) |
| LogFieldType/Times-8                     |  887ns ± 0% |     887ns ± 0% |     ~    |  (p=0.164 n=8+10) |
| LogFieldType/Dur-8                       | 41.1ns ± 2% |    40.2ns ± 6% |   -2.10% |  (p=0.014 n=10+10) |
| LogFieldType/Durs-8                      |  266ns ± 0% |     262ns ± 0% |   -1.35% |  (p=0.000 n=7+10) |
| LogFieldType/Floats-8                    |  166ns ± 0% |     165ns ± 1% |     ~    |  (p=0.238 n=10+10) |
| LogFieldType/Errs-8                      |  126ns ± 1% |     120ns ± 2% |   -4.61% |  (p=0.000 n=10+10) |
| ContextFieldType/Bool-8                  |  140ns ± 2% |     140ns ± 2% |     ~    |  (p=0.701 n=10+9) |
| ContextFieldType/Err-8                   |  150ns ± 3% |     150ns ± 2% |     ~    |  (p=0.932 n=10+10) |
| ContextFieldType/Interfaces-8            |  631ns ± 1% |     628ns ± 1% |     ~    |  (p=0.108 n=10+10) |
| ContextFieldType/Floats-8                |  263ns ± 1% |     257ns ± 1% |   -2.05% |  (p=0.000 n=10+10) |
| ContextFieldType/Errs-8                  |  205ns ± 2% |     204ns ± 2% |     ~    |  (p=0.499 n=10+9) |
| ContextFieldType/Dur-8                   |  146ns ± 3% |     149ns ± 2% |   +1.86% |  (p=0.011 n=9+10) |
| ContextFieldType/Durs-8                  |  372ns ± 1% |     367ns ± 1% |   -1.24% |  (p=0.000 n=10+10) |
| ContextFieldType/Bools-8                 |  145ns ± 2% |     144ns ± 3% |     ~    |  (p=0.447 n=10+10) |
| ContextFieldType/Ints-8                  |  157ns ± 3% |     157ns ± 2% |     ~    |  (p=0.976 n=9+9) |
| ContextFieldType/Float-8                 |  147ns ± 3% |     148ns ± 4% |     ~    |  (p=0.385 n=9+10) |
| ContextFieldType/Strs-8                  |  158ns ± 3% |     157ns ± 2% |     ~    |  (p=0.666 n=10+10) |
| ContextFieldType/Time-8                  |  143ns ± 2% |     141ns ± 3% |   -1.75% |  (p=0.035 n=10+10) |
| ContextFieldType/Times-8                 |  159ns ± 4% |     159ns ± 2% |     ~    |  (p=0.978 n=10+10) |
| ContextFieldType/Interface(Object)-8     |  252ns ± 2% |     251ns ± 2% |     ~    |  (p=0.415 n=10+10) |
| ContextFieldType/Timestamp-8             |  167ns ± 2% |     167ns ± 3% |     ~    |  (p=0.662 n=10+10) |
| ContextFieldType/Int-8                   |  142ns ± 4% |     140ns ± 2% |   -2.04% |  (p=0.026 n=10+10) |
| ContextFieldType/Str-8                   |  142ns ± 1% |     141ns ± 3% |   -1.00% |  (p=0.016 n=9+10) |
| ContextFieldType/Interface-8             |  253ns ± 1% |     249ns ± 3% |     ~    |  (p=0.055 n=9+10) |
| ContextFieldType/Interface(Objects)-8    |  632ns ± 1% |     624ns ± 1% |   -1.20% |  (p=0.000 n=10+9) |
| ContextFieldType/Object-8                |  194ns ± 2% |     192ns ± 2% |     ~    |  (p=0.083 n=10+10) |
| Hooks/Nop/Single-8                       | 16.5ns ± 6% |    15.5ns ± 5% |   -5.95% |  (p=0.001 n=10+10) |
| Hooks/Nop/Multi-8                        | 18.5ns ± 6% |    17.8ns ± 4% |   -3.66% |  (p=0.009 n=10+9) |
| Hooks/Simple-8                           | 31.0ns ± 2% |    28.1ns ± 2% |   -9.24% |  (p=0.000 n=8+9) |
| Samplers/BasicSampler_1-8                | 0.65ns ± 1% |    0.63ns ± 1% |   -1.78% |  (p=0.000 n=10+9) |
| Samplers/BasicSampler_5-8                | 30.0ns ± 1% |    32.2ns ± 0% |   +7.29% |  (p=0.000 n=10+9) |
| Samplers/RandomSampler-8                 | 92.8ns ± 1% |    90.8ns ± 1% |   -2.25% |  (p=0.000 n=10+10) |
| Samplers/BurstSampler-8                  | 34.5ns ± 1% |    36.6ns ± 1% |   +5.95% |  (p=0.000 n=9+9) |
| Samplers/BurstSamplerNext-8              | 46.3ns ± 0% |    46.1ns ± 0% |   -0.41% |  (p=0.001 n=9+7) |
| ConsoleWriter-8                          | 5.90µs ± 0% |    5.84µs ± 1% |   -0.91% |  (p=0.000 n=10+10) |
2020-05-05 19:44:34 -07:00
Olivier Poitrey a06edf20d7
Fix zerolog.SetGlobalLevel readme 2020-04-20 13:50:01 -07:00
Blake Williams fe394c81ce
Remove dependency on Goji (#223) 2020-04-12 22:02:06 -07:00
haozibi 1c32ee06a7
Fix: Event.stack initialization error (#219) 2020-03-30 10:16:40 -07:00
Milo d9df1802de
Updated README (#212)
Updated README to reflect changes in the code - included new field types available, corrected typos.
2020-02-15 09:27:26 -08:00
Olivier Poitrey f7c93dce1c Fix test on non linux platform 2020-02-10 17:16:38 -08:00
Olivier Poitrey 68a3fd989d Fix a crash condition when AnErr is used with a nil interface 2020-02-10 17:15:06 -08:00