gui: Add debug tab to settings (ref #2644)

Just because there are a ton of people struggling to set env vars.
Perhaps this should live in advanced settings, and perhaps we should have a button to view the log.

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4604
LGTM: calmh, imsodin
This commit is contained in:
Audrius Butkevicius
2017-12-24 22:26:05 +00:00
committed by Simon Frei
parent 2547a29dd7
commit c58b383b6d
7 changed files with 148 additions and 16 deletions

View File

@@ -308,6 +308,7 @@ type recorder struct {
type Line struct {
When time.Time `json:"when"`
Message string `json:"message"`
Level LogLevel `json:"level"`
}
func NewRecorder(l Logger, level LogLevel, size, initial int) Recorder {
@@ -324,18 +325,18 @@ func (r *recorder) Since(t time.Time) []Line {
defer r.mut.Unlock()
res := r.lines
for i := 0; i < len(res) && res[i].When.Before(t); i++ {
// nothing, just incrementing i
}
if len(res) == 0 {
return nil
}
// We must copy the result as r.lines can be mutated as soon as the lock
// is released.
cp := make([]Line, len(res))
copy(cp, res)
return cp
for i := 0; i < len(res); i++ {
if res[i].When.After(t) {
// We must copy the result as r.lines can be mutated as soon as the lock
// is released.
res = res[i:]
cp := make([]Line, len(res))
copy(cp, res)
return cp
}
}
return nil
}
func (r *recorder) Clear() {
@@ -348,6 +349,7 @@ func (r *recorder) append(l LogLevel, msg string) {
line := Line{
When: time.Now(),
Message: msg,
Level: l,
}
r.mut.Lock()
@@ -367,6 +369,6 @@ func (r *recorder) append(l LogLevel, msg string) {
r.lines = append(r.lines, line)
if len(r.lines) == r.initial {
r.lines = append(r.lines, Line{time.Now(), "..."})
r.lines = append(r.lines, Line{time.Now(), "...", l})
}
}

View File

@@ -130,4 +130,24 @@ func TestRecorder(t *testing.T) {
}
}
// Check that since works
now := time.Now()
time.Sleep(time.Millisecond)
lines = r1.Since(now)
if len(lines) != 0 {
t.Error("unexpected lines")
}
l.Infoln("hah")
lines = r1.Since(now)
if len(lines) != 1 {
t.Fatalf("unexpected line count: %d", len(lines))
}
if lines[0].Message != "hah" {
t.Errorf("incorrect line: %s", lines[0])
}
}