mcopy/cli/lib/log/index.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-03-09 03:31:51 +00:00
'use strict';
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;
const path = require('path');
const fs = require('fs-extra');
const os = require('os');
const logTime = 'MM/DD/YY-HH:mm:ss';
let transport;
async function logFile() {
let exists;
let logPath = path.join(os.homedir(), `/.config/mcopy-cli/`);
if (process.platform === 'darwin') {
logPath = path.join(os.homedir(), `/Library/Logs/mcopy-cli/`);
}
else if (process.platform === 'win32') {
logPath = path.join(os.homedir(), `/AppData/Roaming/mcopy-cli/`);
}
exists = await fs.exists(logPath);
if (!exists) {
await fs.mkdir(logPath);
}
return path.join(logPath, 'mcopy-cli.log');
}
2019-03-09 03:31:51 +00:00
module.exports = async function (arg) {
if (arg.quiet) {
transport = {
info: function () { },
warn: function () { },
error: function () { }
};
}
else {
transport = createLogger({
transports: [
new (transports.Console)({
format: combine(format.colorize(), format.simple())
}),
new (transports.File)({
filename: await logFile()
})
]
});
}
return transport;
};
//# sourceMappingURL=index.js.map