File size: 884 Bytes
19605ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';

// This module knows how to wire together a
// rotating file stream and a rotation trigger

function TriggerAdapter(trigger, rfs) {
    var onRotate = function (triggerinfo) {
        rfs.rotate(triggerinfo);
    };

    var onNewFile = function (data) {
        trigger.newFile(data);
    };

    var onLogWrite = function (data) {
        trigger.logWrite(data);
    };

    var onShutdown = function () {
        trigger.shutdown();

        trigger.removeListener('rotate', onRotate);
        rfs.removeListener('newfile', onNewFile);
        rfs.removeListener('logwrite', onLogWrite);
        rfs.removeListener('shutdown', onShutdown);
    }

    trigger.on('rotate', onRotate);

    rfs.on('newfile', onNewFile);
    rfs.on('logwrite', onLogWrite);
    rfs.on('shutdown', onShutdown);

    return { onShutdown: onShutdown };
}

module.exports = TriggerAdapter;