| 1 |
// Copyright (c) 2016 Uber Technologies, Inc. |
| 2 |
// |
| 3 |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 |
// of this software and associated documentation files (the "Software"), to deal |
| 5 |
// in the Software without restriction, including without limitation the rights |
| 6 |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 |
// copies of the Software, and to permit persons to whom the Software is |
| 8 |
// furnished to do so, subject to the following conditions: |
| 9 |
// |
| 10 |
// The above copyright notice and this permission notice shall be included in |
| 11 |
// all copies or substantial portions of the Software. |
| 12 |
// |
| 13 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 |
// THE SOFTWARE. |
| 20 |
|
| 21 |
package benchmarks |
| 22 |
|
| 23 |
import ( |
| 24 |
"io" |
| 25 |
"log/slog" |
| 26 |
) |
| 27 |
|
| 28 |
func newSlog(fields ...slog.Attr) *slog.Logger { |
| 29 |
return slog.New(slog.NewJSONHandler(io.Discard, nil).WithAttrs(fields)) |
| 30 |
} |
| 31 |
|
| 32 |
func newDisabledSlog(fields ...slog.Attr) *slog.Logger { |
| 33 |
return slog.New(slog.NewJSONHandler(io.Discard, &slog.HandlerOptions{Level: slog.LevelError}).WithAttrs(fields)) |
| 34 |
} |
| 35 |
|
| 36 |
func fakeSlogFields() []slog.Attr { |
| 37 |
return []slog.Attr{ |
| 38 |
slog.Int("int", _tenInts[0]), |
| 39 |
slog.Any("ints", _tenInts), |
| 40 |
slog.String("string", _tenStrings[0]), |
| 41 |
slog.Any("strings", _tenStrings), |
| 42 |
slog.Time("time", _tenTimes[0]), |
| 43 |
slog.Any("times", _tenTimes), |
| 44 |
slog.Any("user1", _oneUser), |
| 45 |
slog.Any("user2", _oneUser), |
| 46 |
slog.Any("users", _tenUsers), |
| 47 |
slog.Any("error", errExample), |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
func fakeSlogArgs() []any { |
| 52 |
return []any{ |
| 53 |
"int", _tenInts[0], |
| 54 |
"ints", _tenInts, |
| 55 |
"string", _tenStrings[0], |
| 56 |
"strings", _tenStrings, |
| 57 |
"time", _tenTimes[0], |
| 58 |
"times", _tenTimes, |
| 59 |
"user1", _oneUser, |
| 60 |
"user2", _oneUser, |
| 61 |
"users", _tenUsers, |
| 62 |
"error", errExample, |
| 63 |
} |
| 64 |
} |