feat(log): use github.com/qdm12/log library

This commit is contained in:
Quentin McGaw
2022-03-30 07:46:53 +00:00
parent 84607e332b
commit 179274ade0
14 changed files with 54 additions and 60 deletions

View File

@@ -4,7 +4,7 @@ import (
"net"
"time"
"github.com/qdm12/golibs/logging"
"github.com/qdm12/log"
"inet.af/netaddr"
)
@@ -62,11 +62,11 @@ func CopyDurationPtr(original *time.Duration) (copied *time.Duration) {
return copied
}
func CopyLogLevelPtr(original *logging.Level) (copied *logging.Level) {
func CopyLogLevelPtr(original *log.Level) (copied *log.Level) {
if original == nil {
return nil
}
copied = new(logging.Level)
copied = new(log.Level)
*copied = *original
return copied
}

View File

@@ -4,7 +4,7 @@ import (
"net"
"time"
"github.com/qdm12/golibs/logging"
"github.com/qdm12/log"
)
func DefaultInt(existing *int, defaultValue int) (
@@ -74,12 +74,12 @@ func DefaultDuration(existing *time.Duration,
return result
}
func DefaultLogLevel(existing *logging.Level,
defaultValue logging.Level) (result *logging.Level) {
func DefaultLogLevel(existing *log.Level,
defaultValue log.Level) (result *log.Level) {
if existing != nil {
return existing
}
result = new(logging.Level)
result = new(log.Level)
*result = defaultValue
return result
}

View File

@@ -5,7 +5,7 @@ import (
"net/http"
"time"
"github.com/qdm12/golibs/logging"
"github.com/qdm12/log"
"inet.af/netaddr"
)
@@ -96,13 +96,13 @@ func MergeWithDuration(existing, other *time.Duration) (result *time.Duration) {
return other
}
func MergeWithLogLevel(existing, other *logging.Level) (result *logging.Level) {
func MergeWithLogLevel(existing, other *log.Level) (result *log.Level) {
if existing != nil {
return existing
} else if other == nil {
return nil
}
result = new(logging.Level)
result = new(log.Level)
*result = *other
return result
}

View File

@@ -5,7 +5,7 @@ import (
"net/http"
"time"
"github.com/qdm12/golibs/logging"
"github.com/qdm12/log"
"inet.af/netaddr"
)
@@ -86,11 +86,11 @@ func OverrideWithDuration(existing, other *time.Duration) (result *time.Duration
return result
}
func OverrideWithLogLevel(existing, other *logging.Level) (result *logging.Level) {
func OverrideWithLogLevel(existing, other *log.Level) (result *log.Level) {
if other == nil {
return existing
}
result = new(logging.Level)
result = new(log.Level)
*result = *other
return result
}

View File

@@ -2,15 +2,15 @@ package settings
import (
"github.com/qdm12/gluetun/internal/configuration/settings/helpers"
"github.com/qdm12/golibs/logging"
"github.com/qdm12/gotree"
"github.com/qdm12/log"
)
// Log contains settings to configure the logger.
type Log struct {
// Level is the log level of the logger.
// It cannot be nil in the internal state.
Level *logging.Level
Level *log.Level
}
func (l Log) validate() (err error) {
@@ -37,7 +37,7 @@ func (l *Log) overrideWith(other Log) {
}
func (l *Log) setDefaults() {
l.Level = helpers.DefaultLogLevel(l.Level, logging.LevelInfo)
l.Level = helpers.DefaultLogLevel(l.Level, log.LevelInfo)
}
func (l Log) String() string {

View File

@@ -7,7 +7,7 @@ import (
"strings"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/golibs/logging"
"github.com/qdm12/log"
)
func readLog() (log settings.Log, err error) {
@@ -19,13 +19,13 @@ func readLog() (log settings.Log, err error) {
return log, nil
}
func readLogLevel() (level *logging.Level, err error) {
func readLogLevel() (level *log.Level, err error) {
s := os.Getenv("LOG_LEVEL")
if s == "" {
return nil, nil //nolint:nilnil
}
level = new(logging.Level)
level = new(log.Level)
*level, err = parseLogLevel(s)
if err != nil {
return nil, fmt.Errorf("environment variable LOG_LEVEL: %w", err)
@@ -36,16 +36,16 @@ func readLogLevel() (level *logging.Level, err error) {
var ErrLogLevelUnknown = errors.New("log level is unknown")
func parseLogLevel(s string) (level logging.Level, err error) {
func parseLogLevel(s string) (level log.Level, err error) {
switch strings.ToLower(s) {
case "debug":
return logging.LevelDebug, nil
return log.LevelDebug, nil
case "info":
return logging.LevelInfo, nil
return log.LevelInfo, nil
case "warning":
return logging.LevelWarn, nil
return log.LevelWarn, nil
case "error":
return logging.LevelError, nil
return log.LevelError, nil
default:
return level, fmt.Errorf(
"%w: %q is not valid and can be one of debug, info, warning or error",