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 | ;
|
22 |
|
23 | var test = require('tape');
|
24 |
|
25 | var captureStdio = require('./lib/capture-stdio.js');
|
26 | var ConsoleLogger = require('./lib/console-logger.js');
|
27 | var FileLogger = require('./lib/file-logger.js');
|
28 |
|
29 | test('writing a buffer object (console)', function t(assert) {
|
30 | var logger = ConsoleLogger({
|
31 | raw: true
|
32 | });
|
33 |
|
34 | var meta = allocMeta();
|
35 |
|
36 | assert.ok(captureStdio(
|
37 | '{"someKey":"hi","some":{"nestedKey":"oh hi"},' +
|
38 | '"level":"info","message":"cool story"}',
|
39 | function log() {
|
40 | logger.info('cool story', meta, function cb(err) {
|
41 | assert.ifError(err);
|
42 |
|
43 | logger.destroy();
|
44 | assert.end();
|
45 | });
|
46 | }));
|
47 | });
|
48 |
|
49 | test('writing a buffer object (disk)', function t(assert) {
|
50 | var logger = FileLogger({
|
51 | json: true
|
52 | });
|
53 |
|
54 | var meta = allocMeta();
|
55 |
|
56 | logger.info('cool story', meta, function log(err) {
|
57 | assert.ifError(err);
|
58 |
|
59 | logger.readFile(function onFile(err2, buf) {
|
60 | assert.ifError(err2);
|
61 |
|
62 | assert.notEqual(
|
63 | buf.indexOf(
|
64 | '{"someKey":"hi","some":{"nestedKey":"oh hi"},' +
|
65 | '"level":"info","message":"cool story"'
|
66 | ),
|
67 | -1
|
68 | );
|
69 |
|
70 | logger.destroy();
|
71 | assert.end();
|
72 | });
|
73 | });
|
74 | });
|
75 |
|
76 | function allocMeta() {
|
77 | var meta = {};
|
78 | meta.someKey = 'hi';
|
79 | meta.some = {
|
80 | nestedKey: 'oh hi'
|
81 | };
|
82 |
|
83 | return meta;
|
84 | }
|