UNPKG

3.6 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
21'use strict';
22
23var test = require('tape');
24
25var captureStdio = require('./lib/capture-stdio.js');
26var ConsoleLogger = require('./lib/console-logger.js');
27var FileLogger = require('./lib/file-logger.js');
28var SentryLogger = require('./lib/sentry-logger.js');
29var KafkaLogger = require('./lib/kafka-logger.js');
30
31test('writing a circular object (console)', function t(assert) {
32 var logger = ConsoleLogger();
33
34 var circular = allocCircularLol();
35
36 assert.ok(captureStdio('info: cool story', function log() {
37 logger.info('cool story', circular, function (err) {
38 assert.ifError(err);
39
40 logger.destroy();
41 assert.end();
42 });
43 }));
44});
45
46test('writing a circular object (disk)', function t(assert) {
47 var logger = FileLogger();
48
49 var circular = allocCircularLol();
50
51 logger.info('cool story', circular, function log(err) {
52 assert.ifError(err);
53
54 logger.readFile(function (err, buf) {
55 assert.ifError(err);
56
57 assert.ok(buf.indexOf('info: cool story') !== -1);
58
59 logger.destroy();
60 assert.end();
61 });
62 });
63});
64
65test('writing a circular object (sentry)', function t(assert) {
66 var messages = [];
67 var logger = SentryLogger(function listener(msg) {
68 messages.push(msg);
69
70 if (messages.length === 1) {
71 onLogged();
72 }
73 });
74
75 var circular = allocCircularLol();
76
77 logger.error('cool story', circular);
78
79 function onLogged() {
80 var msg = messages[0];
81
82 assert.ok(msg.message.indexOf('cool story') !== -1);
83
84 logger.destroy();
85 assert.end();
86 }
87});
88
89test('writing a circular object (kafka)', function t(assert) {
90 var messages = [];
91 var logger = KafkaLogger(function listener(err, msg) {
92 assert.ifError(err, 'no unexpected server error');
93 messages.push(msg);
94
95 if (messages.length === 1) {
96 onLogged();
97 }
98 });
99
100 var circular = allocCircularLol();
101
102 logger.info('cool story', circular);
103
104 function onLogged() {
105 var msg = messages[0];
106
107 var payload = msg.messages[0].payload;
108
109 assert.ok(payload.msg.indexOf('cool story') !== -1);
110
111 logger.destroy();
112 assert.end();
113 }
114});
115
116function allocCircularLol() {
117 var circular = {};
118 circular.lol = 'lol';
119 circular.circular = circular;
120 circular.pwnt = {};
121 circular.pwnt.circular = circular;
122
123 return circular;
124}