1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var assert = require('assert'),
|
10 | exec = require('child_process').exec,
|
11 | fs = require('fs'),
|
12 | path = require('path'),
|
13 | vows = require('vows'),
|
14 | winston = require('../../lib/winston'),
|
15 | helpers = require('../helpers');
|
16 |
|
17 | var archiveTransport = new winston.transports.File({
|
18 | timestamp: true,
|
19 | json: false,
|
20 | zippedArchive: true,
|
21 | tailable: true,
|
22 | filename: 'testarchive.log',
|
23 | dirname: path.join(__dirname, '..', 'fixtures', 'logs'),
|
24 | maxsize: 4096,
|
25 | maxFiles: 3
|
26 | });
|
27 |
|
28 | function data(ch) {
|
29 | return new Array(1018).join(String.fromCharCode(65 + ch));
|
30 | }
|
31 |
|
32 | function logKbytes(kbytes, txt) {
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | for (var i = 0; i < kbytes; i++) {
|
39 | archiveTransport.log('info', data(txt), null, function() {});
|
40 | }
|
41 | }
|
42 |
|
43 | vows.describe('winston/transports/file/zippedArchive').addBatch({
|
44 | "An instance of the File Transport with tailable true": {
|
45 | "when created archived files are rolled": {
|
46 | topic: function() {
|
47 | var that = this,
|
48 | created = 0;
|
49 |
|
50 | archiveTransport.on('logged', function() {
|
51 | if (++created === 6) {
|
52 | return that.callback();
|
53 | }
|
54 |
|
55 | logKbytes(4, created);
|
56 | });
|
57 |
|
58 | logKbytes(4, created);
|
59 | },
|
60 | "should be only 3 files called testarchive.log, testarchive1.log.gz and testarchive2.log.gz": function() {
|
61 |
|
62 |
|
63 | for (var num = 0; num < 6; num++) {
|
64 | var file = !num ? 'testarchive.log' : 'testarchive' + num + '.log.gz',
|
65 | fullpath = path.join(__dirname, '..', 'fixtures', 'logs', file);
|
66 |
|
67 |
|
68 | if (num >= 3) {
|
69 | assert.throws(function() {
|
70 | fs.statSync(fullpath);
|
71 | }, Error);
|
72 | } else {
|
73 |
|
74 | assert.doesNotThrow(function() {
|
75 | fs.statSync(fullpath);
|
76 | }, Error);
|
77 | }
|
78 | }
|
79 |
|
80 | },
|
81 | }
|
82 | },
|
83 | }).export(module);
|