[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 ...
随机推荐
- python查看删除你微信的账号
#应用环境:python2.7 #!/usr/bin/env python # coding=utf-8 from __future__ import print_function import os ...
- WebApi2官网学习记录---单元测试
如果没有对应的web api模板,首先使用nuget进行安装 例子1: ProductController 是以硬编码的方式使用StoreAppContext类的实例,可以使用依赖注入模式,在外部指定 ...
- Linq中的多表左联,详细语句
from m in context.WX_MemberCollectDish join d in context.Dish on m.DishID equals d.DishID into temp ...
- silverlight+wcf 项目 silverlight获得web程序的参数
silverlight 可以通过属性InitParams 获得参数,如果参数是动态的需要web程序传递的,具体操作如下: web程序后台:AppID,USERID需要的参数 this.frmRepor ...
- JAVA 对象引用,以及对象赋值(转)
原文链接:http://zwmf.iteye.com/blog/1738574 关键字: java对象 引用 Java对象及其引用 关于对象与引用之间的一些基本概念. 初学Java时,在很长一段时间里 ...
- hdu 2642 Stars
Problem Description Yifenfei is a romantic guy and he likes to count the stars in the sky. To make t ...
- jQuery选择器的学习
jQuery的核心在于它的选择器,通过观看视频和阅读,发现jQuery选择器大体上的分类可分为这么几种(不同人方式不同,这里选择一个自认为比较好的): 1.基础选择器(对应api文档中的基本选择器和层 ...
- Android开发重修
Android程序开发的重新学习 #####Mars课程学习笔记20140926 1.Service主要用于完成耗时较长的操作,没有图形化界面. 2.Content Provider数据的提供者,是A ...
- 最短路--hdu2544
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- JDK Linux环境配置
① $sudo vi /etc/profile ② 在末尾行添加 #set java environment JAVA_HOME=/usr/local/jdk1.7.0 CLASSPATH=.:$JA ...