Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: Add log viewer (fixes #2644) #4604

Closed

Conversation

AudriusButkevicius
Copy link
Member

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.

image

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.
@canton7
Copy link
Member

canton7 commented Dec 17, 2017

Awesome! A big +1 to having a button which shows the log -- that's going to be far easier for users to grok than "figure out where, if anywhere, your system is logging to".

$http.get(urlbase + '/system/debug').success(function (data) {
var debug = {};
data.enabled = data.enabled || [];
$.each(data.facilities, function(key, value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same as data.facilities.forEach? Just asking because $.each isn't used in syncthingController.js anywhere else.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing. forEach I think is less cross browsery.

@@ -14,9 +14,9 @@ import (
)

var (
l = logger.DefaultLogger.NewFacility("filesystem", "Filesystem access")
l = logger.DefaultLogger.NewFacility("fs", "Filesystem access")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be changed in the help text in main too (and subsequently in docs).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Help text in main is generated from available facilities.

@AudriusButkevicius
Copy link
Member Author

Now displays logs, and "tails" them by polling every 2s.

image
image
image

@AudriusButkevicius AudriusButkevicius changed the title gui: Add debug tab to settings (ref #2644) gui: Add debug tab to settings (fixes #2644) Dec 18, 2017
@AudriusButkevicius AudriusButkevicius changed the title gui: Add debug tab to settings (fixes #2644) gui: Add log viewer (fixes #2644) Dec 18, 2017
@imsodin
Copy link
Member

imsodin commented Dec 19, 2017

The log view keeps re-writing tags from the beginning (cmdline confirms it isn't actually restarting):

screenshot_2017-12-19_09-37-46

Also the trailing is very jumpy and doesn't actually follow the last line, but that may be related to the above problem. I think (de-)activating trailing should be done with a button that toggles it (while still also disabling when clicking into the text area).

What is the intention of the log view? If it is meant as the main source when asking users for logs, 250 lines might not be enough and a button to copy or save the log would be neat. To not increase memory consumption by raising the limit, maybe there could be an additional debug config option to keep all the logs.

@AudriusButkevicius
Copy link
Member Author

It's rewriting logs if you haven't built syncthing, as there is a bug in the since parsing logic. I guess when we tell people to look at the log, they atleast can glimpse at the last 250 lines.

You can open the log and keep it open for a while I guess, but I suspect this would only be used to peek at the last few lines.

@imsodin
Copy link
Member

imsodin commented Dec 19, 2017

I have rebuilt before and now with clean & assets for good measure, the problem with repeating logs and trailing not working remains (nothing in the JS console).

@AudriusButkevicius
Copy link
Member Author

Do the http calls have a since query string?

Whats the issue with trailing apart from you not liking the way you enable disable it?

@AudriusButkevicius
Copy link
Member Author

Also, the message is a red herring. Essentially, it stops tailing when the field gains focus, and the message comes up as 'click on me' just for the user to lose focus on the textarea (clicking the text doesn't actually do anything).

@imsodin
Copy link
Member

imsodin commented Dec 19, 2017

I am confused: In JS console it looks like the last variable is correct, but in gui.go the since query string is empty. When I try from command line with the example for RFC3339 given in Go's docs like this:

 curl -X GET -H "X-API-Key: *" "localhost:8384/rest/system/log?since=2006-01-02T15:04:05Z07:00'

it fails to parse it (custom debug log after time.Parse):

[CBBHG] 2017/12/19 12:18:32.604678 gui.go:961: INFO: getSystemlog q.Get("since"): 2006-01-02T15:04:05Z07:00 err: parsing time "2006-01-02T15:04:05Z07:00": extra text: 07:00

The "test case"

	t, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z07:00")
	fmt.Println(t, err)

also results in

0001-01-01 00:00:00 +0000 UTC parsing time "2006-01-02T15:04:05Z07:00": extra text: 07:00.

What is wrong here?

@AudriusButkevicius
Copy link
Member Author

Strange that it can generate timestamps with that signature yet not parse them, anyway, that's definately a bug.

@AudriusButkevicius
Copy link
Member Author

I guess I could replace the text with "Click anywhere outside of the text box to continue tailing the log"

@calmh
Copy link
Member

calmh commented Dec 19, 2017 via email

@imsodin
Copy link
Member

imsodin commented Dec 19, 2017

EDIT: Missed calmh's comment: That is not generated, that was me copy-pasting from the Go docs.

Strange that it can generate timestamps with that signature yet not parse them, anyway, that's definately a bug.

Nah, it's non-obvious format notation combined with me not RTFM (thoroughly). The time zone is either Z or +-xx:xx, so Z07:00 is invalid.

That's actually a pretty annoying format for html queries, because + gets converted to -> error again. Therefore we need to either convert to UTC or encode the timezone + as %2B. Also the format from JS is with nanoseconds, that should be stripped in the request.

@canton7
Copy link
Member

canton7 commented Dec 19, 2017

Well, anything you put in a query string should be automatically escaped by whatever library you're using to do the query, so that shouldn't be an issue...

@imsodin
Copy link
Member

imsodin commented Dec 19, 2017

How does the library know whether you mean a literal + or not? Curl and angularjs (I am assume $http.get is angularjs) don't do it.

Also I would propose to change the log rest functions such that a problem like this is a bit more obvious:

--- a/cmd/syncthing/gui.go
+++ b/cmd/syncthing/gui.go
@@ -955,20 +955,36 @@ func (s *apiService) postSystemErrorClear(w http.ResponseWriter, r *http.Request
 
 func (s *apiService) getSystemLog(w http.ResponseWriter, r *http.Request) {
 	q := r.URL.Query()
-	since, err := time.Parse(time.RFC3339, q.Get("since"))
-	l.Debugln(err)
+	var t time.Time
+	if since := q.Get("since"); since != "" {
+		var err error
+		if t, err = time.Parse(time.RFC3339, since); err != nil {
+			l.Debugln(err)
+			http.Error(w, err.Error(), 400)
+			return
+		}
+	}
+
 	sendJSON(w, map[string][]logger.Line{
-		"messages": s.systemLog.Since(since),
+		"messages": s.systemLog.Since(t),
 	})
 }
 
 func (s *apiService) getSystemLogTxt(w http.ResponseWriter, r *http.Request) {
 	q := r.URL.Query()
-	since, err := time.Parse(time.RFC3339, q.Get("since"))
-	l.Debugln(err)
+	var t time.Time
+	if since := q.Get("since"); since != "" {
+		var err error
+		if t, err = time.Parse(time.RFC3339, since); err != nil {
+			l.Debugln(err)
+			http.Error(w, err.Error(), 400)
+			return
+		}
+	}
+
 	w.Header().Set("Content-Type", "text/plain; charset=utf-8")
 
-	for _, line := range s.systemLog.Since(since) {
+	for _, line := range s.systemLog.Since(t) {
 		fmt.Fprintf(w, "%s: %s\n", line.When.Format(time.RFC3339), line.Message)
 	}
 }

@canton7
Copy link
Member

canton7 commented Dec 19, 2017

Apparently you should use encodeURIComponent with $http.get.

How does the library know whether you mean a literal + or not?

You pass in some values. They're url encoded. The server url decodes them, and gets your values. If you pass in a +, that's urlencoded to %2B and the server decodes it to +. If you pass in a , that's urlencoded to + and the server decodes it to .

@imsodin
Copy link
Member

imsodin commented Dec 19, 2017

That's it - using encodeURIComponent on last the log display (including trailing) works smoothly here.

<div id="log-viewer-log" class="tab-pane in active">
<label translate ng-if="logging.logEntries.length == 0">Loading...</label>
<textarea ng-focus="logging.paused = true" ng-blur="logging.paused = false" id="logViewerText" class="form-control" rows="20" ng-if="logging.logEntries.length != 0" readonly style="font-family: Consolas; font-size: 11px; overflow: auto;">{{ logging.content() }}</textarea>
<p translate class="help-block" ng-style="{'visibility': logging.paused ? 'visible' : 'hidden'}">Log tailing paused. Click here to continue</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The click on me as text seems fine and better than the new "Click anywhere..." proposal: Otherwise someone might click on the background and complain when the log modal disappears :P
I would add a dot (or three) at the end though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three dots to existing text?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent (first sentence gets a final dot): "Log tailing paused. Click here to continue."
On second thought, I don't like three dots ("continue..."). The idea was, that it signifies that something (trailing) will continue when you click, but that seems unnecessary and might be a problem for translation.

@imsodin
Copy link
Member

imsodin commented Dec 21, 2017

@calmh The mac agent is missing - is it a planned "revision outage" or something unforeseen? More to the point: Will it be up soon(ish) or should we start skipping that test to merge stuff?

Apart from the very nitpicky comment about punctuation, this is lgtm.

@calmh
Copy link
Member

calmh commented Dec 21, 2017 via email

@imsodin
Copy link
Member

imsodin commented Dec 21, 2017

Translation strings need to be updated.

@AudriusButkevicius
Copy link
Member Author

@calmh does that before every release anyway

@calmh
Copy link
Member

calmh commented Dec 24, 2017

@st-review lgtm

@st-review
Copy link

@calmh: Noted! Need another LGTM or explicit merge command.

@calmh
Copy link
Member

calmh commented Dec 24, 2017

I think the viewer deserves to be full screen and not a modal but that's a valid future improvement and this is great as is.

@AudriusButkevicius
Copy link
Member Author

@imsodin needs to leave his mark.

@imsodin
Copy link
Member

imsodin commented Dec 24, 2017

@st-review lgtm

@st-review
Copy link

👌 Merged as c58b383. Thanks, @AudriusButkevicius!

@st-review st-review closed this Dec 24, 2017
st-review pushed a commit that referenced this pull request Dec 24, 2017
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: #4604
LGTM: calmh, imsodin
@st-review st-review added the pr-merged Legacy label used in the past for pull requests merged to the main tree label Jan 15, 2018
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Dec 25, 2018
@syncthing syncthing locked and limited conversation to collaborators Dec 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion pr-merged Legacy label used in the past for pull requests merged to the main tree
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants