mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-31 22:11:51 +00:00
lib: Consistently set suture logging (#7202)
This commit is contained in:
parent
7919310dc6
commit
fa40ccece1
@ -119,7 +119,7 @@ func TestStopAfterBrokenConfig(t *testing.T) {
|
|||||||
defer os.Remove(token)
|
defer os.Remove(token)
|
||||||
srv.started = make(chan string)
|
srv.started = make(chan string)
|
||||||
|
|
||||||
sup := suture.New("test", util.Spec())
|
sup := suture.New("test", util.SpecWithDebugLogger(l))
|
||||||
sup.Add(srv)
|
sup.Add(srv)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
sup.ServeBackground(ctx)
|
sup.ServeBackground(ctx)
|
||||||
|
@ -44,16 +44,13 @@ type cast struct {
|
|||||||
// caller needs to set reader and writer with the addReader and addWriter
|
// caller needs to set reader and writer with the addReader and addWriter
|
||||||
// methods to get a functional implementation of Interface.
|
// methods to get a functional implementation of Interface.
|
||||||
func newCast(name string) *cast {
|
func newCast(name string) *cast {
|
||||||
spec := util.Spec()
|
// Only log restarts in debug mode.
|
||||||
|
spec := util.SpecWithDebugLogger(l)
|
||||||
// Don't retry too frenetically: an error to open a socket or
|
// Don't retry too frenetically: an error to open a socket or
|
||||||
// whatever is usually something that is either permanent or takes
|
// whatever is usually something that is either permanent or takes
|
||||||
// a while to get solved...
|
// a while to get solved...
|
||||||
spec.FailureThreshold = 2
|
spec.FailureThreshold = 2
|
||||||
spec.FailureBackoff = 60 * time.Second
|
spec.FailureBackoff = 60 * time.Second
|
||||||
// Only log restarts in debug mode.
|
|
||||||
spec.EventHook = func(e suture.Event) {
|
|
||||||
l.Debugln(e)
|
|
||||||
}
|
|
||||||
c := &cast{
|
c := &cast{
|
||||||
Supervisor: suture.New(name, spec),
|
Supervisor: suture.New(name, spec),
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -139,10 +139,7 @@ type service struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewService(cfg config.Wrapper, myID protocol.DeviceID, mdl Model, tlsCfg *tls.Config, discoverer discover.Finder, bepProtocolName string, tlsDefaultCommonName string, evLogger events.Logger) Service {
|
func NewService(cfg config.Wrapper, myID protocol.DeviceID, mdl Model, tlsCfg *tls.Config, discoverer discover.Finder, bepProtocolName string, tlsDefaultCommonName string, evLogger events.Logger) Service {
|
||||||
spec := util.Spec()
|
spec := util.SpecWithInfoLogger(l)
|
||||||
spec.EventHook = func(e suture.Event) {
|
|
||||||
l.Infoln(e)
|
|
||||||
}
|
|
||||||
service := &service{
|
service := &service{
|
||||||
Supervisor: suture.New("connections.Service", spec),
|
Supervisor: suture.New("connections.Service", spec),
|
||||||
connectionStatusHandler: newConnectionStatusHandler(),
|
connectionStatusHandler: newConnectionStatusHandler(),
|
||||||
|
@ -68,11 +68,8 @@ type Lowlevel struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewLowlevel(backend backend.Backend, opts ...Option) *Lowlevel {
|
func NewLowlevel(backend backend.Backend, opts ...Option) *Lowlevel {
|
||||||
spec := util.Spec()
|
|
||||||
// Only log restarts in debug mode.
|
// Only log restarts in debug mode.
|
||||||
spec.EventHook = func(e suture.Event) {
|
spec := util.SpecWithDebugLogger(l)
|
||||||
l.Debugln(e)
|
|
||||||
}
|
|
||||||
db := &Lowlevel{
|
db := &Lowlevel{
|
||||||
Supervisor: suture.New("db.Lowlevel", spec),
|
Supervisor: suture.New("db.Lowlevel", spec),
|
||||||
Backend: backend,
|
Backend: backend,
|
||||||
|
@ -52,7 +52,7 @@ const (
|
|||||||
|
|
||||||
func NewLocal(id protocol.DeviceID, addr string, addrList AddressLister, evLogger events.Logger) (FinderService, error) {
|
func NewLocal(id protocol.DeviceID, addr string, addrList AddressLister, evLogger events.Logger) (FinderService, error) {
|
||||||
c := &localClient{
|
c := &localClient{
|
||||||
Supervisor: suture.New("local", util.Spec()),
|
Supervisor: suture.New("local", util.SpecWithDebugLogger(l)),
|
||||||
myID: id,
|
myID: id,
|
||||||
addrList: addrList,
|
addrList: addrList,
|
||||||
evLogger: evLogger,
|
evLogger: evLogger,
|
||||||
|
@ -47,7 +47,7 @@ type manager struct {
|
|||||||
|
|
||||||
func NewManager(myID protocol.DeviceID, cfg config.Wrapper, cert tls.Certificate, evLogger events.Logger, lister AddressLister) Manager {
|
func NewManager(myID protocol.DeviceID, cfg config.Wrapper, cert tls.Certificate, evLogger events.Logger, lister AddressLister) Manager {
|
||||||
m := &manager{
|
m := &manager{
|
||||||
Supervisor: suture.New("discover.Manager", util.Spec()),
|
Supervisor: suture.New("discover.Manager", util.SpecWithDebugLogger(l)),
|
||||||
myID: myID,
|
myID: myID,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
cert: cert,
|
cert: cert,
|
||||||
|
@ -52,7 +52,7 @@ type folderSummaryService struct {
|
|||||||
|
|
||||||
func NewFolderSummaryService(cfg config.Wrapper, m Model, id protocol.DeviceID, evLogger events.Logger) FolderSummaryService {
|
func NewFolderSummaryService(cfg config.Wrapper, m Model, id protocol.DeviceID, evLogger events.Logger) FolderSummaryService {
|
||||||
service := &folderSummaryService{
|
service := &folderSummaryService{
|
||||||
Supervisor: suture.New("folderSummaryService", util.Spec()),
|
Supervisor: suture.New("folderSummaryService", util.SpecWithDebugLogger(l)),
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
model: m,
|
model: m,
|
||||||
id: id,
|
id: id,
|
||||||
|
@ -198,10 +198,7 @@ var (
|
|||||||
// where it sends index information to connected peers and responds to requests
|
// where it sends index information to connected peers and responds to requests
|
||||||
// for file data without altering the local folder in any way.
|
// for file data without altering the local folder in any way.
|
||||||
func NewModel(cfg config.Wrapper, id protocol.DeviceID, clientName, clientVersion string, ldb *db.Lowlevel, protectedFiles []string, evLogger events.Logger) Model {
|
func NewModel(cfg config.Wrapper, id protocol.DeviceID, clientName, clientVersion string, ldb *db.Lowlevel, protectedFiles []string, evLogger events.Logger) Model {
|
||||||
spec := util.Spec()
|
spec := util.SpecWithDebugLogger(l)
|
||||||
spec.EventHook = func(e suture.Event) {
|
|
||||||
l.Debugln(e)
|
|
||||||
}
|
|
||||||
m := &model{
|
m := &model{
|
||||||
Supervisor: suture.New("model", spec),
|
Supervisor: suture.New("model", spec),
|
||||||
|
|
||||||
|
@ -99,10 +99,7 @@ func New(cfg config.Wrapper, dbBackend backend.Backend, evLogger events.Logger,
|
|||||||
func (a *App) Start() error {
|
func (a *App) Start() error {
|
||||||
// Create a main service manager. We'll add things to this as we go along.
|
// Create a main service manager. We'll add things to this as we go along.
|
||||||
// We want any logging it does to go through our log system.
|
// We want any logging it does to go through our log system.
|
||||||
spec := util.Spec()
|
spec := util.SpecWithDebugLogger(l)
|
||||||
spec.EventHook = func(e suture.Event) {
|
|
||||||
l.Debugln(e)
|
|
||||||
}
|
|
||||||
a.mainService = suture.New("main", spec)
|
a.mainService = suture.New("main", spec)
|
||||||
|
|
||||||
// Start the supervisor and wait for it to stop to handle cleanup.
|
// Start the supervisor and wait for it to stop to handle cleanup.
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/syncthing/syncthing/lib/logger"
|
||||||
"github.com/syncthing/syncthing/lib/sync"
|
"github.com/syncthing/syncthing/lib/sync"
|
||||||
|
|
||||||
"github.com/thejerf/suture/v4"
|
"github.com/thejerf/suture/v4"
|
||||||
@ -390,8 +391,17 @@ func OnSupervisorDone(sup *suture.Supervisor, fn func()) {
|
|||||||
sup.Add(&doneService{fn})
|
sup.Add(&doneService{fn})
|
||||||
}
|
}
|
||||||
|
|
||||||
func Spec() suture.Spec {
|
func SpecWithDebugLogger(l logger.Logger) suture.Spec {
|
||||||
|
return spec(func(e suture.Event) { l.Debugln(e) })
|
||||||
|
}
|
||||||
|
|
||||||
|
func SpecWithInfoLogger(l logger.Logger) suture.Spec {
|
||||||
|
return spec(func(e suture.Event) { l.Infoln(e) })
|
||||||
|
}
|
||||||
|
|
||||||
|
func spec(eventHook suture.EventHook) suture.Spec {
|
||||||
return suture.Spec{
|
return suture.Spec{
|
||||||
|
EventHook: eventHook,
|
||||||
PassThroughPanics: true,
|
PassThroughPanics: true,
|
||||||
DontPropagateTermination: false,
|
DontPropagateTermination: false,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user