Commit Graph

46 Commits

Author SHA1 Message Date
Ben Visness f2cc3cf8b7
Fix Context.Stack() (#303) 2021-03-23 23:01:01 +01:00
Eugene 1b763497ee
Fix UpdateContext panic with empty Context (#244) 2020-06-24 16:11:26 -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
Dmitry Savintsev cb951d468e fix the typo in 'guarantee' (#203) 2019-12-27 09:23:15 -08:00
Olivier Poitrey 54e95fe699 Fix numbering of levels 2019-11-18 09:34:23 -08:00
CrazyMax 4502cc1942 Add TraceLevel (#158) 2019-11-04 11:39:22 -08:00
Veselkov Konstantin 33a4561a07 remove golint errors (#187) 2019-10-04 07:31:06 -07:00
wangyuehong 60d4b07b61 Add GetLevel method (#161) 2019-06-20 16:44:55 -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 509d727fba Add the Err function to ease the log errors. 2019-04-19 15:24:32 -07:00
Soloman Weng 8e5449ab35 Allow using custom level field format (#136) 2019-03-01 16:08:23 -08: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 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
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
Ilya Galimyanov 1e2ce57d98 Make GlobalLevel a public function (#53) 2018-04-17 15:52:22 -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
Kai Ren b62d797a8d Mention fields duplication caveat in documentation (#41) 2018-03-08 07:41:28 -08:00
Olivier Poitrey fcbdf23e9e Use new hook internally to handle timestamp in context 2018-02-07 13:31:00 -08:00
Rodrigo Coelho c3d02683c7 Add hook support (#24) 2017-12-01 10:52:37 -07:00
Ravi Raju 9a65e7ccd2 Fix Output with existing context (fix #20)
Also includes tests for Output()
2017-11-08 10:47:56 -08:00
Giovanni Bajo 89e128fdc1 Speed up operations when logging is disabled. (#18)
Low-level optimizations to help the compiler generate better code
when logging is disabled. Measured improvement is ~30% on amd64
(from 21 ns/op to 16 ns/op).
2017-11-05 05:22:20 -08:00
Olivier Poitrey 3ac71fc58d Simplify copies 2017-09-03 11:01:28 -07:00
Olivier Poitrey 26094019c8 Fix godoc 2017-09-01 20:07:47 -07:00
Olivier Poitrey 8c682b3b12 Add Print and Printf top level methods 2017-09-01 19:59:48 -07:00
Olivier Poitrey e26050b2a3 Improve hlog handlers performance by switching to pointer logger
Update request logger's context thru its pointer in order to avoid
multiple copies/allocations.
2017-08-29 22:53:32 -07:00
Olivier Poitrey 9e5c06cf0e Add more advanced sampling modes 2017-08-28 23:30:54 -07:00
Olivier Poitrey 2ed2f2c974 Fix pretty logging and add a screenshot to the README 2017-08-05 20:45:41 -07:00
Olivier Poitrey a83efb6080 Add a ConsoleWriter to output pretty log on the console during dev 2017-08-05 19:47:55 -07:00
Olivier Poitrey 6cdd9977c4 Refactor JSON encoding code 2017-07-25 22:05:32 -07:00
Olivier Poitrey 7af653895b Add utility functions WithLevel and Fields
Add some utility functions to ease migration from other logger API.
2017-07-10 02:58:58 -07:00
Olivier Poitrey 2e3da1d5b5 Always place timestamp as first field for better log readability 2017-06-08 10:12:49 -07:00
Olivier Poitrey 2a829377cb Rename warning field to warn in the output 2017-06-08 10:03:03 -07:00
Olivier Poitrey 3f6ca6688c Fix Fatal and Panic not terminating to program 2017-06-06 10:23:34 -07:00
Olivier Poitrey 46cd35d1f2 Remove error returned by Msg and Msgf
When error happen, there is nothing the caller can really do and it is
not practicle to handle logging errors. Print an error on the standard
error instead.
2017-06-06 10:10:31 -07:00
Olivier Poitrey 95ecd5ad27 Fix Log level 2017-06-05 13:03:55 -07:00
Olivier Poitrey 7e8bba7e7f Fix typos 2017-06-05 13:03:55 -07:00
Olivier Poitrey 67803eb791 Add Nop constructor 2017-06-02 00:24:52 -07:00
Olivier Poitrey 6bcd15ecf0 Add support for zerolog as an output for stdlib logger 2017-06-01 23:17:28 -07:00
Olivier Poitrey 6a6144a10b Add http.Handler helpers (adapted from xlog) 2017-05-20 01:48:00 -07:00
Olivier Poitrey d0cfcbbafe Write directly into a single shared buffer per event for even better perf 2017-05-19 19:45:46 -07:00
Olivier Poitrey 77726764ed Optimize disabled logging 2017-05-19 09:56:31 -07:00
Olivier Poitrey a417fb1a8b Fix sample template types 2017-05-19 09:48:01 -07:00
Olivier Poitrey af9dd4ec23 Add SyncWriter utility type for non-thread-safe writers 2017-05-19 09:13:04 -07:00
Olivier Poitrey d0a1bd7e3e Make GlobalLevel and DisableSampling thread safe 2017-05-15 11:18:42 -07:00
Olivier Poitrey 7f302b00ec Initial commit 2017-05-13 16:22:35 -07:00