-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.js
25 lines (20 loc) · 902 Bytes
/
index.js
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
const path = require('path');
const mkdirp = require('mkdirp');
const spdlog = require('bindings')('spdlog');
exports.version = spdlog.version;
exports.setLevel = spdlog.setLevel;
exports.setFlushOn = spdlog.setFlushOn;
exports.Logger = spdlog.Logger;
function createRotatingLogger(name, filepath, maxFileSize, maxFiles) {
return createLogger('rotating', name, filepath, maxFileSize, maxFiles);
}
function createAsyncRotatingLogger(name, filepath, maxFileSize, maxFiles) {
return createLogger('rotating_async', name, filepath, maxFileSize, maxFiles);
}
async function createLogger(loggerType, name, filepath, maxFileSize, maxFiles) {
const dirname = path.dirname(filepath);
await mkdirp(dirname);
return new spdlog.Logger(loggerType, name, filepath, maxFileSize, maxFiles);
}
exports.createRotatingLogger = createRotatingLogger;
exports.createAsyncRotatingLogger = createAsyncRotatingLogger;