Skip to content

Commit

Permalink
docs: style customization updated (#106)
Browse files Browse the repository at this point in the history
* Style customization doc updated

I believe the doc was not up to date regarding the cutomization of logger

* Update README.md

Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>

* Update README.md

Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>

---------

Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
  • Loading branch information
santoshlite and aymanbagabas authored Feb 17, 2024
1 parent 1f0b8bb commit 9d04d2b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,18 @@ defined at a global level in [styles.go](./styles.go).

```go
// Override the default error level style.
log.ErrorLevelStyle = lipgloss.NewStyle().
SetString("ERROR!!").
Padding(0, 1, 0, 1).
Background(lipgloss.AdaptiveColor{
Light: "203",
Dark: "204",
}).
Foreground(lipgloss.Color("0"))
styles := log.DefaultStyles()
styles.Levels[log.ErrorLevel] = lipgloss.NewStyle().
SetString("ERROR!!").
Padding(0, 1, 0, 1).
Background(lipgloss.Color("204")).
Foreground(lipgloss.Color("0"))
// Add a custom style for key `err`
log.KeyStyles["err"] = lipgloss.NewStyle().Foreground(lipgloss.Color("204"))
log.ValueStyles["err"] = lipgloss.NewStyle().Bold(true)
log.Error("Whoops!", "err", "kitchen on fire")
styles.Keys["err"] = lipgloss.NewStyle().Foreground(lipgloss.Color("204"))
styles.Values["err"] = lipgloss.NewStyle().Bold(true)
logger := log.New(os.Stderr)
logger.SetStyles(styles)
logger.Error("Whoops!", "err", "kitchen on fire")
```

<picture>
Expand Down

0 comments on commit 9d04d2b

Please sign in to comment.