aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Borg <jakob@kastelo.net>2024-02-09 11:17:44 +0100
committerGitHub <noreply@github.com>2024-02-09 11:17:44 +0100
commit416b9e8924a99a01520aaa08ee60050eaf200dc8 (patch)
tree755a9b62fe5877e5f8434da8b45cad1630e9c38e
parent9f6d732587b26f507916e26e2f5c57e331b1492c (diff)
downloadsyncthing-416b9e8924a99a01520aaa08ee60050eaf200dc8.tar.gz
syncthing-416b9e8924a99a01520aaa08ee60050eaf200dc8.zip
lib/logger: Reduce API surface (#9404)
There is no need to expose the IsTraced() thing; it's just used in initialisation, and thereafter ShouldDebug() is the corresponding correct call.
-rw-r--r--lib/api/debug.go12
-rw-r--r--lib/logger/logger.go9
2 files changed, 6 insertions, 15 deletions
diff --git a/lib/api/debug.go b/lib/api/debug.go
index b5d4b1a1c..e5325a695 100644
--- a/lib/api/debug.go
+++ b/lib/api/debug.go
@@ -10,18 +10,8 @@ import (
"github.com/syncthing/syncthing/lib/logger"
)
-var (
- l = logger.DefaultLogger.NewFacility("api", "REST API")
-)
+var l = logger.DefaultLogger.NewFacility("api", "REST API")
func shouldDebugHTTP() bool {
return l.ShouldDebug("api")
}
-
-func init() {
- // The debug facility was originally named "http", changed in:
- // https://github.com/syncthing/syncthing/pull/5548
- if l.IsTraced("http") {
- l.SetDebug("api", true)
- }
-}
diff --git a/lib/logger/logger.go b/lib/logger/logger.go
index ac06f0c13..a60856e12 100644
--- a/lib/logger/logger.go
+++ b/lib/logger/logger.go
@@ -54,7 +54,6 @@ type Logger interface {
Warnf(format string, vals ...interface{})
ShouldDebug(facility string) bool
SetDebug(facility string, enabled bool)
- IsTraced(facility string) bool
Facilities() map[string]string
FacilityDebugging() []string
NewFacility(facility, description string) Logger
@@ -132,6 +131,7 @@ func (l *logger) callHandlers(level LogLevel, s string) {
func (l *logger) Debugln(vals ...interface{}) {
l.debugln(3, vals...)
}
+
func (l *logger) debugln(level int, vals ...interface{}) {
s := fmt.Sprintln(vals...)
l.mut.Lock()
@@ -144,6 +144,7 @@ func (l *logger) debugln(level int, vals ...interface{}) {
func (l *logger) Debugf(format string, vals ...interface{}) {
l.debugf(3, format, vals...)
}
+
func (l *logger) debugf(level int, format string, vals ...interface{}) {
s := fmt.Sprintf(format, vals...)
l.mut.Lock()
@@ -229,8 +230,8 @@ func (l *logger) SetDebug(facility string, enabled bool) {
}
}
-// IsTraced returns whether the facility name is contained in STTRACE.
-func (l *logger) IsTraced(facility string) bool {
+// isTraced returns whether the facility name is contained in STTRACE.
+func (l *logger) isTraced(facility string) bool {
if len(l.traces) > 0 {
if l.traces[0] == "all" {
return true
@@ -269,7 +270,7 @@ func (l *logger) Facilities() map[string]string {
// NewFacility returns a new logger bound to the named facility.
func (l *logger) NewFacility(facility, description string) Logger {
- l.SetDebug(facility, l.IsTraced(facility))
+ l.SetDebug(facility, l.isTraced(facility))
l.mut.Lock()
l.facilities[facility] = description