every-second-test.js
2.48 KB
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
39
40
41
42
43
44
45
var moment = require('moment');
// var rotatingLogStream = require('../FileStreamRotator').getStream({filename:"/tmp/testlog-%DATE%.log", frequency:"1m", verbose: true});
// var rotatingLogStream = require('../FileStreamRotator').getStream({filename:"/tmp/testlog-%DATE%.log", frequency:"custom", verbose: true, date_format: "YYYY-MM-DD.HH.mm"});
// var rotatingLogStream = require('../FileStreamRotator').getStream({filename:"/tmp/testlog-%DATE%.log", frequency:"dont-rotate", verbose: true, date_format: "YYYY-MM-DD.HH.mm.ss"});
// var rotatingLogStream = require('../FileStreamRotator').getStream({filename:"/tmp/testlog-%DATE%.log", frequency:"daily", verbose: true, date_format: "YYYYMMDD"});
// var rotatingLogStream = require('../FileStreamRotator').getStream({filename:"/tmp/testlog-%DATE%.log", frequency:"daily", verbose: true});
var rotatingLogStream = require('../FileStreamRotator').getStream({filename:"logs/%DATE%/a/b/c/d/e/f/g/testlog-%DATE%.log", frequency:"custom", verbose: true, date_format: "YYYY-MM-DD.HH.mm", size:"0.5M"});
rotatingLogStream.on("error",function(){
console.log(Date.now(), Date(), "stream error")
})
rotatingLogStream.on("close",function(){
console.log(Date.now(), Date(), "stream closed")
})
rotatingLogStream.on("finish",function(){
console.log(Date.now(), Date(), "stream finished")
})
rotatingLogStream.on("rotate",function(oldFile,newFile){
console.log(Date.now(), Date(), "stream rotated",oldFile,newFile);
})
rotatingLogStream.on("open",function(fd){
console.log(Date.now(), Date(), "stream open",fd);
})
rotatingLogStream.on("new",function(newFile){
console.log(Date.now(), Date(), "stream new",newFile);
})
// console.log(rotatingLogStream.on, rotatingLogStream.end, rotatingLogStream)
var counter = 0;
var i = setInterval(function(){
counter++;
rotatingLogStream.write("testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890-testing 1234567890\n")
if(counter == 2000){
clearInterval(i);
rotatingLogStream.end("end\n");
}
}, 10);