36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
/*
|
|
SkeptCOM [logs] | on va log les choses, c'est mieux quand on a un problème ... 'fin, les gens bons le fond souvent ♥
|
|
*/
|
|
|
|
// REQUIRE, CONST, VARIABLES
|
|
const dateFormat = require('dateformat')
|
|
const fs = require('fs')
|
|
const fse = require('fs-extra')
|
|
const colors = require('colors')
|
|
const path = require('path')
|
|
|
|
const skepticonf = require('../conf/skepticom.json')
|
|
const skeptIO = require('../modules/skeptIO')('logs')
|
|
const logConf = {}
|
|
|
|
// INIT
|
|
if (!skepticonf.logs) return console.log(` [ERROR || LOGS] no configuration for logs.js in ./conf/skepticom.json`)
|
|
if (skepticonf.logs.path) {
|
|
logConf.path = path.resolve(skepticonf.logs.path)
|
|
} else {
|
|
logConf.path = path.resolve('./_logs')
|
|
}
|
|
fse.ensureDirSync(logConf.path)
|
|
|
|
skeptIO.receive( obj => {
|
|
let rtn = `[${dateFormat("yyyy-mm-dd HH:MM")}] ${obj.from.replace(skepticonf.pm2.prefix, '')}\n ${JSON.stringify(obj.data)}`
|
|
|
|
console.log(rtn.magenta)
|
|
fs.appendFile(logConf.path + '/' + dateFormat("yyyy-W") + '.log', rtn + '\n', 'utf8', function(err) {
|
|
if (err) return console.error(err)
|
|
})
|
|
|
|
})
|
|
|
|
console.log(` --- [LOGS] Load`)
|