/
var
/
www
/
myprog.com.ua
/
server
/
node
/
logs
/
/var/www/myprog.com.ua/server/node/logs
mkdir
upload
Name
Size
Mode
Actions
log.js
4993
0644
edit
dl
rm
Edit:
/var/www/myprog.com.ua/server/node/logs/log.js
(4993B)
module.exports = (function () { const util = require('util'); const { createLogger, format, transports } = require('winston'); const { printf } = format; const myFormat = printf(({ level, message, service, timestamp, stack, method }) => { return `${level} ${timestamp} :: ${service ? service : ''} :: ${method ? method : ''} :: ${message}\n${stack ? stack : ''}`; }); const logger = createLogger({ level: config.logs_level, format: format.combine( format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), format.errors({ stack: true }), format.splat(), myFormat ), transports: [ new transports.File({ filename: config.logs_dir + '/homehead_error.log', level: 'error' }), new transports.File({ filename: config.logs_dir + '/homehead_debug.log', level: 'debug' }) ] }); const logger_sql = createLogger({ level: config.logs_level, format: format.combine( format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), format.errors({ stack: true }), format.splat(), myFormat ), transports: [ new transports.File({ filename: config.logs_dir + '/homehead_sql_debug.log', level: 'debug' }) ] }); function build_message(args, arguments) { let message = ''; for (let i in arguments) { if (i > 1) { if (Array.isArray(arguments[i])) { message += `\n${util.inspect(arguments[i])}`; } else if (typeof arguments[i] === 'object') { message += '\n' + util.inspect(arguments[i]) } else { message += arguments[i] } message += ' ' args.push(arguments[i]); } } return message; } return { debug: function () { let args = ['\x1b[36m%s\x1b[0m', 'DEBUG', `${new Date().toMysqlString()}`]; for (let i in arguments) { if (Array.isArray(arguments[i])) { args.push(` :: ${util.inspect(arguments[i])}`) } else if (typeof arguments[i] === 'object') { args.push(` :: ${util.inspect(arguments[i])}`) } else { args.push(` :: ${arguments[i]}`) } } if (parseInt(config.debug) === 1) { logger.log({ level: 'debug', service: arguments[0], method: arguments[1], message: build_message(args, arguments) }); } if (process.env.NODE_ENV !== 'production') { args = Array.prototype.slice.call(args); console.debug.apply(console, args); } }, error: function () { let args = ['\x1b[31m%s\x1b[0m', 'ERROR', `${new Date().toMysqlString()}`]; for (let i in arguments) { if (Array.isArray(arguments[i])) { args.push(` :: ${util.inspect(arguments[i])}`) } else if (typeof arguments[i] === 'object') { args.push(` :: ${util.inspect(arguments[i])}`) } else { args.push(` :: ${arguments[i]}`) } } logger.log({ level: 'error', service: arguments[0], method: arguments[1], message: build_message(args, arguments) }); if (process.env.NODE_ENV !== 'production') { args = Array.prototype.slice.call(args); console.error.apply(console, args); } }, debug_sql: function () { let args = ['\x1b[35m%s\x1b[0m', 'DEBUG_SQL', `${new Date().toMysqlString()}`]; for (let i in arguments) { if (Array.isArray(arguments[i])) { args.push(` :: ${util.inspect(arguments[i])}`) } else if (typeof arguments[i] === 'object') { args.push(` :: ${util.inspect(arguments[i])}`) } else { args.push(` :: ${arguments[i]}`) } } if (parseInt(config.debug_sql) === 1) { logger_sql.log({ level: 'debug', service: arguments[0], method: arguments[1], message: build_message(args, arguments) }); } if (process.env.NODE_ENV !== 'production') { args = Array.prototype.slice.call(args); console.debug.apply(console, args); } } } }());
Save
cmd:
run