Only use log module in main

This commit is contained in:
mmcwilliams 2019-03-21 15:47:25 -04:00
parent 94942d86f9
commit 87d43fc15b
1 changed files with 4 additions and 62 deletions

View File

@ -23,9 +23,9 @@ const delay = require('delay')
//Objects //Objects
const mcopy = {} const mcopy = {}
const log = {}
const dev = {} const dev = {}
let log;
let SYSTEM; let SYSTEM;
let mainWindow; let mainWindow;
let mscript; let mscript;
@ -49,7 +49,7 @@ mcopy.settings = {}
* *
**/ **/
dev.init = function () { dev.init = function () {
dev.listen() dev.listen()
} }
@ -399,66 +399,10 @@ seq.listen = function () {
}) })
} }
log.file = function () {
let logPath = path.join(os.homedir(), `/.config/mcopy/`)
if (process.platform === 'darwin') {
logPath = path.join(os.homedir(), `/Library/Logs/mcopy/`)
} else if (process.platform === 'win32') {
logPath = path.join(os.homedir(), `/AppData/Roaming/mcopy/`)
}
if (!fs.existsSync(logPath)) {
fs.mkdirSync(logPath)
}
return path.join(logPath, 'mcopy.log')
}
log.time = 'MM/DD/YY-HH:mm:ss'
log.formatter = (options) => {
console.dir(options)
return options.timestamp() +' ['+ options.level.toUpperCase() +'] '+ (undefined !== options.message ? options.message : '') +
(options.meta && Object.keys(options.meta).length ? '\n\t'+ JSON.stringify(options.meta) : '' );
}
log.transport = createLogger({
transports: [
new (transports.Console)({
level: 'info',
json : false,
format : combine(
timestamp(),
colorize(),
simple()
)
}),
new (transports.File)({
filename: log.file()
})
]
})
log.init = function () {
log.listen()
}
log.display = function (obj) {
mainWindow.webContents.send('log', obj)
}
log.listen = function () {
ipcMain.on('log', (event, arg) => {
log.transport.info(`[renderer] action=${arg.action} service=${arg.service} status=${arg.status}`)
event.returnValue = true
})
}
log.info = function (action, service, status, display) {
var obj = {
action : action,
service : service,
status : status
}
log.transport.info(`[main] action=${action} service=${service} status=${status}`)
if (display) {
log.display(obj)
}
}
var init = async function () { var init = async function () {
log = await require('log')({})
try { try {
SYSTEM = await system() SYSTEM = await system()
} catch (err) { } catch (err) {
@ -471,8 +415,6 @@ var init = async function () {
await settings.restore() await settings.restore()
mcopy.settings = await settings.all() mcopy.settings = await settings.all()
log.init()
dev.init() dev.init()
seq.init() seq.init()