本文整理汇总了TypeScript中express-winston.errorLogger函数的典型用法代码示例。如果您正苦于以下问题:TypeScript errorLogger函数的具体用法?TypeScript errorLogger怎么用?TypeScript errorLogger使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了errorLogger函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
export default function () {
var expressWinston = require('express-winston');
server
.msg('Winston - Error Logging Enabled.');
app.use(expressWinston.errorLogger({
'transports': [
new winston.transports.File({
'name': 'request-error',
'filename': server.cwd() + '/logs/errors.log',
'handleExceptions': true,
'json': true,
'colorize': true
})
],
'expressFormat': true,
'colorStatus': true
}));
};
示例2: next
> = (context: interfaces.Context) => (app: express.Application) => {
const settings = context.container.get<SettingsServiceAttributes>(
registry.SettingsService
);
app.use(
expressWinston.errorLogger({
transports: settings.loggerTransports,
requestWhitelist: [],
msg: '{{req.method}} {{req.url}} => {{res.statusCode}}: {{err.message}}'
})
);
/* tslint:disable:no-void-expression */
/**
* Add a final error handler that will prevent the Express final error handler from executing
* when routing-controllers error handler or any other error handler has already sent headers
* and data.
* See https://github.com/pleerock/routing-controllers/issues/243
*/
app.use(
(
error: Error,
_req: express.Request,
res: express.Response,
next: express.NextFunction
) => {
if (res.headersSent || res._header) {
return next();
}
return next(error);
}
);
/* tslint:enable:no-void-expression */
return app;
};
示例3: errorLogger
export function errorLogger() {
return expressWinston.errorLogger(winstonOptions)
}
示例4: new
import IAppLogger from './IAppLogger';
const logger = new (winston.Logger)({
level: config.get('LOG_LEVEL')
});
if (config.get('NODE_ENV') !== 'test') {
logger.add(winston.transports.Console);
}
export interface ILoggerMiddleware {
logger: express.RequestHandler;
errorLogger: express.ErrorRequestHandler;
}
const loggerSingleton: IAppLogger = logger;
const LoggerMiddleware: ILoggerMiddleware = {
logger: expressWinston.logger({
winstonInstance: logger
}),
errorLogger: expressWinston.errorLogger({
winstonInstance: logger
})
};
export default loggerSingleton;
export {
LoggerMiddleware
};
示例5: winstonMongo
expressWinston.requestWhitelist.push('ips');
app.use(expressWinston.logger({
transports: [
new winstonMongo({
db: config.winston.mongo.dbName,
collection: config.winston.mongo.accessLogCollName
})
]
}));
// Setup router
app.use('/', require('./route/index'));
// express-winston errorLogger makes sense AFTER the router.
// Send log to mongodb
app.use(expressWinston.errorLogger({
transports: [
new winstonMongo({
db: config.winston.mongo.dbName,
collection: config.winston.mongo.errLogCollName
})
]
}));
// Start listening
app.listen(config.port, () => {
console.log('Web server started at port ' + config.port);
});
module.exports = app;