Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function addLayout(){
log4js.addLayout('xml', config => function (logEvent) {
// format in xml
var xw = new XMLWriter;
xw.startDocument();
xw.startElement('log');
xw.writeElement('startTime',logEvent.startTime.toString());
xw.writeElement('categoryName', logEvent.categoryName);
xw.writeElement('data', logEvent.data.toString());
xw.writeElement('level', logEvent.level.toString());
xw.writeElement('context', JSON.stringify(logEvent.context));
xw.writeElement('pid', logEvent.pid.toString());
//xw.text(logEvent.toString());
xw.endDocument();
//console.log(xw.toString());
return xw.toString();
var path = require('path');
var express = require('express');
var app = express();
var openBrowsers = require('open-browsers');
// log
const log4js = require('log4js');
log4js.addLayout('json', config => function (logEvent) {
logEvent.data = logEvent.data[0];
return JSON.stringify(logEvent) + config.separator;
});
const logConf = require('./conf/log.conf');
log4js.configure(logConf);
const logger = log4js.getLogger('chatLog');
// 开发模式热更新
if (process.env.NODE_ENV !== 'production') {
var webpack = require('webpack');
var config = require('./webpack.config');
var compiler = webpack(config);
// use in develope mode
app.use(
require('webpack-dev-middleware')(compiler, {
import path from 'path';
import log4js from 'log4js';
import { isProdMode } from '../configs/index.config';
import { logPath } from './path.util';
log4js.addLayout('json', config => {
return logEvent => {
return JSON.stringify(logEvent) + config.separator;
};
});
log4js.configure({
appenders: {
console: { type: 'console' },
requestInfoFile: {
type: 'file',
filename: path.join(logPath, 'request-info.log'),
maxLogSize: 3 * 1024 * 1024,
backups: 3,
compress: true,
layout: { type: 'json', separator: ',' },
},
import DependencyExtractorImpl from "./service/DependencyExtractorImpl";
import unasyncify from "./service/unasyncify";
import express = require("express");
import program = require("caporal");
import fs = require("fs");
import health = require("grpc-health-check/health");
import healthv1 = require("grpc-health-check/v1/health_pb");
import Matcher from "./matcher/Matcher";
import promMiddleware = require("express-prometheus-middleware");
const packageMeta = require("../package.json");
const asyncFs = fs.promises;
addLayout("json", function() {
return function(logEvent) {
const data = logEvent.data.length > 1 ? logEvent.data[1] : {};
return JSON.stringify({
level: logEvent.level.levelStr.toLowerCase(),
ts: new Date(logEvent.startTime).getTime(),
msg: logEvent.data[0],
...data,
});
}
})
const logger = getLogger();
program.name("extractor")
.option("--bind-address ", "the ip address to bind to", program.STRING)
WARN = 'WARN',
ERROR = 'ERROR',
FATAL = 'FATAL',
OFF = 'OFF'
}
export class ContextTrace {
constructor(
public readonly context: string,
public readonly path?: string,
public readonly lineNumber?: number,
public readonly columnNumber?: number
) { }
}
Log4js.addLayout('Nestify', (logConfig: any) => {
return (logEvent: Log4js.LoggingEvent): string => {
let moduleName: string = '';
let position: string = '';
const messageList: string[] = [];
logEvent.data.forEach((value: any) => {
if (value instanceof ContextTrace) {
moduleName = value.context;
if (value.lineNumber && value.columnNumber) {
position = `${value.lineNumber}, ${value.columnNumber}`;
}
return;
}
if (typeof value !== 'string') {
value = Util.inspect(value, false, 3, true);
function addLayout(){
log4js.addLayout('json', config => function (logEvent) {
return JSON.stringify(logEvent) + ',';
});
}
if (!hasAttr(config, 'logger')) {
return log4js.getLogger(config.name);
}
if (!hasAttr(config.logger, 'path')) {
return log4js.getLogger(config.name);
}
let level = 'info';
if (hasAttr(config.logger, 'level')) {
level = config.logger.level;
}
let backupCount = 15;
if (hasAttr(config.logger, 'backupCount') && hasAttr(config.logger.backupCount, 'max')) {
backupCount = config.logger.backupCount.max;
}
log4js.addLayout('baetyl', () => logEvent => {
const asctime = moment(logEvent.startTime).format('YYYY-MM-DD HH:mm:ss');
const name = logEvent.categoryName;
const levelname = logEvent.level.levelStr;
const message = logEvent.data;
return `${asctime} - ${name} - ${levelname} - ${message}`;
});
log4js.configure({
appenders: {
file: {
type: 'file',
filename: config.logger.path,
layout: { type: 'baetyl' },
backups: backupCount,
compress: true,
encoding: 'utf-8'
}