本文整理汇总了TypeScript中bunyan-log.Logger类的典型用法代码示例。如果您正苦于以下问题:TypeScript Logger类的具体用法?TypeScript Logger怎么用?TypeScript Logger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Logger类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: express
database.connect().then((success) => {
if (success === true) {
log.info('database connected');
try {
// setup express application and middlewares
const app: express.Application = express();
container.registerInstance(express, app);
container.registerTransient(Router);
app.use(compression());
app.use(helmet());
app.use(requestHandlers.headersToLower);
app.use(requestHandlers.remoteAddressAppender);
// TODO: configure cors correctly for security concerns
app.use(cors());
// add necessary headers
app.use((req, res, next) => {
res.header('Content-*', '*');
res.header('Cache-Control', 'no-cache, no-store, must-revalidate');
res.header('Pragma', 'no-cache');
res.header('Expires', '0');
next();
});
app.use(queryHandlers.toLower);
app.use(bodyParser.json({ type: '*/json', limit: '1Mb' }));
app.set(PORT_KEY, appConfig.server.port || DEFAULT_PORT);
// fulfil pre-flight promise request
app.options('*', (req, res) => {
if (appConfig.server.allowPreFlightRequest === true) {
res.status(StatusCodes.OK).json({
success: true
});
} else {
res.status(StatusCodes.FORBIDDEN).json({
success: false
});
}
});
if (appConfig.server.enableTestEndpoint === true) {
app.get('/api/test', (req, res) => {
res.json({
message: 'hello beowulf'
});
});
}
// START SERVICES HERE
const svcManager: ServiceManager = container.get(ServiceManager);
svcManager.startServices();
app.use(express.static(path.join(__dirname, PUBLIC_DIRECTORY)));
// notify of bad request
const requestLogger = new requestHandlers.RequestLogger(log);
app.use(requestLogger.unhandled);
// log unhandled errors
const errorLogger = new errorHandlers.ErrorMiddleware(log);
app.use(errorLogger.log);
const httpServer: Server = app.listen(app.get('port'), (error: Error) => {
if (error != null) {
log.error(error);
} else {
log.info('server listening over insecure http on port ' + app.get(PORT_KEY));
// we have to start active platforms
log.info('starting active platforms');
}
});
} catch (ex) {
(log as any).fatal(ex, 'fatal error in server start up');
database.close();
process.exit(1);
}
} else {
log.error('database connection failed');
return;
}
}).catch((err) => {
示例2:
const httpServer: Server = app.listen(app.get('port'), (error: Error) => {
if (error != null) {
log.error(error);
} else {
log.info('server listening over insecure http on port ' + app.get(PORT_KEY));
// we have to start active platforms
log.info('starting active platforms');
}
});