From 7274188494f6fd343d9a917fa8de642807e9bba4 Mon Sep 17 00:00:00 2001 From: Robert Kowalski Date: Sat, 12 Apr 2014 15:34:10 +0200 Subject: [PATCH] Fauxton: do not slice off the error text from erlang errors As the erlang errors contain two linebreaks, and the parsing function is using linebreaks to separate the messages, the content was sliced off, which looked like there would not be enough space for the message. In fact it got lost during the parsing. This tries to normalize the data before and after the parsing, it removes the linebreaks of the erlang errors so it is parsed right. As the other spaces are no &nspb;-entities it does not hurt that the are removed. --- src/Makefile.am | 3 +- src/fauxton/app/addons/logs/resources.js | 7 ++- .../logs/tests/{logSpec.js => baseSpec.js} | 0 .../app/addons/logs/tests/resourcesSpec.js | 58 +++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) rename src/fauxton/app/addons/logs/tests/{logSpec.js => baseSpec.js} (100%) create mode 100644 src/fauxton/app/addons/logs/tests/resourcesSpec.js diff --git a/src/Makefile.am b/src/Makefile.am index 07ee5e150e..ea1a11ba36 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -84,7 +84,8 @@ FAUXTON_FILES = \ fauxton/app/addons/logs/templates/dashboard.html \ fauxton/app/addons/logs/templates/filterItem.html \ fauxton/app/addons/logs/templates/sidebar.html \ - fauxton/app/addons/logs/tests/logSpec.js \ + fauxton/app/addons/logs/tests/baseSpec.js \ + fauxton/app/addons/logs/tests/resourcesSpec.js \ fauxton/app/addons/permissions/assets/less/permissions.less \ fauxton/app/addons/permissions/base.js \ fauxton/app/addons/permissions/resources.js \ diff --git a/src/fauxton/app/addons/logs/resources.js b/src/fauxton/app/addons/logs/resources.js index 3a47b92614..9251ab559c 100644 --- a/src/fauxton/app/addons/logs/resources.js +++ b/src/fauxton/app/addons/logs/resources.js @@ -51,7 +51,7 @@ function (app, FauxtonAPI, Backbone) { initialize: function (options) { this.params = {bytes: 5000}; }, - + documentation: "log", url: function () { @@ -68,7 +68,8 @@ function (app, FauxtonAPI, Backbone) { }, parse: function (resp) { - var lines = resp.split(/\n/); + resp = resp.replace(/\n\s/g, ''); + var lines = resp.split(/\n/); return _.foldr(lines, function (acc, logLine) { var match = logLine.match(/^\[(.*?)\]\s\[(.*?)\]\s\[(.*?)\]\s(.*)/); @@ -78,7 +79,7 @@ function (app, FauxtonAPI, Backbone) { date: match[1], log_level: match[2], pid: match[3], - args: match[4] + args: match[4].replace(/\s\s+/g, '') }); return acc; diff --git a/src/fauxton/app/addons/logs/tests/logSpec.js b/src/fauxton/app/addons/logs/tests/baseSpec.js similarity index 100% rename from src/fauxton/app/addons/logs/tests/logSpec.js rename to src/fauxton/app/addons/logs/tests/baseSpec.js diff --git a/src/fauxton/app/addons/logs/tests/resourcesSpec.js b/src/fauxton/app/addons/logs/tests/resourcesSpec.js new file mode 100644 index 0000000000..5bdd339e41 --- /dev/null +++ b/src/fauxton/app/addons/logs/tests/resourcesSpec.js @@ -0,0 +1,58 @@ +// Licensed under the Apache License, Version 2.0 (the 'License'); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +define([ + 'addons/logs/resources', + 'testUtils' +], function (Log, testUtils) { + var assert = testUtils.assert; + + describe('Logs Resources', function () { + + describe('Log Parser', function () { + it('parses GET messages', function () { + var parsedLog, + collection, + log = '[Sat, 12 Apr 2014 13:02:58 GMT] [info] [<0.3097.2>] 127.0.0.1 - - GET /_session 200\n' + + '[Sat, 12 Apr 2014 13:02:58 GMT] [info] [<0.3098.2>] 127.0.0.1 - - GET /_session 200\n' + + '[Sat, 12 Apr 2014 13:02:58 GMT] [info] [<0.3099.2>] 127.0.0.1 - - GET / 200\n'; + + collection = new Log.Collection(); + parsedLog = collection.parse(log); + assert.equal(parsedLog[0].date, 'Sat, 12 Apr 2014 13:02:58 GMT'); + assert.equal(parsedLog[0].args, '127.0.0.1 - - GET / 200'); + }); + + it('parses GET messages with erlang errors', function () { + var parsedLog, + collection, + log = '[Sat, 12 Apr 2014 13:14:15 GMT] [info] [<0.9491.2>] Retrying GET to http://176.9.4.195/registry/genstatic?revs=true&open_revs=%5B%224-a9be203658a59fd2116ae9acbd10f0de%22%5D&latest=true in 1.0 seconds due to error {error,\n' + + ' {error,\n' + + ' connection_closing}}\n' + + '[Sat, 12 Apr 2014 13:14:15 GMT] [error] [<0.9499.2>] Replicator, request GET to "http://176.9.4.195/registry/google-openid?revs=true&open_revs=%5B%2219-380884ba97e3d6fc48c8c7db3dc0e91b%22%5D&latest=true" failed due to error {error,connection_closing}\n' + + '[Sat, 12 Apr 2014 13:14:15 GMT] [info] [<0.9497.2>] Retrying GET to http://176.9.4.195/registry/google-openid?revs=true&open_revs=%5B%2219-380884ba97e3d6fc48c8c7db3dc0e91b%22%5D&latest=true in 1.0 seconds due to error {error,\n' + + ' {error,\n' + + ' connection_closing}}\n' + + '[Sat, 12 Apr 2014 13:14:15 GMT] [error] [<0.9507.2>] Replicator, request GET to "http://176.9.4.195/registry/google-openid?revs=true&open_revs=%5B%224-c8ba4809e2cacc1635f8887ec0d8d49a%22%5D&latest=true" failed due to error {error,connection_closing}\n' + + '[Sat, 12 Apr 2014 13:14:15 GMT] [info] [<0.9505.2>] Retrying GET to http://176.9.4.195/registry/google-openid?revs=true&open_revs=%5B%224-c8ba4809e2cacc1635f8887ec0d8d49a%22%5D&latest=true in 1.0 seconds due to error {error,\n' + + ' {error,\n' + + ' connection_closing}}\n'; + + collection = new Log.Collection(); + parsedLog = collection.parse(log); + assert.equal(parsedLog[1].date, 'Sat, 12 Apr 2014 13:14:15 GMT'); + assert.equal(parsedLog[1].args, 'Replicator, request GET to "http://176.9.4.195/registry/google-openid?revs=true&open_revs=%5B%224-c8ba4809e2cacc1635f8887ec0d8d49a%22%5D&latest=true" failed due to error {error,connection_closing}'); + assert.equal(parsedLog[2].args, 'Retrying GET to http://176.9.4.195/registry/google-openid?revs=true&open_revs=%5B%2219-380884ba97e3d6fc48c8c7db3dc0e91b%22%5D&latest=true in 1.0 seconds due to error {error,{error,connection_closing}}'); + }); + }); + }); +});