]>
git.r.bdr.sh - rbdr/cologne/blob - test/cologne/logger/file.js
01be09f150718c9a795730c9083da340e4c56a40
3 let fs
= require('fs');
5 let tap
= require('tap');
7 let FileLogger
= require('../../../lib/cologne/logger/file');
10 let logObjectA
, logObjectB
, rawFile
, formatterFile
, rawLogger
, formatterLogger
,
11 params
, dummyFormatter
, formatterString
;
13 rawFile
= './raw.log';
14 formatterFile
= './formatter.log';
15 formatterString
= 'example';
18 _timestamp: Date
.now() + .134,
20 _from: 'Dummy Logger',
27 _timestamp: Date
.now() + .134,
29 _from: 'Dummy Logger',
35 params
= [logObjectA
, logObjectB
];
40 format: function (logObject
) {
41 this.values
.push(logObject
);
42 return formatterString
;
46 rawLogger
= new FileLogger({
49 formatterLogger
= new FileLogger({
51 formatter: dummyFormatter
55 * TEST: #log() - regular
58 rawLogger
.log
.apply(rawLogger
, params
);
60 setTimeout(function () {
61 tap
.test('raw file', function (t
) {
62 fs
.readFile(rawFile
, {encoding: 'utf8'}, function (error
, contents
) {
65 lines
= contents
.trim().split('\n');
67 tap
.equal(lines
.length
, params
.length
,
68 'it should send all params to the file');
70 tap
.equal(JSON
.stringify(logObjectA
), lines
[0],
71 'it should log the raw json object');
73 fs
.unlink(rawFile
, function () {
78 }, 10); // allow for flush
80 * TEST: #log() - formatter
83 formatterLogger
.log
.apply(formatterLogger
, params
);
85 setTimeout(function () {
86 tap
.test('formatted file', function (t
) {
87 fs
.readFile(formatterFile
, {encoding: 'utf8'}, function (error
, contents
) {
90 lines
= contents
.trim().split('\n');
92 tap
.equal(lines
.length
, params
.length
,
93 'it should send all params to the file');
95 tap
.equal(formatterString
, lines
[0],
96 'it should log the formatted object');
98 fs
.unlink(formatterFile
, function () {