* Increase code coverage in acmedns * More testing of ReadConfig() and its fallback mechanism * Found that if someone put a '"' double quote into the filename that we configure zap to log to, it would cause the the JSON created to be invalid. I have replaced the JSON string with proper config * Better handling of config options for api.TLS - we now error on an invalid value instead of silently failing. added a basic test for api.setupTLS() (to increase test coverage) * testing nameserver isOwnChallenge and isAuthoritative methods * add a unit test for nameserver answerOwnChallenge * fix linting errors * bump go and golangci-lint versions in github actions * Update golangci-lint.yml Bumping github-actions workflow versions to accommodate some changes in upstream golanci-lint * Bump Golang version to 1.23 (currently the oldest supported version) Bump golanglint-ci to 2.0.2 and migrate the config file. This should resolve the math/rand/v2 issue * bump golanglint-ci action version * Fixing up new golanglint-ci warnings and errors --------- Co-authored-by: Joona Hoikkala <5235109+joohoi@users.noreply.github.com>
47 lines
990 B
Go
47 lines
990 B
Go
package acmedns
|
|
|
|
import (
|
|
"go.uber.org/zap/zapcore"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func SetupLogging(config AcmeDnsConfig) (*zap.Logger, error) {
|
|
var (
|
|
logger *zap.Logger
|
|
zapCfg zap.Config
|
|
err error
|
|
)
|
|
|
|
logformat := "console"
|
|
if config.Logconfig.Format == "json" {
|
|
logformat = "json"
|
|
}
|
|
outputPath := "stdout"
|
|
if config.Logconfig.Logtype == "file" {
|
|
outputPath = config.Logconfig.File
|
|
}
|
|
errorPath := "stderr"
|
|
if config.Logconfig.Logtype == "file" {
|
|
errorPath = config.Logconfig.File
|
|
}
|
|
|
|
zapCfg.Level, err = zap.ParseAtomicLevel(config.Logconfig.Level)
|
|
if err != nil {
|
|
return logger, err
|
|
}
|
|
zapCfg.Encoding = logformat
|
|
zapCfg.OutputPaths = []string{outputPath}
|
|
zapCfg.ErrorOutputPaths = []string{errorPath}
|
|
zapCfg.EncoderConfig = zapcore.EncoderConfig{
|
|
TimeKey: "time",
|
|
MessageKey: "msg",
|
|
LevelKey: "level",
|
|
EncodeLevel: zapcore.LowercaseLevelEncoder,
|
|
EncodeTime: zapcore.ISO8601TimeEncoder,
|
|
}
|
|
|
|
logger, err = zapCfg.Build()
|
|
return logger, err
|
|
}
|