-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf31f76
commit 0ecd17c
Showing
8 changed files
with
94 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package logger | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/rs/zerolog" | ||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
func SetupLogger() { | ||
zerolog.CallerMarshalFunc = func(pc uintptr, file string, line int) string { | ||
short := file | ||
for i := len(file) - 1; i > 0; i-- { | ||
if file[i] == '/' { | ||
short = file[i+1:] | ||
break | ||
} | ||
} | ||
file = short | ||
return file + ":" + strconv.Itoa(line) | ||
} | ||
log.Logger = log.With().Caller().Logger().Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339}) | ||
var logLevel zerolog.Level | ||
logLevelEnv := os.Getenv("LOG_LEVEL") | ||
var err error | ||
if logLevelEnv != "" { | ||
logLevel, err = zerolog.ParseLevel(logLevelEnv) | ||
} | ||
if err != nil { | ||
log.Error().Err(err).Msg("couldn't parse LOG_LEVEL.") | ||
logLevel = zerolog.InfoLevel | ||
} | ||
zerolog.SetGlobalLevel(logLevel) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.