@@ -6,13 +6,14 @@ var PassThrough = require('stream').PassThrough;
6
6
7
7
// external requires
8
8
var assert = require ( 'chai' ) . assert ;
9
- var bunyan = require ( 'bunyan ' ) ;
9
+ var pino = require ( 'pino ' ) ;
10
10
var lodash = require ( 'lodash' ) ;
11
11
var restify = require ( '../../lib/index.js' ) ;
12
12
var restifyClients = require ( 'restify-clients' ) ;
13
13
14
14
// local files
15
15
var helper = require ( '../lib/helper' ) ;
16
+ var StreamRecorder = require ( '../lib/streamRecorder' ) ;
16
17
var vasync = require ( 'vasync' ) ;
17
18
18
19
// local globals
@@ -51,22 +52,12 @@ describe('audit logger', function() {
51
52
} ) ;
52
53
53
54
it ( 'audit logger should print log by default' , function ( done ) {
54
- var logBuffer = new bunyan . RingBuffer ( {
55
- limit : 1000
56
- } ) ;
55
+ var logBuffer = new StreamRecorder ( ) ;
57
56
var collectLog ;
58
57
SERVER . on (
59
58
'after' ,
60
59
restify . plugins . auditLogger ( {
61
- log : bunyan . createLogger ( {
62
- name : 'audit' ,
63
- streams : [
64
- {
65
- level : 'info' ,
66
- stream : process . stdout
67
- }
68
- ]
69
- } ) ,
60
+ log : pino ( { name : 'audit' } , logBuffer ) ,
70
61
server : SERVER ,
71
62
event : 'after'
72
63
} )
@@ -126,15 +117,7 @@ describe('audit logger', function() {
126
117
SERVER . once (
127
118
'after' ,
128
119
restify . plugins . auditLogger ( {
129
- log : bunyan . createLogger ( {
130
- name : 'audit' ,
131
- streams : [
132
- {
133
- level : 'info' ,
134
- stream : process . stdout
135
- }
136
- ]
137
- } ) ,
120
+ log : pino ( { name : 'audit' } ) ,
138
121
server : SERVER ,
139
122
event : 'after'
140
123
} )
@@ -166,22 +149,13 @@ describe('audit logger', function() {
166
149
} ) ;
167
150
168
151
it ( 'test custom serializers' , function ( done ) {
169
- // Dirty hack to capture the log record using a ring buffer.
170
- var ringbuffer = new bunyan . RingBuffer ( { limit : 1 } ) ;
152
+ // capture the log record
153
+ var buffer = new StreamRecorder ( ) ;
171
154
172
155
SERVER . once (
173
156
'after' ,
174
157
restify . plugins . auditLogger ( {
175
- log : bunyan . createLogger ( {
176
- name : 'audit' ,
177
- streams : [
178
- {
179
- level : 'info' ,
180
- type : 'raw' ,
181
- stream : ringbuffer
182
- }
183
- ]
184
- } ) ,
158
+ log : pino ( { name : 'audit' } , buffer ) ,
185
159
event : 'after' ,
186
160
serializers : {
187
161
req : function ( req ) {
@@ -200,7 +174,7 @@ describe('audit logger', function() {
200
174
} ) ;
201
175
202
176
SERVER . on ( 'after' , function ( ) {
203
- var record = ringbuffer . records && ringbuffer . records [ 0 ] ;
177
+ var record = buffer . records && buffer . records [ 0 ] ;
204
178
assert . equal ( record . req . fooReq , 'barReq' ) ;
205
179
assert . equal ( record . res . fooRes , 'barRes' ) ;
206
180
done ( ) ;
@@ -212,23 +186,14 @@ describe('audit logger', function() {
212
186
} ) ;
213
187
214
188
it ( 'should log handler timers' , function ( done ) {
215
- // Dirty hack to capture the log record using a ring buffer.
216
- var ringbuffer = new bunyan . RingBuffer ( { limit : 1 } ) ;
189
+ // capture the log record
190
+ var buffer = new StreamRecorder ( ) ;
217
191
var WAIT_IN_MILLISECONDS = 1100 ;
218
192
219
193
SERVER . once (
220
194
'after' ,
221
195
restify . plugins . auditLogger ( {
222
- log : bunyan . createLogger ( {
223
- name : 'audit' ,
224
- streams : [
225
- {
226
- level : 'info' ,
227
- type : 'raw' ,
228
- stream : ringbuffer
229
- }
230
- ]
231
- } ) ,
196
+ log : pino ( { name : 'audit' } , buffer ) ,
232
197
event : 'after'
233
198
} )
234
199
) ;
@@ -246,12 +211,12 @@ describe('audit logger', function() {
246
211
} ) ;
247
212
248
213
SERVER . on ( 'after' , function ( ) {
249
- var record = ringbuffer . records && ringbuffer . records [ 0 ] ;
214
+ var record = buffer . records && buffer . records [ 0 ] ;
250
215
251
216
// check timers
252
217
assert . ok ( record , 'no log records' ) ;
253
218
assert . equal (
254
- ringbuffer . records . length ,
219
+ buffer . records . length ,
255
220
1 ,
256
221
'should only have 1 log record'
257
222
) ;
@@ -290,23 +255,14 @@ describe('audit logger', function() {
290
255
it ( 'should log anonymous handler timers' , function ( done ) {
291
256
this . timeout ( 5000 ) ;
292
257
293
- // Dirty hack to capture the log record using a ring buffer.
294
- var ringbuffer = new bunyan . RingBuffer ( { limit : 1 } ) ;
258
+ // capture the log record
259
+ var buffer = new StreamRecorder ( ) ;
295
260
var WAIT_IN_MILLISECONDS = 1000 ;
296
261
297
262
SERVER . once (
298
263
'after' ,
299
264
restify . plugins . auditLogger ( {
300
- log : bunyan . createLogger ( {
301
- name : 'audit' ,
302
- streams : [
303
- {
304
- level : 'info' ,
305
- type : 'raw' ,
306
- stream : ringbuffer
307
- }
308
- ]
309
- } ) ,
265
+ log : pino ( { name : 'audit' } , buffer ) ,
310
266
event : 'after'
311
267
} )
312
268
) ;
@@ -345,10 +301,10 @@ describe('audit logger', function() {
345
301
346
302
SERVER . on ( 'after' , function ( ) {
347
303
// check timers
348
- var record = ringbuffer . records && ringbuffer . records [ 0 ] ;
304
+ var record = buffer . records && buffer . records [ 0 ] ;
349
305
assert . ok ( record , 'no log records' ) ;
350
306
assert . equal (
351
- ringbuffer . records . length ,
307
+ buffer . records . length ,
352
308
1 ,
353
309
'should only have 1 log record'
354
310
) ;
@@ -415,23 +371,14 @@ describe('audit logger', function() {
415
371
} ) ;
416
372
417
373
it ( 'restify-GH-1435 should accumulate log handler timers' , function ( done ) {
418
- // Dirty hack to capture the log record using a ring buffer.
419
- var ringbuffer = new bunyan . RingBuffer ( { limit : 1 } ) ;
374
+ // capture the log record
375
+ var buffer = new StreamRecorder ( ) ;
420
376
var WAIT_IN_MILLISECONDS = 1100 ;
421
377
422
378
SERVER . once (
423
379
'after' ,
424
380
restify . plugins . auditLogger ( {
425
- log : bunyan . createLogger ( {
426
- name : 'audit' ,
427
- streams : [
428
- {
429
- level : 'info' ,
430
- type : 'raw' ,
431
- stream : ringbuffer
432
- }
433
- ]
434
- } ) ,
381
+ log : pino ( { name : 'audit' } , buffer ) ,
435
382
event : 'after'
436
383
} )
437
384
) ;
@@ -452,12 +399,12 @@ describe('audit logger', function() {
452
399
} ) ;
453
400
454
401
SERVER . on ( 'after' , function ( ) {
455
- var record = ringbuffer . records && ringbuffer . records [ 0 ] ;
402
+ var record = buffer . records && buffer . records [ 0 ] ;
456
403
457
404
// check timers
458
405
assert . ok ( record , 'no log records' ) ;
459
406
assert . equal (
460
- ringbuffer . records . length ,
407
+ buffer . records . length ,
461
408
1 ,
462
409
'should only have 1 log record'
463
410
) ;
@@ -482,22 +429,13 @@ describe('audit logger', function() {
482
429
} ) ;
483
430
484
431
it ( 'restify-GH-812 audit logger has query params string' , function ( done ) {
485
- // Dirty hack to capture the log record using a ring buffer.
486
- var ringbuffer = new bunyan . RingBuffer ( { limit : 1 } ) ;
432
+ // capture the log record
433
+ var buffer = new StreamRecorder ( ) ;
487
434
488
435
SERVER . once (
489
436
'after' ,
490
437
restify . plugins . auditLogger ( {
491
- log : bunyan . createLogger ( {
492
- name : 'audit' ,
493
- streams : [
494
- {
495
- level : 'info' ,
496
- type : 'raw' ,
497
- stream : ringbuffer
498
- }
499
- ]
500
- } ) ,
438
+ log : pino ( { name : 'audit' } , buffer ) ,
501
439
event : 'after'
502
440
} )
503
441
) ;
@@ -509,13 +447,13 @@ describe('audit logger', function() {
509
447
510
448
SERVER . on ( 'after' , function ( ) {
511
449
// check timers
512
- assert . ok ( ringbuffer . records [ 0 ] , 'no log records' ) ;
450
+ assert . ok ( buffer . records [ 0 ] , 'no log records' ) ;
513
451
assert . equal (
514
- ringbuffer . records . length ,
452
+ buffer . records . length ,
515
453
1 ,
516
454
'should only have 1 log record'
517
455
) ;
518
- assert . ok ( ringbuffer . records [ 0 ] . req . query , 'a=1&b=2' ) ;
456
+ assert . ok ( buffer . records [ 0 ] . req . query , 'a=1&b=2' ) ;
519
457
done ( ) ;
520
458
} ) ;
521
459
@@ -525,22 +463,13 @@ describe('audit logger', function() {
525
463
} ) ;
526
464
527
465
it ( 'restify-GH-812 audit logger has query params obj' , function ( done ) {
528
- // Dirty hack to capture the log record using a ring buffer.
529
- var ringbuffer = new bunyan . RingBuffer ( { limit : 1 } ) ;
466
+ // capture the log record using a buffer.
467
+ var buffer = new StreamRecorder ( ) ;
530
468
531
469
SERVER . once (
532
470
'after' ,
533
471
restify . plugins . auditLogger ( {
534
- log : bunyan . createLogger ( {
535
- name : 'audit' ,
536
- streams : [
537
- {
538
- level : 'info' ,
539
- type : 'raw' ,
540
- stream : ringbuffer
541
- }
542
- ]
543
- } ) ,
472
+ log : pino ( { name : 'audit' } , buffer ) ,
544
473
event : 'after'
545
474
} )
546
475
) ;
@@ -555,13 +484,13 @@ describe('audit logger', function() {
555
484
556
485
SERVER . on ( 'after' , function ( ) {
557
486
// check timers
558
- assert . ok ( ringbuffer . records [ 0 ] , 'no log records' ) ;
487
+ assert . ok ( buffer . records [ 0 ] , 'no log records' ) ;
559
488
assert . equal (
560
- ringbuffer . records . length ,
489
+ buffer . records . length ,
561
490
1 ,
562
491
'should only have 1 log record'
563
492
) ;
564
- assert . deepEqual ( ringbuffer . records [ 0 ] . req . query , {
493
+ assert . deepEqual ( buffer . records [ 0 ] . req . query , {
565
494
a : '1' ,
566
495
b : '2'
567
496
} ) ;
@@ -579,15 +508,7 @@ describe('audit logger', function() {
579
508
SERVER . once (
580
509
'pre' ,
581
510
restify . plugins . auditLogger ( {
582
- log : bunyan . createLogger ( {
583
- name : 'audit' ,
584
- streams : [
585
- {
586
- level : 'info' ,
587
- stream : ptStream
588
- }
589
- ]
590
- } ) ,
511
+ log : pino ( { name : 'audit' } , ptStream ) ,
591
512
event : 'pre'
592
513
} )
593
514
) ;
@@ -620,15 +541,7 @@ describe('audit logger', function() {
620
541
SERVER . once (
621
542
'routed' ,
622
543
restify . plugins . auditLogger ( {
623
- log : bunyan . createLogger ( {
624
- name : 'audit' ,
625
- streams : [
626
- {
627
- level : 'info' ,
628
- stream : ptStream
629
- }
630
- ]
631
- } ) ,
544
+ log : pino ( { name : 'audit' } , ptStream ) ,
632
545
event : 'routed'
633
546
} )
634
547
) ;
@@ -659,15 +572,7 @@ describe('audit logger', function() {
659
572
SERVER . once (
660
573
'after' ,
661
574
restify . plugins . auditLogger ( {
662
- log : bunyan . createLogger ( {
663
- name : 'audit' ,
664
- streams : [
665
- {
666
- level : 'info' ,
667
- stream : process . stdout
668
- }
669
- ]
670
- } ) ,
575
+ log : pino ( { name : 'audit' } ) ,
671
576
context : function ( req , res , route , err ) {
672
577
return {
673
578
qs : req . getQuery ( )
@@ -704,15 +609,7 @@ describe('audit logger', function() {
704
609
SERVER . once (
705
610
'after' ,
706
611
restify . plugins . auditLogger ( {
707
- log : bunyan . createLogger ( {
708
- name : 'audit' ,
709
- streams : [
710
- {
711
- level : 'info' ,
712
- stream : process . stdout
713
- }
714
- ]
715
- } ) ,
612
+ log : pino ( { name : 'audit' } ) ,
716
613
server : SERVER ,
717
614
event : 'after'
718
615
} )
0 commit comments