Skip to content

Commit

Permalink
Refactored logger styles
Browse files Browse the repository at this point in the history
  • Loading branch information
evg4b committed Apr 21, 2024
1 parent ea20189 commit cd35b41
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
4 changes: 2 additions & 2 deletions internal/tui/styles/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package styles

var (
DebugLabel = "DEBUG"
InfoLabel = "INFO "
WarningLabel = "WARN "
InfoLabel = "INFO"
WarningLabel = "WARN"
ErrorLabel = "ERROR"
FatalLabel = "FATAL"
)
65 changes: 37 additions & 28 deletions internal/tui/styles/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,40 @@ import (
"github.com/charmbracelet/log"
)

var DefaultStyles = log.Styles{
Timestamp: lipgloss.NewStyle(),
Caller: lipgloss.NewStyle().Faint(true),
Prefix: lipgloss.NewStyle().Bold(true).Faint(true),
Message: lipgloss.NewStyle(),
Key: lipgloss.NewStyle().Faint(true),
Value: lipgloss.NewStyle(),
Separator: lipgloss.NewStyle().Faint(true),
Levels: map[log.Level]lipgloss.Style{
log.DebugLevel: DebugText.Copy().
SetString(DebugBlock.Render(DebugLabel)).
Bold(true),
log.InfoLevel: InfoText.Copy().
SetString(InfoBlock.Render(InfoLabel)).
Bold(true),
log.WarnLevel: WarningText.Copy().
SetString(WarningBlock.Render(WarningLabel)).
Bold(true),
log.ErrorLevel: ErrorText.Copy().
SetString(ErrorBlock.Render(ErrorLabel)).
Bold(true),
log.FatalLevel: ErrorText.Copy().
SetString(ErrorBlock.Render(FatalLabel)).
Bold(true),
},
Keys: map[string]lipgloss.Style{},
Values: map[string]lipgloss.Style{},
}
var (
boxLength = 7

debugPrefix = DebugBlock.Copy().Width(boxLength)
infoPrefix = InfoBlock.Copy().Width(boxLength)
warnPrefix = WarningBlock.Copy().Width(boxLength)
errorPrefix = ErrorBlock.Copy().Width(boxLength)

DefaultStyles = log.Styles{
Timestamp: lipgloss.NewStyle(),
Caller: lipgloss.NewStyle().Faint(true),
Prefix: lipgloss.NewStyle().Bold(true).Faint(true),
Message: lipgloss.NewStyle(),
Key: lipgloss.NewStyle().Faint(true),
Value: lipgloss.NewStyle(),
Separator: lipgloss.NewStyle().Faint(true),
Levels: map[log.Level]lipgloss.Style{
log.DebugLevel: DebugText.Copy().
SetString(debugPrefix.Render(DebugLabel)).
Bold(true),
log.InfoLevel: InfoText.Copy().
SetString(infoPrefix.Render(InfoLabel)).
Bold(true),
log.WarnLevel: WarningText.Copy().
SetString(warnPrefix.Render(WarningLabel)).
Bold(true),
log.ErrorLevel: ErrorText.Copy().
SetString(errorPrefix.Render(ErrorLabel)).
Bold(true),
log.FatalLevel: ErrorText.Copy().
SetString(errorPrefix.Render(FatalLabel)).
Bold(true),
},
Keys: map[string]lipgloss.Style{},
Values: map[string]lipgloss.Style{},
}
)

0 comments on commit cd35b41

Please sign in to comment.