File tree 3 files changed +28
-15
lines changed
3 files changed +28
-15
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
23
### Security
24
24
- Nothing
25
25
26
+ ## [ 1.5.0] - 2019-07-30
27
+ ### Added
28
+ - ` LoggerFactory ` interface abstracting ` Factory ` struct
29
+ - ` DefaultFactory ` global var that allows to replace factory used to generate loggers
30
+
26
31
## [ 1.4.0] - 2019-05-30
27
32
### Changed
28
33
- Baggage key is now a public string ` "logctx-data-map-string-interface" ` that can be set and read by anyone from any package.
Original file line number Diff line number Diff line change @@ -23,6 +23,23 @@ func baggageString(b map[string]interface{}) string {
23
23
return strings .Join (kvPairs , ": " )
24
24
}
25
25
26
+ // Factory provides context aware loggers.
27
+ type Factory struct {
28
+ baseLogger Logger
29
+ }
30
+
31
+ // NewFactory instantiates a factory with the default logger.
32
+ func NewFactory () Factory {
33
+ return Factory {
34
+ baseLogger : DefaultLogger ,
35
+ }
36
+ }
37
+
38
+ // For provides a logger which is aware of the passed context and will prepend the context baggage values.
39
+ func (f Factory ) For (ctx context.Context ) Logger {
40
+ return newBaggageLogger (ctx , f .baseLogger )
41
+ }
42
+
26
43
func newBaggageLogger (ctx context.Context , base Logger ) baggageLogger {
27
44
return baggageLogger {
28
45
Logger : base ,
Original file line number Diff line number Diff line change @@ -4,25 +4,16 @@ import (
4
4
"context"
5
5
)
6
6
7
- // Factory provides context aware loggers.
8
- type Factory struct {
9
- baseLogger Logger
10
- }
11
-
12
- // NewFactory instantiates a factory with the default logger.
13
- func NewFactory () Factory {
14
- return Factory {
15
- baseLogger : DefaultLogger ,
16
- }
17
- }
7
+ // DefaultFactory is the factory used to create new loggers
8
+ var DefaultFactory Factory = NewFactory ()
18
9
19
- // For provides a logger which is aware of the passed context and will prepend the context baggage values.
20
- func ( f Factory ) For ( ctx context. Context ) Logger {
21
- return newBaggageLogger (ctx , f . baseLogger )
10
+ // LoggerFactory creates Logger instances
11
+ type LoggerFactory interface {
12
+ For (ctx context. Context ) Logger
22
13
}
23
14
24
15
// For provides a logger which is aware of the passed context and will prepend
25
16
// the context baggage values, using DefaultLogger as base logger.
26
17
func For (ctx context.Context ) Logger {
27
- return newBaggageLogger (ctx , DefaultLogger )
18
+ return DefaultFactory . For (ctx )
28
19
}
You can’t perform that action at this time.
0 commit comments