[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 ...
随机推荐
- css_day6
- (转) .NET实现Repeater控件+AspNetPager控件分页
SqlConnection (.NET C#) 连接及分页 .net的访问数据机制决定了访问大量数据时会致使客户端机器消耗大量资源,因此有必要对数据进行分页显示,开发工具vs.net+sqlserve ...
- 《第一行代码》学习笔记12-UI(1)
1.程序需要注销或者退出,用一个专门的集合类对所有的活动进行管理即可. 2.可视化编辑工具不利于真正了解界面背后的实现原理,通常这种方式制作的界面都不具有很好的屏幕适配性, 而且当需要编写较为复杂的界 ...
- win7_64位主机装虚机Linux系统(VMware Workstation10+CentOS6.5)详细步骤图文讲解
第一步:创建新的虚拟机 第二步:选择“典型”安装 第三步:选择映像文件安装—浏览选择iso文件 第四步:选择稍后安装操作系统 第五步:系统选择Linux,版本选择centOS64位 第六步:虚拟机名称 ...
- Codeforces round #353div2 C
题目来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=117863#problem/C 题目大意:给你n个数字,代表这个人在n个银行里面 ...
- Tornado模块分类和各模块之间的关系
1. Core web framework tornado.web — 包含web框架的大部分主要功能,包含RequestHandler和Application两个重要的类 tornado.https ...
- C#将十六进制的文本转换到整型数据
1 length1 = Int32.Parse(szLine.Substring(1, 2), System.Globalization.NumberStyles.HexNumber);//计算这一行 ...
- Java语言中有4种访问修饰符
转载:http://wuhaidong.iteye.com/blog/851754 Java语言中有4种访问修饰符 在Java语言中有4中访问修饰符:package(默认).private.publi ...
- LeetCode_Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- LeetCode_Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...