generated from rog-golang-buddies/golang-template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from rog-golang-buddies/feature/logger
Feature/logger
- Loading branch information
Showing
16 changed files
with
537 additions
and
38 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
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,6 @@ | ||
package config | ||
|
||
//LoggerConfig represents configuration of the logger | ||
type LoggerConfig struct { | ||
Level LoggerLevel `default:"info"` //Level of minimum logging | ||
} |
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,40 @@ | ||
package config | ||
|
||
import "go.uber.org/zap/zapcore" | ||
|
||
//Environment defines the application environment to adjust settings to it. | ||
type Environment string | ||
|
||
const ( | ||
Dev Environment = "dev" | ||
Prod Environment = "prod" | ||
) | ||
|
||
//LoggerLevel defines the minimum logging level to process | ||
type LoggerLevel string | ||
|
||
const ( | ||
TraceLevel LoggerLevel = "trace" | ||
DebugLevel LoggerLevel = "debug" | ||
InfoLevel LoggerLevel = "info" | ||
WarnLevel LoggerLevel = "warn" | ||
ErrorLevel LoggerLevel = "error" | ||
PanicLevel LoggerLevel = "panic" | ||
) | ||
|
||
func (ll LoggerLevel) ToZapLevel() zapcore.Level { | ||
switch ll { | ||
case TraceLevel, DebugLevel: | ||
return zapcore.DebugLevel | ||
case InfoLevel: | ||
return zapcore.InfoLevel | ||
case WarnLevel: | ||
return zapcore.WarnLevel | ||
case ErrorLevel: | ||
return zapcore.ErrorLevel | ||
case PanicLevel: | ||
return zapcore.PanicLevel | ||
default: | ||
return zapcore.InfoLevel | ||
} | ||
} |
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,31 @@ | ||
package logger | ||
|
||
import ( | ||
"github.com/rog-golang-buddies/api-hub_data-scraping-service/internal/config" | ||
) | ||
|
||
//Logger represents common logger interface | ||
//go:generate mockgen -source=logger.go -destination=./mocks/logger.go | ||
type Logger interface { | ||
Fatal(args ...interface{}) | ||
Fatalf(format string, args ...interface{}) | ||
|
||
Error(args ...interface{}) | ||
Errorf(format string, args ...interface{}) | ||
|
||
Warn(args ...interface{}) | ||
Warnf(format string, args ...interface{}) | ||
|
||
Info(args ...interface{}) | ||
Infof(format string, args ...interface{}) | ||
|
||
Debug(args ...interface{}) | ||
Debugf(format string, args ...interface{}) | ||
|
||
Trace(args ...interface{}) | ||
Tracef(format string, args ...interface{}) | ||
} | ||
|
||
func NewLogger(conf *config.ApplicationConfig) (Logger, error) { | ||
return newZapLogger(conf) | ||
} |
Oops, something went wrong.