登录tomcat catalina.out的最简单方法 [英] simplest way to log to tomcat catalina.out

查看:79
本文介绍了登录tomcat catalina.out的最简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将日志写入tomcat/catalina.out的最简单方法是什么?我已经尝试过System.out.print()并且System.err.print()正常工作.

What is the simplest way to write logs to tomcat/catalina.out? I have tried System.out.print() and System.err.print() is working fine.

我只是想知道,尽管有sysoutsyserr,是否还有更好的选择可以使用?

I just want to know if there are better options to use despite of sysout and syserr?

推荐答案

您的日志记录

对于您自己的日志记录(由您自己的servlet代码生成的日志记录项目), Java的简单日志记录外观(SLF4J)是现代方式.此界面用作外观,可与多种可插拔实现中的任何一种一起使用.这些实现包括与Java,log4j,Logback等捆绑在一起的java.util.logging工具.

Your Logging

For your own logging (logging items generated by your own servlet code), Simple Logging Facade for Java (SLF4J) is the modern way. This interface acts as a façade to work with any of several pluggable implementations. Those implementations include the java.util.logging tool bundled with Java, log4j, Logback, and more.

登录是您应注意的.由多年前创建了著名的log​​4j的人创建. Logback是log4j的后继产品.同一个人还创建了SLF4J,以防止您被锁定在任何一个日志记录框架中.

Logback is the one you should look at. Created by the man who years ago created the famous log4j. Logback is meant to be the successor to log4j. The same man also created SLF4J as a way to prevent you from getting locked into any one logging framework.

您的servlet代码↔SLF4J↔Logback↔日志

Your servlet code ↔ SLF4J ↔ Logback ↔ logs

您可以通过多种方式配置LogBack以满足您的需求.您可以写入文本文件,将日志记录项发送到数据库,等等.

You can configure LogBack in a variety of ways to suit your needs. You can write to text files, send the logging items to a database, and more.

除了您自己的日志记录之外,还有Tomcat本身执行的日志记录问题,以跟踪每个传入的请求.

Besides your own logging, there is the question of the logging performed by Tomcat itself, to track every incoming request.

Tomcat通过Valve执行这种日志记录.默认情况下,那些日志记录项只是简单地写入文本文件.您可能还想做更多.

Tomcat performs such logging through a Valve. By default, those logging items are simply written to a text file. You may want to do more than that.

Logback提供了一个额外的模块 logback-access ,可与两个servlet容器 Tomcat Eclipse中的 Jetty .模块logback-access是Tomcat的Valve的扩展.通过扩展Valve,您可以替换默认行为.您可以将Tomcat自己的日志记录项发送到Logback基础结构(文件,数据库记录等).

Logback provides an extra module, logback-access for use with both the servlet containers Tomcat from Apache & Jetty from Eclipse. The module logback-access is an extension of Tomcat's Valve. By extending Valve, you can replace the default behavior. You can send Tomcat’s own logging items to your Logback infrastructure (files, database records, etc.).

这篇关于登录tomcat catalina.out的最简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆