Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const onError = err => {
console.error('%s ERROR %s [egg-logger] [%s] %s',
utility.logDate(','), process.pid, this.options.file, err.stack);
this.reload();
console.warn('%s WARN %s [egg-logger] [%s] reloaded', utility.logDate(','), process.pid, this.options.file);
};
// only listen error once because stream will reload after error
const onError = err => {
console.error(
'%s ERROR %s [logger] [%s] %s',
utility.logDate(','),
process.pid,
filename,
err.stack
);
this.reload();
console.warn(
'%s WARN %s [logger] [%s] reloaded',
utility.logDate(','),
process.pid,
filename
);
};
// only listen error once because stream will reload after error
meta = meta || {};
let message;
let output;
const formatter = meta.formatter || options.formatter;
if (args[0] instanceof Error) {
message = formatError(args[0]);
} else {
message = util.format.apply(util, args);
}
if (meta.raw === true) {
output = message;
} else if (options.json === true || formatter) {
meta.level = level;
meta.date = utility.logDate(',');
meta.pid = process.pid;
meta.hostname = hostname;
meta.message = message;
output = options.json === true ? JSON.stringify(meta) : formatter(meta);
} else {
output = message;
}
if (!output) return new Buffer('');
output += options.eol;
// convert string to buffer when encoding is not utf8
return options.encoding === 'utf8' ? new Buffer(output) : iconv.encode(output, options.encoding);
}
let message;
let output;
let formatter = meta.formatter || options.formatter;
if (meta.ctx && options.contextFormatter) formatter = options.contextFormatter;
if (args[0] instanceof Error) {
message = formatError(args[0]);
} else {
message = util.format.apply(util, args);
}
if (meta.raw === true) {
output = message;
} else if (options.json === true || formatter) {
meta.level = level;
meta.date = utility.logDate(',');
meta.pid = process.pid;
meta.hostname = hostname;
meta.message = message;
output = options.json === true ? JSON.stringify(meta) : formatter(meta);
} else {
output = message;
}
if (!output) return new Buffer('');
output += options.eol;
// convert string to buffer when encoding is not utf8
return options.encoding === 'utf8' ? output : iconv.encode(output, options.encoding);
},
function onReachReforkLimit() {
console.error('[%s] [cfork:master:%s] worker died too fast (total %d disconnect, %d unexpected exit)',
utility.logDate(), process.pid, disconnectCount, unexpectedCount);
}
function onUnexpected(worker, code, signal) {
var exitCode = worker.process.exitCode;
var propertyName = worker.hasOwnProperty('exitedAfterDisconnect') ? 'exitedAfterDisconnect' : 'suicide';
var err = new Error(util.format('worker:%s died unexpected (code: %s, signal: %s, %s: %s, state: %s)',
worker.process.pid, exitCode, signal, propertyName, worker[propertyName], worker.state));
err.name = 'WorkerDiedUnexpectedError';
console.error('[%s] [cfork:master:%s] (total %d disconnect, %d unexpected exit) %s',
utility.logDate(), process.pid, disconnectCount, unexpectedCount, err.stack);
}
function log(str) {
console.error(utility.logDate() + ":" + str);
}
this.open(function(aconn) {
log("connected to:" + parent.dburl);
parent.conn = aconn;
aconn.collection("connStatus").updateOne({ _id: parent.serverid }, {
$set: {
addTime: utility.logDate(),
updateTime: utility.logDate(),
count: 1
}
}, { upsert: true }, function(err, r) {
if (!err) {
parent.startConnCheck();
}
});
parent.ready();
});