UNPKG

3.24 kBJavaScriptView Raw
1// Copyright (c) 2015 Uber Technologies, Inc.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21var test = require('tape');
22
23var FileLogger = require('./lib/file-logger.js');
24
25test('can .error("message", new Error())', function (assert) {
26 var logger = FileLogger();
27
28 logger.error('hello', new Error('lulz'), function (err) {
29 assert.ifError(err);
30
31 logger.readFile(function (err, file) {
32 assert.ifError(err);
33
34 assert.notEqual(file.indexOf('error: hello'), -1);
35 assert.notEqual(file.indexOf('message=lulz'), -1);
36 assert.notEqual(
37 file.indexOf('stack=Error: lulz'), -1);
38
39 logger.destroy();
40 assert.end();
41 });
42 });
43});
44
45test('can error("message", { error: Error() })', function (assert) {
46 var logger = FileLogger();
47
48 logger.error('some message', {
49 error: new Error('some error'),
50 other: 'key'
51 }, function (err) {
52 assert.ifError(err);
53
54 logger.readFile(function (err, file) {
55 assert.ifError(err);
56
57 assert.notEqual(
58 file.indexOf('error: some message'), -1);
59 assert.notEqual(
60 file.indexOf('message=some error'), -1);
61 assert.notEqual(
62 file.indexOf('stack=Error: some error'), -1);
63 assert.notEqual(file.indexOf('other=key'), -1);
64
65 logger.destroy();
66 assert.end();
67 });
68 });
69});
70
71test('can error(msg, { someKey: Error() })', function (assert) {
72 var logger = FileLogger();
73
74 logger.error('some message', {
75 someKey: new Error('some error'),
76 other: 'key'
77 }, function (err) {
78 assert.ifError(err);
79
80 logger.readFile(function (err, file) {
81 assert.ifError(err);
82
83 assert.notEqual(
84 file.indexOf('error: some message'), -1);
85 assert.notEqual(
86 file.indexOf('message=some error'), -1);
87 assert.notEqual(
88 file.indexOf('stack=Error: some error'), -1);
89 assert.notEqual(file.indexOf('other=key'), -1);
90
91 logger.destroy();
92 assert.end();
93 });
94 });
95});