[Hapi.js] Logging with good and good-console
hapi doesn't ship with logging support baked in. Luckily, hapi's rich plugin ecosystem includes everything needed to configure logging for your application. This post will introduce good, a process monitor for hapi, and good-console, a reporter for good that outputs to standard out.
Install:
npm install --save good good-console
'use strict'
var Hapi = require( 'hapi' ); /**
* set up server connection
* @type {"hapi".Server}
*/
var server = new Hapi.Server();
server.connection( {
host: 'localhost',
port: 8000
} ); /**
* log
*/
var goodOptions = ({
reporters: [
{
reporter: require('good-console'),
events: {log: ['error'], response: '*'} // only log out error event
// events: {log: '*', response: '*'} // log out any log event
}
]
}); server.register({
register: require('good'),
options: goodOptions
}, function(err){
/**
* Routers
*/
server.route( {
method: 'GET',
path: '/',
handler: function ( request, reply ) {
server.log('error', 'Error happened'); // log error to the terminal
server.log('info', 'replying'); // log info to the terminal
reply( 'hello hapi!' );
}
} ); server.route( {
method: 'GET',
path: '/{name}',
handler: function ( request, reply ) {
reply( "hello " + request.params.name + "!" );
}
} );
}); /**
* Start the server
*/
server.start( function (err) {
if (err) {
throw err;
}
console.log( 'Started at:', server.info.uri )
} );
[Hapi.js] Logging with good and good-console的更多相关文章
- log4j报错ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only err ...
- [Hapi.js] Up and running
hapi is a rock solid server framework for Node.js. Its focus on modularity and configuration-over-co ...
- [Hapi.js] Managing State with Cookies
hapi has built-in support for parsing cookies from a request headers, and writing cookies to a respo ...
- [Hapi.js] Request Validation with Joi
hapi supports request validation out of the box using the joi module. Request path parameters, paylo ...
- [Hapi.js] Friendly error pages with extension events
hapi automatically responds with JSON for any error passed to a route's reply()method. But what if y ...
- [Hapi.js] Extending the request with lifecycle events
Instead of using middlware, hapi provides a number of points during the lifecycle of a request that ...
- [Hapi.js] POST and PUT request payloads
hapi makes handling POST and PUT payloads easy by buffering and parsing them automatically without r ...
- [Hapi.js] View engines
View engines, or template engines, allow you to maintain a clean separation between your presentatio ...
- Js调试中不得不知的Console
在js调试中,大部分的前端人员都是采用console.log()方法来打印出调试的数据,但是很多人都不知道console这个对象有很多很实在的方法,本文就来介绍一下这些方法的使用. 一.console ...
随机推荐
- [RxJS] Creating Observable From Scratch
Get a better understanding of the RxJS Observable by implementing one that's similar from the ground ...
- OC教程10-NSNumber具体
NSNumber简单介绍 NSNumber是数字的对象形式,由于在OC的数组和字典中仅仅同意存放对象,所以我们有时候须要转化 我们普通的类型是 123 那么 NSNumber类型的是 @123, ...
- Ubuntu 12.04设置打开远程桌面登录1
teamviewer_linux.deb sudo dpkg --install teamviewer_linux.deb
- ORA-02069: global_names parameter must be set to TRUE for this operation
原因:在对远程表增删改操作的时候,调用了本地函数. 比如:insert into trans_load_rate@DC values(rate_s(1)); trans_load_rate是DC库的 ...
- js调用百度地图搜索功能
引用百度jsApi <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&a ...
- (转)关于font-size:100%
重设浏览器默认字体大小 h1,h2,h3,h4,h5,h6 {font-size:100%;font-weight:normal;} 假如你设置body{font-size:12px;} 但h1是不会 ...
- 将 varchar 值转换为 JDBC 数据类型 DATE 时发生错误。
问题是: 我是这样解决的 : 网上的 转型方法 并不好使 ,我想了想 可能是由于返回值是String 我 就成功的解决错误了 ..下面是关于原理的讲解肯定方法不唯一 至于错误,的产生,这个肯 ...
- tableview 分割线置最左边的解决方法
首先在viewDidLoad方法加入以下代码: if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { [se ...
- UI基础视图----UILabel总结
UILabel是UIKit框架中非常常用的视图类,是UIView的子类,是UIWindow,UIImageView等的兄弟类,因为继承自UIView,所以继承了UIView中的属性和方法,大部分都可以 ...
- MYSQLI DEMO
1.Select // DEMO mysqli连接方式参考 $db = new mysqli("localhost:3306", "root", "& ...