开发者

Custom Logging in Tomcat (design pattern)

开发者 https://www.devze.com 2022-12-26 23:07 出处:网络
I have java webapp (written in spring mvc) and running on tomcat. I want to log user\'s behavior into a separate log file (separate from what we\'re logging right now to catalina.out).

I have java webapp (written in spring mvc) and running on tomcat. I want to log user's behavior into a separate log file (separate from what we're logging right now to catalina.out).

We're currently using Apache commons logging to obtain Log instances in our classes:

protected final Log logger = LogFactory.getLog(getClass());

I prefer to开发者_运维百科 keep use LogFactory to access my customized logger (hence not creating a dependency on a specific logging package). Yet, I need to create my own handler (so that I route usage events to a separate file. e.g. usage.out), also need a custom formatter to format the logs. I wonder what is the best way to achieve this? What is the common practice?


You can use Simple Logging Facade for Java [1] with native implementation - Logback [2]. Then You can store logs in files or/and in database. Logback has also support for Tomcat [3]

  • [1] http://www.slf4j.org
  • [2] http://logback.qos.ch
  • [3] http://logback.qos.ch/access.html
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号