Skip to content

Commit f2418cf

Browse files
committed
feat: print using levels
Signed-off-by: Felipe Zipitria <felipe.zipitria@owasp.org>
1 parent 954d091 commit f2418cf

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

logger/logger.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,28 @@ func init() {
2727
// Another possibility is to add the following strings between the level and the message:
2828
// file={name},line={line},endLine={endLine},title={title}
2929
func SetGithubOutput() zerolog.Logger {
30-
// the following formatlevel func might need to rename levels to match with github naming
30+
// the following formatlevel loosely translates from posix levels to github levels
3131
consoleOutput.FormatLevel = func(i interface{}) string {
32-
return fmt.Sprintf("::%s", i)
32+
var l string
33+
if ll, ok := i.(string); ok {
34+
switch ll {
35+
case zerolog.LevelTraceValue, zerolog.LevelDebugValue:
36+
l = "debug"
37+
case zerolog.LevelInfoValue:
38+
l = "notice "
39+
case zerolog.LevelWarnValue:
40+
l = "warn "
41+
case zerolog.LevelErrorValue, zerolog.LevelFatalValue, zerolog.LevelPanicValue:
42+
l = "error "
43+
default:
44+
l = "???"
45+
}
46+
} else {
47+
if i == nil {
48+
l = "???"
49+
}
50+
}
51+
return fmt.Sprintf("::%s", l)
3352
}
3453
consoleOutput.FormatMessage = func(i interface{}) string {
3554
return fmt.Sprintf("::%s", i)

0 commit comments

Comments
 (0)