mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
Debug events module
This commit is contained in:
parent
0d9dcb2f4f
commit
87c3790fa8
@ -107,6 +107,7 @@ The following enviroment variables are interpreted by syncthing:
|
||||
facility strings:
|
||||
- "beacon" (the beacon package)
|
||||
- "discover" (the discover package)
|
||||
- "events" (the events package)
|
||||
- "files" (the files package)
|
||||
- "net" (the main package; connections & network messages)
|
||||
- "model" (the model package)
|
||||
|
17
events/debug.go
Normal file
17
events/debug.go
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
|
||||
// All rights reserved. Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/calmh/syncthing/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
debug = strings.Contains(os.Getenv("STTRACE"), "events") || os.Getenv("STTRACE") == "all"
|
||||
dl = logger.DefaultLogger
|
||||
)
|
@ -1,3 +1,7 @@
|
||||
// Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
|
||||
// All rights reserved. Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package events provides event subscription and polling functionality.
|
||||
package events
|
||||
|
||||
@ -93,6 +97,9 @@ func NewLogger() *Logger {
|
||||
|
||||
func (l *Logger) Log(t EventType, data interface{}) {
|
||||
l.mutex.Lock()
|
||||
if debug {
|
||||
dl.Debugln("log", l.nextId, t.String(), data)
|
||||
}
|
||||
e := Event{
|
||||
ID: l.nextId,
|
||||
Time: time.Now(),
|
||||
@ -114,6 +121,9 @@ func (l *Logger) Log(t EventType, data interface{}) {
|
||||
|
||||
func (l *Logger) Subscribe(mask EventType) *Subscription {
|
||||
l.mutex.Lock()
|
||||
if debug {
|
||||
dl.Debugln("subscribe", mask)
|
||||
}
|
||||
s := &Subscription{
|
||||
mask: mask,
|
||||
id: l.nextId,
|
||||
@ -127,6 +137,9 @@ func (l *Logger) Subscribe(mask EventType) *Subscription {
|
||||
|
||||
func (l *Logger) Unsubscribe(s *Subscription) {
|
||||
l.mutex.Lock()
|
||||
if debug {
|
||||
dl.Debugln("unsubsribe")
|
||||
}
|
||||
delete(l.subs, s.id)
|
||||
close(s.events)
|
||||
l.mutex.Unlock()
|
||||
@ -136,6 +149,10 @@ func (s *Subscription) Poll(timeout time.Duration) (Event, error) {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
if debug {
|
||||
dl.Debugln("poll", timeout)
|
||||
}
|
||||
|
||||
to := time.After(timeout)
|
||||
select {
|
||||
case e, ok := <-s.events:
|
||||
|
@ -1,3 +1,7 @@
|
||||
// Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
|
||||
// All rights reserved. Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package events_test
|
||||
|
||||
import (
|
||||
|
Loading…
Reference in New Issue
Block a user