Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function consoleFormatter(options){
// Messages will usually be debug or warnings (to send message to console use logger.debug(message) )
// We only want custom format for the auto-middleware logging. When called with logger.debug("message", args) it should
// act like console.log but with a colorized level indication
const meta = options.meta;
const logMessage = (meta && 'status' in meta)
? winston.config.colorize(options.level) + `: ${meta.status} ${meta.ip} ${meta.method} ${meta.url} ${meta.input || ""}`
: winston.config.colorize(options.level) + `: ${options.message}` + (options.meta && Object.keys(options.meta).length ? JSON.stringify(options.meta, null, ' ') : '' );
return logMessage
}
filename: `${logDir}/-platform.log`,
timestamp: true,
datePattern: 'yyyy-MM-dd',
prepend: true,
level: 'debug',
handleExceptions: true,
humanReadableUnhandledException: true,
maxsize: 1024 * 1024 * 10, // in bytes, 10 MB
json: true,
}),
*/
],
exitOnError: false
});
obj.log.setLevels(winston.config.syslog.levels);
}
module.exports = obj;
const winston = require('winston');
const fs = require('fs');
const logDir = 'logs';
const obj = {};
// Create the log directory if it does not exist
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir);
}
winston.setLevels(winston.config.syslog.levels);
winston.addColors(winston.config.npm.colors);
if (!obj.log) {
obj.log = new (winston.Logger)({
transports: [
// file transport
new (require('winston-daily-rotate-file'))({
label: 'slidewiki-platform',
filename: `${logDir}/-platform.log`,
timestamp: true,
datePattern: 'yyyy-MM-dd',
prepend: true,
level: 'warning',
handleExceptions: true,
humanReadableUnhandledException: true,
maxsize: 1024 * 1024 * 10, // in bytes, 10 MB
json: true,
formatter: function(options) {
return '['+ process.pid + '] ' + winston.config.colorize(options.level, options.level) +' '+ (undefined !== options.message ? options.message : '') +
(options.meta && Object.keys(options.meta).length ? '\n\t'+ util.inspect(options.meta) : '' );
}
});
for (const i in this.options) {
if (args[i] !== null && args[i] !== undefined) {
this.options[i] = args[i];
}
}
this.loggers = [];
this.loggers.push(
winston.createLogger({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
levels: winston.config.syslog.levels,
transports: [
new winston.transports.File({
filename: `${this.options.logPath}/${this.options.logFile}`
})
]
})
);
if (cluster.isMaster && args.silent !== true) {
this.loggers.push(
winston.createLogger({
format: winston.format.combine(
winston.format.timestamp(),
winston.format.colorize(),
winston.format.printf(msg => {
return `${this.options.id} @ ${msg.timestamp} - ${msg.level}: ${msg.message}`;
.option('-H, --host ', 'Set the host string; important for running with the balancer to be able to advertise an externally visible host name.')
.parse(process.argv);
var setLevel = "info";
if(program.verbose) {
setLevel = "debug";
}
io.set("log level", 0);
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({timestamp:true, level:setLevel, colorize:true}),
]
});
logger.setLevels(winston.config.syslog.levels);
var queueHost = "localhost";
if(program.args.length>=0) {
queueHost = program.args[0];
} else if (program.args.length==0) {
logger.warning("Default to localhost for queue host.");
}
var host = "localhost";
if(program.host) {
host = program.host;
logger.info("Setting host to " + host);
} else {
logger.warning("Defaulting host to localhost - this is probably bad if you're using balancer. Use -h to set the host.");
}
fs = require('fs'),
winston = require('winston'),
nconf = require('nconf'),
pkg = require('./package.json'),
ws = require('./src/webserver');
//`var memory = require('./src/memory');
global.forks = [];
nconf.argv().env();
global.env = process.env.NODE_ENV || 'development';
//global.env = process.env.NODE_ENV || 'production';
winston.setLevels(winston.config.cli.levels);
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, {
colorize: true,
timestamp: function() {
var date = new Date();
return (date.getMonth() + 1) + '/' + date.getDate() + ' ' + date.toTimeString().substr(0,8) + ' [' + global.process.pid + ']';
},
level: global.env === 'production' ? 'info' : 'verbose'
});
winston.add(winston.transports.File, {
filename: 'logs/error.log',
level: 'error'
});
winston.err = function (err) {
.option('-p, --port ', 'Set the websocket port to bind to (default 8080)')
.parse(process.argv);
var setLevel = "info";
if(program.verbose) {
setLevel = "debug";
}
io.set("log level", 0);
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({timestamp:true, level:setLevel, colorize:true}),
]
});
logger.setLevels(winston.config.syslog.levels);
var queueHost = "localhost";
if(program.args.length>=0) {
queueHost = program.args[0];
} else if (program.args.length==0) {
logger.warn("Default to localhost for queue host.");
}
var port = 8080;
if(program.port) {
port = program.port
logger.info("Setting port to " + program.port);
}
app.listen(port);
let formatter = function(options){
let format = '(' + moment().format('YYYY-MM-DD_HH-mm-ss') + ') ';
format += '[' + winston.config.colorize(options.level,options.level.toUpperCase()) + '] ';
format += options.message;
if (options.meta.length > 0){
format += JSON.stringify(options.meta);
}
return format;
};