Skip to content

Commit c1d1a3a

Browse files
authored
remove support for winston2 and methods supported by winston2 (#221)
1 parent 4f6cfaa commit c1d1a3a

File tree

5 files changed

+20
-297
lines changed

5 files changed

+20
-297
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ node_js:
66
- "10"
77

88
env:
9-
- WINSTON_VER=winston@2
109
- WINSTON_VER=winston@3
1110

1211
before_install:

daily-rotate-file.js

Lines changed: 7 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ var fs = require('fs');
44
var os = require('os');
55
var path = require('path');
66
var util = require('util');
7-
var semver = require('semver');
87
var zlib = require('zlib');
98
var hash = require('object-hash');
10-
var winston = require('winston');
11-
var compat = require('winston-compat');
129
var MESSAGE = require('triple-beam').MESSAGE;
1310
var PassThrough = require('stream').PassThrough;
14-
var Transport = semver.major(winston.version) === 2 ? compat.Transport : require('winston-transport');
11+
var Transport = require('winston-transport');
1512

1613
var loggerDefaults = {
1714
json: false,
@@ -127,29 +124,13 @@ util.inherits(DailyRotateFile, Transport);
127124
DailyRotateFile.prototype.name = 'dailyRotateFile';
128125

129126
var noop = function () {};
130-
if (semver.major(winston.version) === 2) {
131-
DailyRotateFile.prototype.log = function (level, msg, meta, callback) {
132-
callback = callback || noop;
133-
var options = Object.assign({}, this.options, {
134-
level: level,
135-
message: msg,
136-
meta: meta
137-
});
138-
139-
var output = compat.log(options) + options.eol;
140-
this.logStream.write(output);
141-
callback(null, true);
142-
};
143-
} else {
144-
DailyRotateFile.prototype.normalizeQuery = compat.Transport.prototype.normalizeQuery;
145-
DailyRotateFile.prototype.log = function (info, callback) {
146-
callback = callback || noop;
127+
DailyRotateFile.prototype.log = function (info, callback) {
128+
callback = callback || noop;
147129

148-
this.logStream.write(info[MESSAGE] + this.options.eol);
149-
this.emit('logged', info);
150-
callback(null, true);
151-
};
152-
}
130+
this.logStream.write(info[MESSAGE] + this.options.eol);
131+
this.emit('logged', info);
132+
callback(null, true);
133+
};
153134

154135
DailyRotateFile.prototype.close = function () {
155136
var self = this;
@@ -159,134 +140,3 @@ DailyRotateFile.prototype.close = function () {
159140
});
160141
}
161142
};
162-
163-
DailyRotateFile.prototype.query = function (options, callback) {
164-
if (typeof options === 'function') {
165-
callback = options;
166-
options = {};
167-
}
168-
169-
if (!this.options.json) {
170-
throw new Error('query() may not be used without the json option being set to true');
171-
}
172-
173-
if (!this.filename) {
174-
throw new Error('query() may not be used when initializing with a stream');
175-
}
176-
177-
var self = this;
178-
var results = [];
179-
options = self.normalizeQuery(options);
180-
181-
var logFiles = (function () {
182-
var fileRegex = new RegExp(self.filename.replace('%DATE%', '.*'), 'i');
183-
return fs.readdirSync(self.dirname).filter(function (file) {
184-
return path.basename(file).match(fileRegex);
185-
});
186-
})();
187-
188-
if (logFiles.length === 0 && callback) {
189-
callback(null, results);
190-
}
191-
192-
(function processLogFile(file) {
193-
if (!file) {
194-
return;
195-
}
196-
197-
var logFile = path.join(self.dirname, file);
198-
var buff = '';
199-
200-
var stream;
201-
202-
if (file.endsWith('.gz')) {
203-
stream = new PassThrough();
204-
fs.createReadStream(logFile).pipe(zlib.createGunzip()).pipe(stream);
205-
} else {
206-
stream = fs.createReadStream(logFile, {
207-
encoding: 'utf8'
208-
});
209-
}
210-
211-
stream.on('error', function (err) {
212-
if (stream.readable) {
213-
stream.destroy();
214-
}
215-
216-
if (!callback) {
217-
return;
218-
}
219-
220-
return err.code === 'ENOENT' ? callback(null, results) : callback(err);
221-
});
222-
223-
stream.on('data', function (data) {
224-
data = (buff + data).split(/\n+/);
225-
var l = data.length - 1;
226-
227-
for (var i = 0; i < l; i++) {
228-
add(data[i]);
229-
}
230-
231-
buff = data[l];
232-
});
233-
234-
stream.on('end', function () {
235-
if (buff) {
236-
add(buff, true);
237-
}
238-
239-
if (logFiles.length) {
240-
processLogFile(logFiles.shift());
241-
} else if (callback) {
242-
results.sort(function (a, b) {
243-
var d1 = new Date(a.timestamp).getTime();
244-
var d2 = new Date(b.timestamp).getTime();
245-
246-
return d1 > d2 ? 1 : d1 < d2 ? -1 : 0;
247-
});
248-
249-
if (options.order === 'desc') {
250-
results = results.reverse();
251-
}
252-
253-
var start = options.start || 0;
254-
var limit = options.limit || results.length;
255-
256-
results = results.slice(start, start + limit);
257-
258-
if (options.fields) {
259-
results = results.map(function (log) {
260-
var obj = {};
261-
options.fields.forEach(function (key) {
262-
obj[key] = log[key];
263-
});
264-
return obj;
265-
});
266-
}
267-
268-
callback(null, results);
269-
}
270-
});
271-
272-
function add(buff, attempt) {
273-
try {
274-
var log = JSON.parse(buff);
275-
if (!log || typeof log !== 'object') {
276-
return;
277-
}
278-
279-
var time = new Date(log.timestamp);
280-
if ((options.from && time < options.from) || (options.until && time > options.until)) {
281-
return;
282-
}
283-
284-
results.push(log);
285-
} catch (e) {
286-
if (!attempt) {
287-
stream.emit('error', e);
288-
}
289-
}
290-
}
291-
})(logFiles.shift());
292-
};

package-lock.json

Lines changed: 0 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"homepage": "https://github.com/winstonjs/winston-daily-rotate-file#readme",
3131
"peerDependencies": {
32-
"winston": "^2 || ^3"
32+
"winston": "^3"
3333
},
3434
"devDependencies": {
3535
"chai": "4.2.0",
@@ -42,9 +42,7 @@
4242
"dependencies": {
4343
"file-stream-rotator": "^0.4.1",
4444
"object-hash": "^1.3.0",
45-
"semver": "^6.2.0",
4645
"triple-beam": "^1.3.0",
47-
"winston-compat": "^0.1.4",
4846
"winston-transport": "^4.2.0"
4947
}
5048
}

0 commit comments

Comments
 (0)