@@ -67,25 +67,25 @@ use the logger from the context;
67
67
// In main();
68
68
ctx = logr.NewContext (ctx, logger)
69
69
// In a function;
70
- logger = log.FromContextOrDefault (ctx)
70
+ logger = log.FromContextOrGlobal (ctx)
71
71
```
72
72
73
73
Functions really should always have a context as first parameter but
74
- during transition they might not. A global logger is provided;
74
+ they might not. A global logger is provided;
75
75
76
76
```
77
77
log.Logger.Info("Configuration read", "config", config)
78
78
```
79
79
80
80
The global logger it the one returnad by the * first* call to ` log.New `
81
- or a logger named "Meridio" and always on INFO level if ` log.New ` is
82
- not called.
81
+ or a logger named "Meridio" and always on INFO level before ` log.New ` is
82
+ called.
83
83
84
84
85
85
86
86
## Log levels
87
87
88
- Only severity ` info ` , ` error ` and ` critical ` are used (not ` warning ` ) but
88
+ Severity ` debug ` , ` info ` , ` error ` and ` critical ` are used (not ` warning ` ).
89
89
` info ` can have different "verbosity" set with the ` V(n) ` method;
90
90
91
91
``` go
@@ -94,9 +94,9 @@ logger.V(1).Info("This is a debug message")
94
94
logger.V (2 ).Info (" This is a trace message" )
95
95
```
96
96
97
- There is no "trace" level so both trace and debug messages will be
98
- shown as "debug". The level setting is still valid though, trace
99
- messages are suspressed unless TRACE level is set.
97
+ There is no defined "trace" level so both trace and debug messages
98
+ will be shown as "debug". The level filtering is still valid though,
99
+ trace messages are suspressed unless TRACE level is set.
100
100
101
101
The ` Fatal() ` function logs on ` critical ` level.
102
102
@@ -154,8 +154,8 @@ Example output;
154
154
## Design patterns
155
155
156
156
Patterns must evolve slowly to get really good so these are mere
157
- ideas. It is very easy to get carried away and impose some over
158
- structured logging that floods the logs with useless data.
157
+ ideas. It is very easy to get carried away and impose some
158
+ over- structured logging that floods the logs with useless data.
159
159
160
160
161
161
### Class logger
@@ -167,7 +167,7 @@ A logger used in a type (Class) can be decorated with `class` and
167
167
type someHandler struct {
168
168
ctx context.Context
169
169
logger logr.Logger
170
- Adr *net.TCPAddr // Capitalized to make it visible!
170
+ Adr *net.TCPAddr // (optional; capitalized to make it visible)
171
171
}
172
172
173
173
func newHandler (ctx context .Context , addr string ) *someHandler {
@@ -181,7 +181,7 @@ func newHandler(ctx context.Context, addr string) *someHandler {
181
181
logger: logger.WithValues (" instance" , adr),
182
182
Adr: adr,
183
183
}
184
- h.logger .Info (" Created" )
184
+ h.logger .Info (" Created" , " object " , h )
185
185
return h
186
186
}
187
187
@@ -193,8 +193,8 @@ func (h *someHandler) connect() error {
193
193
```
194
194
195
195
The ` class ` is the name of the type and ` instance ` can be anything
196
- that identifies an instance. Remember that the instance field must be
197
- visible (Capitalized) .
196
+ that identifies an instance. The instance field must be
197
+ capitalized if you want it visible .
198
198
199
199
The example shows a ` func ` entry to identify a function. This should
200
200
* not* be used as a common pattern but may be handy in some cases.
0 commit comments