UNPKG

1.28 kBJavaScriptView Raw
1/*
2 * Copyright 2012 Amadeus s.a.s.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16var fs = require('fs');
17
18var JsonLogReport = function (file) {
19 this._stream = fs.createWriteStream(file);
20 this._stream.write('[');
21 this._first = true;
22};
23
24JsonLogReport.prototype = {};
25
26JsonLogReport.prototype.addResult = function (event) {
27 if (this._stream) {
28 var value = JSON.stringify(event);
29 if (this._first) {
30 this._first = false;
31 } else {
32 this._stream.write(',\n');
33 }
34 this._stream.write(value);
35 if (event.event == "campaignFinished") {
36 this._stream.end(']');
37 this._stream.destroySoon();
38 this._stream = null;
39 }
40 }
41};
42
43module.exports = JsonLogReport;