44package logger
55
66import (
7+ "fmt"
78 "os"
89
910 "github.com/rs/zerolog"
@@ -12,7 +13,27 @@ import (
1213
1314const DefaultLogLevel zerolog.Level = zerolog .InfoLevel
1415
16+ var consoleOutput = zerolog.ConsoleWriter {Out : os .Stderr , TimeFormat : "03:04:05" }
17+
1518func init () {
16- log .Logger = log .Output (zerolog. ConsoleWriter { Out : os . Stderr , TimeFormat : "03:04:05" } ).With ().Caller ().Logger ()
19+ log .Logger = log .Output (consoleOutput ).With ().Caller ().Logger ()
1720 zerolog .SetGlobalLevel (DefaultLogLevel )
1821}
22+
23+ // SetGithubOutput changes the standard logging format to be compatible with GitHub's.
24+ // See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-creating-an-annotation-for-an-error
25+ // Levels on github are:
26+ // - debug, notice, error, warning
27+ // Another possibility is to add the following strings between the level and the message:
28+ // file={name},line={line},endLine={endLine},title={title}
29+ func SetGithubOutput () zerolog.Logger {
30+ // the following formatlevel func might need to rename levels to match with github naming
31+ consoleOutput .FormatLevel = func (i interface {}) string {
32+ return fmt .Sprintf ("::%s" , i )
33+ }
34+ consoleOutput .FormatMessage = func (i interface {}) string {
35+ return fmt .Sprintf ("::%s" , i )
36+ }
37+ consoleOutput .PartsExclude = []string {zerolog .TimestampFieldName }
38+ return zerolog .New (consoleOutput ).With ().Logger ()
39+ }
0 commit comments