From faeddb84ab565a8d50d7add19b3384f9069adee1 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Fri, 8 Mar 2019 22:31:51 -0500 Subject: [PATCH] Build log --- cli/lib/log/index.js | 89 ++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/cli/lib/log/index.js b/cli/lib/log/index.js index 5583ec0..08b6e65 100644 --- a/cli/lib/log/index.js +++ b/cli/lib/log/index.js @@ -1,45 +1,46 @@ -'use strict' - -const winston = require('winston') -const path = require('path') -const fs = require('fs-extra') -const os = require('os') - -const log = {} - -log.file = function () { - 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/`) - } - if (!fs.existsSync(logPath)) { - fs.mkdirSync(logPath) - } - return path.join(logPath, 'mcopy-cli.log') +'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'); } - -log.time = 'MM/DD/YY-HH:mm:ss' - -module.exports = function (arg) { - if (arg.quiet) { - log.transport = { - info : function () {}, - warn : function () {}, - error : function () {} - } - } else { - log.transport = winston.createLogger({ - transports: [ - new (winston.transports.Console)({ - format: winston.format.simple() - }), - new (winston.transports.File)({ - filename: log.file() - }) - ] - }) - } - return log.transport -} \ No newline at end of file +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 \ No newline at end of file