mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-08-08 23:12:18 -04:00
updated docs against format strings + correct function With()
This commit is contained in:
parent
35755c6d12
commit
0c92fa9998
1 changed files with 9 additions and 5 deletions
|
@ -40,22 +40,26 @@ Further we try to adhere to the following guidelines:
|
||||||
log.Error("A critical error occurred!")
|
log.Error("A critical error occurred!")
|
||||||
```
|
```
|
||||||
|
|
||||||
* Use the `WithAttrs()` method to add structured context to your log messages. The context tags should be easily searchable to allow for easy log filtering. Try to keep consistent tag naming!
|
* Use the `With()` method to add structured context to your log messages. The context tags should be easily searchable to allow for easy log filtering. Try to keep consistent tag naming!
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
log.WithAttrs(slog.Any("error" someError), slog.String("ip", "192.0.2.1")).Error("Connecting to IP failed")
|
log.With(slog.Any("error" someError), slog.String("ip", "192.0.2.1")).Error("Connecting to IP failed")
|
||||||
```
|
```
|
||||||
|
|
||||||
* Slog does not support format strings out of the box. You have to wrap any format strings in `fmt.Sprintf()`.
|
* Log messages may use format strings to produce human readable messages. However, the information should also be present as structured context fields if it might be valuable for debugging purposes. So, instead of writing
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
log.Info(fmt.Sprintf("Starting server on %s:%s", addr, port))
|
log.Info(fmt.Sprintf("Starting server on %s:%s", addr, port))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You should write
|
||||||
|
|
||||||
|
```Go
|
||||||
|
log.With(slog.String("address", addr), slog.Int("port", port)).Info("Starting server")
|
||||||
|
```
|
||||||
|
|
||||||
* Use log levels to configure how detailed the logs of you application should be.
|
* Use log levels to configure how detailed the logs of you application should be.
|
||||||
|
|
||||||
* `Debug()` for log low level and detailed information. This may include variable dumps, but should not disclose sensitive information, e.g. keys or secret tokens.
|
* `Debug()` for log low level and detailed information. This may include variable dumps, but should not disclose sensitive information, e.g. keys or secret tokens.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue