Commit Graph

186 Commits

Author SHA1 Message Date
guonaihong e709c5d91e Allow custom caller level (#196)
To modify the Caller, you can pass a jump to a few function call stacks.

```go
package main

import (
    "github.com/rs/zerolog"
    "github.com/rs/zerolog/log"
)

func myError() {
    log.Debug().Caller(1).Str("test2", "v2").Send()
}

func foo() {
    log.Debug().Caller(2).Str("test2", "v2").Send()
}

func myError2() {
    foo()
}
func main() {
    zerolog.TimeFieldFormat = zerolog.TimeFormatUnix

    log.Debug().Caller().Str("test1", "v1").Send()
    myError()
    myError2()
}
```
2019-11-11 01:14:19 -08:00
CrazyMax 4502cc1942 Add TraceLevel (#158) 2019-11-04 11:39:22 -08:00
aca 43d05e8ddf hlog: add custom header handler (#197) 2019-11-04 10:14:00 -08:00
Nelz 5861452d64 enable adding raw JSON to an array (#145)
* enable adding JSON to an array

* do not forget the comment
2019-11-04 09:47:06 -08:00
hazimj 7592fcbe60 make TimeFormatUnixMicro var exportable (#189) 2019-10-24 17:02:51 -07:00
Veselkov Konstantin 2e41c37ac4 Fixed comment for documentations (#194) 2019-10-24 03:02:36 -07:00
hazimj 19e454b4c7 Add Unix time format for microseconds (#188) 2019-10-09 20:35:32 -07:00
Veselkov Konstantin 33a4561a07 remove golint errors (#187) 2019-10-04 07:31:06 -07:00
Tim Satke 06599535fa Bumped golang.org/x/tools (#183) 2019-08-28 14:58:12 -07:00
Charles Chan 61d1749124 Fix description in README for Global Settings (#176) 2019-08-11 07:03:49 +02:00
Stefan VanBuren b806a5ecbe Fix a few typos / clarify. (#169) 2019-07-19 18:10:43 +01:00
Zhang Sen a7f9fc2a17 simplify code of event.msg() (#165) 2019-07-19 12:35:57 +01:00
Christian Muehlhaeuser 42d101e9f7 Fixed code formatting and import order using goimports (#167) 2019-07-19 12:07:15 +01:00
i6du 77a1695358 add send function for convenience (#164) 2019-07-03 23:16:03 -07:00
wangyuehong 60d4b07b61 Add GetLevel method (#161) 2019-06-20 16:44:55 -07:00
IxDay 9938a23cba Fix JSON when object is first to be pushed (#154)
When pushing an object to the logger, and this object was the first
field added. Zerolog was outputting an invalid json blob, issuing an
extra comma before the object. This patch ensure that JSON is still valid
even if an object is pushed first to the logger.

Fixes #152
2019-06-04 23:48:09 -07:00
Vasiliy Faronov 1a2c7daec4 Fix misleading text about duplicate keys in JSON (#141)
Per RFC 8259 Section 4, behavior on duplicate keys is unspecified.

Fixes #140.
2019-05-25 18:51:33 -07:00
Olivier Poitrey ffd0e9625d Optimize basic sampler 2019-05-23 17:01:18 -07:00
Olivier Poitrey ad0401954a
Remove go 1.12 requirement 2019-05-23 11:44:28 -07:00
Olivier Poitrey acf3980132 console: handle timestamp in ms correctly + fix UTC 2019-04-25 12:44:49 -07:00
Olivier Poitrey 33f552ec3d Fix console write with missing level field 2019-04-25 12:12:24 -07:00
Olivier Poitrey 2a07580c27 Fix console writer when unix time stamp and/or no message field is used 2019-04-25 12:01:27 -07:00
Olivier Poitrey 3e85c4b21c Add a new time format for UNIX timestamp in milliseconds 2019-04-19 15:48:31 -07:00
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