-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: migrate logrus to zap * chore: add additional logging internal functions Don't want to fetch each time. * chore: shorten logging package to just "log", obligatory "go mod tidy" * fix: "one of these things is not like the other"
- Loading branch information
Showing
10 changed files
with
163 additions
and
116 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,66 @@ | ||
package log | ||
|
||
import ( | ||
"os" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
var logger *zap.Logger | ||
|
||
func Init() { | ||
config := zap.NewProductionConfig() | ||
|
||
// Set the log format | ||
format := os.Getenv("LOG_FORMAT") | ||
if format == "test" { | ||
config.Encoding = "console" | ||
} else { | ||
config.Encoding = "json" | ||
} | ||
|
||
// Set the log level | ||
level := os.Getenv("LOG_LEVEL") | ||
switch level { | ||
case "debug": | ||
config.Level = zap.NewAtomicLevelAt(zap.DebugLevel) | ||
case "info": | ||
config.Level = zap.NewAtomicLevelAt(zap.InfoLevel) | ||
case "warn": | ||
config.Level = zap.NewAtomicLevelAt(zap.WarnLevel) | ||
case "error": | ||
config.Level = zap.NewAtomicLevelAt(zap.ErrorLevel) | ||
default: | ||
config.Level = zap.NewAtomicLevelAt(zap.InfoLevel) | ||
} | ||
|
||
// Build the logger | ||
var err error | ||
logger, err = config.Build() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Ensure we flush any buffered log entries | ||
defer logger.Sync() | ||
} | ||
|
||
func Info(message string, fields ...zap.Field) { | ||
logger.Info(message, fields...) | ||
} | ||
|
||
func Debug(message string, fields ...zap.Field) { | ||
logger.Debug(message, fields...) | ||
} | ||
|
||
func Error(message string, fields ...zap.Field) { | ||
logger.Error(message, fields...) | ||
} | ||
|
||
func Fatal(message string, fields ...zap.Field) { | ||
logger.Fatal(message, fields...) | ||
} | ||
|
||
func With(fields ...zap.Field) *zap.Logger { | ||
return logger.With(fields...) | ||
} |
This file was deleted.
Oops, something went wrong.
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
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.