diff options
author | Robert Kowalski <rok@kowalski.gd> | 2014-04-12 15:34:10 +0200 |
---|---|---|
committer | suelockwood <deathbear@apache.org> | 2014-04-17 16:17:36 -0400 |
commit | e3239f195e6058bfb48878e393a0334383b08474 (patch) | |
tree | 959fb215363d219a88ff97aba6c4f93f6c488940 /src | |
parent | 174e7596e2cabb76131bd85948aee162831706be (diff) | |
download | couchdb-e3239f195e6058bfb48878e393a0334383b08474.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/fauxton/app/addons/logs/resources.js | 5 | ||||
-rw-r--r-- | src/fauxton/app/addons/logs/tests/resourcesSpec.js | 48 |
2 files changed, 37 insertions, 16 deletions
diff --git a/src/fauxton/app/addons/logs/resources.js b/src/fauxton/app/addons/logs/resources.js index c285395be..6082fcd7c 100644 --- a/src/fauxton/app/addons/logs/resources.js +++ b/src/fauxton/app/addons/logs/resources.js @@ -67,7 +67,8 @@ function (app, FauxtonAPI, Backbone, d3) { }, 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(.*)/); @@ -77,7 +78,7 @@ function (app, FauxtonAPI, Backbone, d3) { 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/resourcesSpec.js b/src/fauxton/app/addons/logs/tests/resourcesSpec.js index d67c67718..5bdd339e4 100644 --- a/src/fauxton/app/addons/logs/tests/resourcesSpec.js +++ b/src/fauxton/app/addons/logs/tests/resourcesSpec.js @@ -16,22 +16,42 @@ define([ ], function (Log, testUtils) { var assert = testUtils.assert; - describe('Log Resources', function () { + describe('Logs Resources', function () { - describe('Date Formatter', function () { - it('adds leading zeros to minutes', function () { - var model; + 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'; - model = new Log.Model({ - date: 'Sat, 12 Apr 2014 15:04:01 GMT', - log_level: 'info', - pid: '123', - args: 'ente ente' - }); - // timezones with daylightsaving in JS are hard - // and we use the current local time here - // so do not test for hours and the exact day - assert.ok(/Apr \d\d \d\d:04:01/.test(model.date())); + 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}}'); }); }); }); |