-
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.
- Loading branch information
1 parent
4a2a83e
commit e3f1ddb
Showing
12 changed files
with
54 additions
and
75 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
repos: | ||
- repo: https://github.com/golangci/golangci-lint | ||
rev: v1.54.2 | ||
rev: v1.56.2 | ||
hooks: | ||
- id: golangci-lint | ||
|
||
|
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
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 |
---|---|---|
@@ -1,39 +1,35 @@ | ||
package log | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/natefinch/lumberjack" | ||
"github.com/samber/lo" | ||
"github.com/snivilised/extendio/xfs/utils" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
|
||
"github.com/snivilised/extendio/i18n" | ||
) | ||
|
||
func NewLogger(info *LoggerInfo) Ref { | ||
return utils.NewRoProp(lo.TernaryF(info.Enabled, | ||
func() Logger { | ||
if info.Path == "" { | ||
panic(i18n.NewInvalidConfigEntryError(info.Path, "-")) | ||
} | ||
func NewLogger(info *LoggerInfo) (Logger, error) { | ||
if !info.Enabled { | ||
return zap.NewNop(), nil | ||
} | ||
|
||
ws := zapcore.AddSync(&lumberjack.Logger{ | ||
Filename: info.Path, | ||
MaxSize: info.Rotation.MaxSizeInMb, | ||
MaxBackups: info.Rotation.MaxNoOfBackups, | ||
MaxAge: info.Rotation.MaxAgeInDays, | ||
}) | ||
config := zap.NewProductionEncoderConfig() | ||
config.EncodeTime = zapcore.TimeEncoderOfLayout(info.TimeStampFormat) | ||
core := zapcore.NewCore( | ||
zapcore.NewJSONEncoder(config), | ||
ws, | ||
info.Level, | ||
) | ||
if info.Path == "" { | ||
return nil, fmt.Errorf("invalid config, value: %q", info.Path) | ||
} | ||
|
||
return zap.New(core) | ||
}, func() Logger { | ||
return zap.NewNop() | ||
}), | ||
ws := zapcore.AddSync(&lumberjack.Logger{ | ||
Filename: info.Path, | ||
MaxSize: info.Rotation.MaxSizeInMb, | ||
MaxBackups: info.Rotation.MaxNoOfBackups, | ||
MaxAge: info.Rotation.MaxAgeInDays, | ||
}) | ||
config := zap.NewProductionEncoderConfig() | ||
config.EncodeTime = zapcore.TimeEncoderOfLayout(info.TimeStampFormat) | ||
core := zapcore.NewCore( | ||
zapcore.NewJSONEncoder(config), | ||
ws, | ||
info.Level, | ||
) | ||
|
||
return zap.New(core), nil | ||
} |
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