Skip to content

Commit

Permalink
feat: print using levels
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Zipitria <[email protected]>
  • Loading branch information
fzipi committed Feb 27, 2024
1 parent 954d091 commit f2418cf
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,28 @@ func init() {
// Another possibility is to add the following strings between the level and the message:
// file={name},line={line},endLine={endLine},title={title}
func SetGithubOutput() zerolog.Logger {
// the following formatlevel func might need to rename levels to match with github naming
// the following formatlevel loosely translates from posix levels to github levels
consoleOutput.FormatLevel = func(i interface{}) string {
return fmt.Sprintf("::%s", i)
var l string
if ll, ok := i.(string); ok {
switch ll {
case zerolog.LevelTraceValue, zerolog.LevelDebugValue:
l = "debug"
case zerolog.LevelInfoValue:
l = "notice "
case zerolog.LevelWarnValue:
l = "warn "
case zerolog.LevelErrorValue, zerolog.LevelFatalValue, zerolog.LevelPanicValue:
l = "error "
default:
l = "???"
}
} else {
if i == nil {
l = "???"
}
}
return fmt.Sprintf("::%s", l)
}
consoleOutput.FormatMessage = func(i interface{}) string {
return fmt.Sprintf("::%s", i)
Expand Down

0 comments on commit f2418cf

Please sign in to comment.