入门索引resin作为一款applicationserver,对jsp与servlet提供了良好的支持,自身采接用的java开发,与tomcat相比,各有优劣(resinvstom
入门索引
resin作为一款application server,对jsp与servlet提供了良好的支持,自身采接用的java开发,与tomcat相比,各有优劣(resin vs tomcat).对日志支持,resin旗下有自己的一个log系统,与log4j相比有过之无不及
初始环境搭建
环境搭建(参照中的hessianhessian的debug日志),resin版本4.0.52,jdk1.7,使用eclipse插件开发.
环境搭建完成,进行测试,log日志的配置大体区分显式与隐士,显示诸如log4j中的运用api显示调用,还有像resin这种通过配置隐式设置(这种区分只是方便自己理解)
初始log案例
web环境采用原始的servlet.新建web项目(空的web.xml)
pom.xml
4.0.0
stustu0.0.1-SNAPSHOTresin
warjavax.servletjavax.servlet-api3.0.1providedorg.apache.httpcomponentshttpclient4.5.3
servlet使用注解,故需要javax.servlet,使用postman测试,httpclient可注释掉
servlet
package log;import java.io.IOException;import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;@WebServlet("/log.do")
public class LogTestServlet extends HttpServlet{private static final long serialVersiOnUID= 1L;@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("call get");resp.getWriter().write("hello");}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("call post");doGet(req, resp);}
}
get访问http://localhost:8080/resin/log.do
默认打印,控制台
[17-08-08 20:19:01.148] {resin-16} WebApp[production/webapp/default/resin] active
log/access.log日志记录
0:0:0:0:0:0:0:1 - - [08/Aug/2017:20:19:01 +0800] "GET /resin/log.do HTTP/1.1" 200 5 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36"
结果解释
access.log的内容在conf/cluster-default.xml配置
path(
resin path)
format具体参数的意义(resin log)-
上面漏掉了两个(accesslog)
%l -Not used. Recognized but always results in "-"
%t-time
因为使用的浏览器访问本机,所以%h-访问的ip是0:0:0:0:0:0:0:1,没有的值以''-"代替
rollover-period is used to specify the time period, and can be in days (15D), weeks (2W), months (1M), or hours (1h).(设置归档日志的周期)
acccess-log 参数
其中有四个重要的参数,archive-format(如何归档,如压缩成zip),rollover-priod(周期),rollover-size(大小限制).rollover-count(日期限制)决定对日期进行归档
初始控制台打印内容由conf/resin.xml控制
logger是log-handler的具体解释,此处的两个logger主要用于启动时参数的配置,get第一次访问出现上述打印日志
具体参数解释(resin log hander)-
format
level
name
timesamp-时间格式,默认出现在行首,name根据包名来控制
注:conf下面几个配置文件resin.xml继承cluster-default.xml(集群配置),也就是resin配置的会覆盖cluster-default.xml的相关配置
resin log配置初窥
resin log标签(标签参考列表)
resin log主要通过一些标签完成log的基本配置
log--log format string,The format for log tags is used to specify a format string for each log message. format recognizes EL-expressions. The EL variable log is a com.caucho.log.ELFormatter.ELFormatterLogRecordobject.(个人理解log相对独立,作为一个log detail 描述性结构而存在,log相当于log-handler+logger)
logger--主要配置 JDK logging API, logger用于指定需要log的包及level(logger对log-handler的进一步解释)
child of ,,,,,(可以理解为作用域)
access-log --主要用于http输出
child of ,,,,,,,
stdout-log-用于标准输出(system.out)
child of ,,,,,
stderr-用于错误输出(system.err)
child of ,,,,,
resin项目配置
一个基本的项目的log配要满足:
- 日志层级分明(区分log的不同level,正常与异常)
- 日志错误异常记录
- 日志存储归类(比如按天存储)
- 打印请求响应(开发调试阶段)
对于一个容器来讲,还要区分不同的webapp
初步配置
主要更改了配置中的host,通过host区分不同的webapp,stdout与stderr承当一个显示记录日志的角色,通过path,archive-format等将不同的归档不同的日志(如一个webapp对应一个目录,每个周期对应一个目录等)
resin作为容器,其异常还可以由error-page标签处理
java.lang.RuntimeException/error.jsp
error.jsp
<%@ page language="java" cOntentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
${requestScope["javax.servlet.error.exception"]}
resin项目配置测试
package log;import java.io.IOException;import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;@WebServlet("/log.do")
public class LogTestServlet extends HttpServlet{private static final long serialVersiOnUID= 1L;@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("call get");System.err.println("error get");int i=1/0;resp.getWriter().write("hello");}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("call post");doGet(req, resp);}}
浏览器访问http://localhost:8080/resin/log.do
logs/localost目录下生成4个日志文件,access.log,error.log,stderr.log,stdout.log,打印内容
0:0:0:0:0:0:0:1 - - [09/Aug/2017:20:42:45 +0800] "GET /resin/log.do HTTP/1.1" 500 327 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36"
[2017-08-09 21:17:10]HttpServletRequestImpl[HttpRequest[app-0, 3]] java.lang.ArithmeticException: / by zeroat log.LogTestServlet.doGet(LogTestServlet.java:19)at javax.servlet.http.HttpServlet.service(HttpServlet.java:120)at javax.servlet.http.HttpServlet.service(HttpServlet.java:97)at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:109)at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:156)at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:95)at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:290)at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:838)at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:1353)at com.caucho.network.listen.TcpSocketLink.handleRequest(TcpSocketLink.java:1309)at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:1293)at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:1201)at com.caucho.network.listen.TcpSocketLink.handleAcceptTaskImpl(TcpSocketLink.java:997)at com.caucho.network.listen.ConnectionTask.runThread(ConnectionTask.java:117)at com.caucho.network.listen.ConnectionTask.run(ConnectionTask.java:93)at com.caucho.network.listen.SocketLinkThreadLauncher.handleTasks(SocketLinkThreadLauncher.java:169)at com.caucho.network.listen.TcpSocketAcceptThread.run(TcpSocketAcceptThread.java:61)at com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173)at com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118)
[2017.08.09 21:17:10]error getstdout.log
[2017.08.09 21:17:10]call get
页面跳转至error.jsp 页面显示
java.lang.ArithmeticException: / by zero