Codebase list golang-github-go-kit-kit / a50819e
Document implementation tradeoff and reason for choosing to favor a cheap WIth method at the expense of the Log method. Chris Hines 8 years ago
1 changed file(s) with 14 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
88 type Levels struct {
99 ctx log.Context
1010 levelKey string
11
12 // We have a choice between storing level values in string fields or
13 // making a separate context for each level. When using string fields the
14 // Log method must combine the base context, the level data, and the
15 // logged keyvals; but the With method only requires updating one context.
16 // If we instead keep a separate context for each level the Log method
17 // must only append the new keyvals; but the With method would have to
18 // update all five contexts.
19
20 // Roughly speaking, storing multiple contexts breaks even if the ratio of
21 // Log/With calls is more than the number of levels. We have chosen to
22 // make the With method cheap and the Log method a bit more costly because
23 // we do not expect most applications to Log more than five times for each
24 // call to With.
1125
1226 debugValue string
1327 infoValue string