1、tomcat发布项目 日志
今天用tomcat发布其他离职同事写的IndexBysolr项目,发现始终转向error.jsp页面,还以为是找不到请求路径错误或者别filter拦截了!!!!!!项目中配置了debug、info、error日志,从这些日志以及tomcat的catalina.out中没有发现任何有效信息。 tomcat中 stdout log and stderr log日志不打印到任何地方(windows下)!!!
------404、500等都转向error.jsp。问其他同事说不会把有效信息返回给用户,所以所有异常都返回了error.jsp文件,这也是我之前不知道的地方!!!!!
2、resin发布项目 日志
后来改为resin-4.0发布(起初也没有配置sdout、sderror日志),resin控制台输出了有效信息(action处理中 No live solrServer 信息),这个信息就是stout和sterror信息,tomcat控制台则神马都没有输出。
resin中 stdout log and stderr log 默认打印到控制台dos窗口(windows下);
resin中 stdout log and stderr log配置输出到文件,resin4.0.0中日志配置(resin.xml):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189<!-- - Resin 4.0 configuration file. - - See conf/full.xml for more sample configuration, including load - balancing and database configuration. --> <resin xmlns="http://caucho.com/ns/resin" xmlns:resin="urn:java:com.caucho.resin"> <!-- - driver .jar files can be placed in ${resin.root}/ext-lib --> <class-loader> <tree-loader path="${resin.root}/ext-lib"/> </class-loader> <!-- - project jars with maven dependencies can be placed - in project-jars to be used by web-apps. A WEB-INF/pom.xml will - select the project's artifacts. --> <resin:ProjectJarRepository path="${resin.root}/project-jars"/> <!-- - Remote management requires at least one enabled admin user. --> <resin:AdminAuthenticator> <resin:import path="${__DIR__}/admin-users.xml" optional="true"/> </resin:AdminAuthenticator> <!-- - Logging configuration for the JDK logging API. --> <log-handler name="" level="all" path="stdout:" timestamp="[%y-%m-%d %H:%M:%S.%s] {%{thread}} "/> <!-- - level='info' for production - 'fine' or 'finer' for development and troubleshooting --> <logger name="com.caucho" level="info"/> <logger name="com.caucho.java" level="config"/> <logger name="com.caucho.loader" level="config"/> <!-- - For production sites, change dependency-check-interval to something - like 600s, so it only checks for updates every 10 minutes. --> <dependency-check-interval>2s</dependency-check-interval> <!-- - SMTP server for sending mail notifications --> <system-property mail.smtp.host="127.0.0.1"/> <system-property mail.smtp.port="25"/> <!-- - default configuration applied to all clusters --> <cluster-default> <!-- standard servlet behavior, including .jsp, .php, and WEB-INF --> <resin:import path="${__DIR__}/app-default.xml"/> <!-- enables development error pages --> <development-mode-error-page/> <!-- - Enables the proxy cache (available in Resin Professional) --> <resin:if test="${resin.professional}"> <cache memory-size="64M"> <!-- Vary header rewriting for IE --> <rewrite-vary-as-private/> </cache> </resin:if> <!-- - Admin services --> <resin:DeployService/> <resin:if test="${resin.professional}"> <resin:JmxService/> <resin:LogService/> <resin:StatService/> <resin:XaLogService/> </resin:if> <!-- - Default host configuration applied to all virtual hosts. --> <host-default> <access-log path="logs/access.log" archive-format="access-%Y%m%d.log.gz" format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"' rollover-size="10mb" rollover-period="1D"/> <!-- - stdout log and stderr log --> <stdout-log path="logs/stdout.log" archive-format="stdout-%Y%m%d.log.gz" timestamp="[%Y.%m.%d %H:%M:%S.%s]" rollover-size="10mb" rollover-period="1D"/> <stderr-log path="logs/stderr.log" archive-format="stderr-%Y%m%d.log.gz" timestamp="[%Y.%m.%d %H:%M:%S.%s]" rollover-size="10mb" rollover-period="1D"/> <!-- creates the webapps directory for .war expansion --> <web-app-deploy path="webapps"/> </host-default> <!-- - Defaults applied to each web-app. --> <web-app-default> <prologue> <!-- - Enable EL expressions in Servlet and Filter init-param --> <allow-servlet-el/> </prologue> <!-- enable persistent sessions --> <session-config> <use-persistent-store/> </session-config> <!-- - Sets max-age for cacheable pages, e.g. static pages. --> <cache-mapping url-pattern="/" max-age="5s"/> <cache-mapping url-pattern="*.gif" max-age="60s"/> <cache-mapping url-pattern="*.jpg" max-age="60s"/> <cache-mapping url-pattern="*.png" max-age="60s"/> <cache-mapping url-pattern="*.css" max-age="60s"/> <cache-mapping url-pattern="*.js" max-age="60s"/> </web-app-default> </cluster-default> <!-- - Configures the main appliction cluster. Load-balancing configurations - will also have a load-balance-tier cluster. --> <cluster id="app-tier"> <!-- sets the content root for the cluster, relative to resin.root --> <root-directory>.</root-directory> <!-- defaults for each server, i.e. JVM --> <server-default> <!-- The http port --> <http address="*" port="8080"/> <!-- SSL port configuration: --> <http address="*" port="8443"> <jsse-ssl self-signed-certificate-name="resin@localhost"/> </http> <jvm-arg>-Xmx512m</jvm-arg> <!-- - <jvm-arg>-agentlib:resin</jvm-arg> --> <!-- - If starting Resin as root on Unix, specify the user name - and group name for the web server user. --> <resin:if test="${resin.userName == 'root'}"> <user-name>www-data</user-name> <group-name>www-data</group-name> </resin:if> </server-default> <!-- define the servers in the cluster --> <server id="" address="127.0.0.1" port="6800"> <!-- server-specific configuration, e.g. jvm-arg goes here --> </server> <!-- the default host, matching any host name --> <host id="" root-directory="."> <!-- - configures an explicit root web-app matching the - webapp's ROOT --> <web-app id="/" root-directory="webapps/ROOT"/> <web-app id="/IndexBysolr" root-directory="webapps/IndexBysolr"/> <!-- - Administration application /resin-admin --> <web-app id="/resin-admin" root-directory="${resin.root}/doc/admin"> <prologue> <resin:set var="resin_admin_external" value="false"/> <resin:set var="resin_admin_insecure" value="true"/> </prologue> </web-app> <!-- - Resin documentation - remove for a live site --> <web-app id="/resin-doc" root-directory="${resin.root}/doc/resin-doc"/> <!-- - <resin:LoadBalance regexp="^/load" cluster="backend-tier"/> - <resin:HttpProxy regexp="^/http" address="localhost:9000"/> - <resin:FastCgiProxy regexp="^/fcgi" address="localhost:9001"/> --> </host> </cluster> </resin>
Resin中对日志的设置主要有如下参数:log、logger、access-log、stdout-log和stderr-log。前两个放在<resin>标签,也就是主标签下面,其中log主要用于配置JDK logging API,logger用于指定需要log的包及level,跟log4j中的用法相似,只不过resin中level有个特殊的选项就是off,用于关闭日志输出;而后面三个*-log放在<host>或<host-default>下面,access用于HTTP输出,stdout用于标准输出(System.out),stderr用于错误输出(System.err,对应log4j中的log.error)。
三个*-log中间的属性是相同的,所以我们集中来说明一下:
- path: 用于设定日志文件的路径,非常有意思的是它支持所谓的El Variables and Functions,也就是resin中的变量,比如${host.name}就是虚拟站点的id名称,所以如果将它放在<host-default>下面的话,将path设置为 logs/${host.name}/access.log的话可以将不同站点的日志存放在不同的目录下面。
- archive-format: 这个参数可以设置日志归档的格式,如设置为access-%Y%m%d.log可以在归档的时候自动按日期进行归档命名。另外还有一个特性需要说明的是,resin竟然支持自动压缩log文件,而且设置的方法非常简单,只要后缀名是gz就可以了,如access-%Y%m%d.log.gz,这样归档的时候会自动压缩,而且支持windows和linux系统。
- format: 用于设置每条日志输出的格式,这个非常简单,而且通常使用系统内置的格式就可以了。
- rollover-size: 用来设置归档日志文件的最小尺寸,单位可以设置成kb、mb等等,默认为1mb。
- rollover-period: 用来设置归档日志文件的周期,单位可以是1D(一天)、1W(一周)、1M(一个月)等。
最后给出一个范例供大家参考:
- <!--
- - Resin 3.1 configuration file.
- -->
- <resin xmlns="http://caucho.com/ns/resin"
- xmlns:resin="http://caucho.com/ns/resin/core">
- <!--
- - Logging configuration for the JDK logging API.
- -->
- <log name="" level="off" path="stdout:"
- timestamp="[%H:%M:%S.%s] {%{thread}} "/>
- <!--
- - 'info' for production
- - 'fine' or 'finer' for development and troubleshooting
- -->
- <logger name="com.caucho" level="info"/>
- <logger name="com.caucho.java" level="config"/>
- <logger name="com.caucho.loader" level="config"/>
- <host-default>
- <!--
- - With another web server, like Apache, this can be commented out
- - because the web server will log this information.
- -->
- <access-log path="logs/${host.name}/access.log"
- archive-format="access-%Y%m%d.log.gz"
- format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'
- rollover-size="10mb"
- rollover-period="1D"/>
- <!--
- - stdout log and stderr log
- -->
- <stdout-log path="logs/${host.name}/stdout.log"
- archive-format="stdout-%Y%m%d.log.gz"
- timestamp="[%Y.%m.%d %H:%M:%S.%s]"
- rollover-size="10mb"
- rollover-period="1D"/>
- <stderr-log path="logs/${host.name}/stderr.log"
- archive-format="stderr-%Y%m%d.log.gz"
- timestamp="[%Y.%m.%d %H:%M:%S.%s]"
- rollover-size="10mb"
- rollover-period="1D"/>
- </host-default>
- </resin>
最后还有一个事情需要说明一下,如果在windows系统下将resin注册成服务程序之后就会在log目录下产生jvm-defautl.log文件,而且这个文件会一直累加,所以会变的文件非常大而影响resin的性能。原来在Apache和Resin产生大容量日志的解决办法这篇文件中提到的使用httpd -jvm-log NUL的方法在3.1中无法使用,而且查找了大量的文档也没有找到合适的方法,后来索性将log目录中的写入权限去掉了,重启resin也没有任何影响,算是解决了这个问题。
参考资料:
http://caucho.com/resin-3.1/doc/config-log.xtp
http://caucho.com/resin-3.1/doc/el-var.xtp#host
最后
以上就是冷艳小丸子最近收集整理的关于resin和tomcat 日志配置的全部内容,更多相关resin和tomcat内容请搜索靠谱客的其他文章。
发表评论 取消回复