本文整理汇总了TypeScript中log4js.connectLogger函数的典型用法代码示例。如果您正苦于以下问题:TypeScript connectLogger函数的具体用法?TypeScript connectLogger怎么用?TypeScript connectLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connectLogger函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: setup
function setup(app: express.Express) {
// View engine setup
app.set("views", path.join(__dirname, "/../views"));
app.set("view engine", "pug");
// uncomment after placing your favicon in /public
// app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
// Body parser setup
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
// Cookie parser setup
app.use(cookieParser());
// Log4js setup
app.use(log4js.connectLogger(log4js.getLogger("http"), { level: "auto" }));
// Passport setup when using
// app.use(setupedPassport.initialize());
// app.use(setupedPassport.session());
// Static dir setup
app.use(express.static(path.join(__dirname, "/../public")));
// Rooting setup
setupRoutes(app);
app.use((req, res, next) => {
const err = new HttpErrors.NotFound();
next(err);
});
app.use((err: Error, req, res, next) => {
const error = err as HttpErrors.HttpError;
res.status(error.status || 500);
const params = {
error: (process.env.NODE_ENV !== "production") ? error : null,
message: error.message
};
if (/^\/api/.test(req.originalUrl)) {
res.send(params);
} else {
res.render("error", params);
}
});
}
示例2: init
static init(config: any, app: express.Application): any {
var log4js: any = require('log4js');
log4js.configure('config/log4js_setting.json');
var logger = log4js.getLogger('app');
logger.setLevel(config.log.level); // ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF
logger.info('Logging start. ');
logger.info('Log Level:' + config.log.level);
app.use(log4js.connectLogger(logger, {
level: config.log.level
}));
return logger;
}
示例3:
import * as fs from 'fs';
import * as path from 'path';
import * as log4js from 'log4js';
import * as constants from '../config/constants';
const LOG_METADATA = path.parse(constants.LOG_FILE);
if (!fs.existsSync(LOG_METADATA.dir)) {
fs.mkdirSync(LOG_METADATA.dir);
}
log4js.configure({
appenders: [
{
type: 'dateFile',
filename: constants.LOG_FILE,
category: 'main',
pattern: '-yyyy-MM-dd',
alwaysIncludePattern: true
}
],
replaceConsole: false
});
export const logger = log4js.getLogger('main');
export const loggerConnect = log4js.connectLogger(logger, { level: log4js.levels.DEBUG, format: ':method - :url - :status - :response-timems' });
示例4: express
let logger = log4js.getLogger('server-config');
export let app = express();
//configuracion express, middleware y setters
app.set(_.PORT, process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
//conecta logger con express para pintar los accesos
app.use(log4js.connectLogger(log4js.getLogger("http"), { level: 'auto' }));
app.get('/', routes.index);
app.use("/api/v1/users", userController.usersRouter);
// captura todos los errores procedentes de los middleware
app.use((err:Error, req: express.Request, res: express.Response, next: express.NextFunction)=> {
logger.error(err.message);
res.status(500);
res.send( {
error: err.message
});
});
示例5:
maxLogSize: config.log4js.maxLogSize,
backups: config.log4js.backups,
category: [ 'server', 'console' ]
},
],
replaceConsole: true
});
var logger = log4js.getLogger('server');
app.use(log4js.connectLogger(logger, {
level: log4js.levels.DEBUG,
nolog: [ '\\.css', '\\.js', ],
format: JSON.stringify({
'date': ':date',
'remote-addr': ':remote-addr',
'method': ':method',
'url': ':url',
'http-version': ':http-version',
'status': ':status',
'content-length': ':content-length',
'user-agent': ':user-agent'
})
}));
app.set('port', process.env.PORT || config.server.listenPort);
app.enable('trust proxy');
app.use(methodOverride());
app.use(cookieParser('jrpcMockServer'));
app.use(bodyParser.json());
app.use(session({
secret: 'jrpcMockServer',