MyBatis Log翻译

来源:互联网 发布:知乎 感动 句子 编辑:程序博客网 时间:2024/06/14 03:47

之前翻译的,后来发现了官方的翻译,对比了一下,自己的更像直译,今天偶然翻出来了,还是发下鞭策自己继续努力吧。

原文地址:传送门

MyBatis provides logging information through the use of an internal log factory. 

The internal log factory will delegate logging information to one of the following log implementations:


MyBatis通过使用内部日志工厂来提供日志信息。内部日志工厂将日志信息委托给一个下面的日志实现:


The logging solution chosen is based on runtime introspection by the internal MyBatis log factory. 
The MyBatis log factory will use the first logging implementation it finds (implementations are searched in the above order). 
If MyBatis finds none of the above implementations, then logging will be disabled.


选择日志解决方案是基于内部MyBatis日志工厂运行时的内省。MyBatis日志工厂将使用它找到的第一个日志实现(按上面的顺序搜索实现)。
如果MyBatis没有发现以上实现,那么日志将被禁用。


Many environments ship Commons Logging as a part of the application server classpath (good examples include Tomcat and WebSphere). 
It is important to know that in such environments, MyBatis will use Commons Logging as the logging implementation. 
In an environment like WebSphere this will mean that your Log4J configuration will be ignored because WebSphere supplies its own proprietary implementation of Commons Logging. 
This can be very frustrating because it will appear that MyBatis is ignoring your Log4J configuration (in fact, MyBatis is ignoring your Log4J configuration because MyBatis will use Commons Logging in such environments).
If your application is running in an environment where Commons Logging is included in the classpath 
but you would rather use one of the other logging implementations you can select a different logging implementation by adding a setting in mybatis-config.xml file as follows:


许多环境中通用日志作为应用服务器类路径的一部分(好的例子如Tomcat和WebSphere)。
重要的是要知道,在这样的环境中,MyBatis将使用通用日志作为日志的实现。
像WebSphere环境这将意味着你的Log4J配置将被忽略,因为WebSphere提供自身的通用日志实现。
这是非常令人沮丧的,因为会出现MyBatis无视你的Log4J配置的情况(事实上,MyBatis无视你的Log4J配置因为这样环境里MyBatis将使用通用日志)。
如果你的应用程序运行在一个在类路径中包含通用日志的环境中但你宁愿用另一种日志实现,你通过添加MyBatis中-config.xml文件中的设置选择一种不同的日志记录实现如下:


Valid values are SLF4J, LOG4J, LOG4J2, JDK_LOGGING, COMMONS_LOGGING, STDOUT_LOGGING, NO_LOGGING or a full qualified class name 
that implements org.apache.ibatis.logging.Log and gets an string as a constructor parameter.


有效的值如SLF4J,LOG4J,LOG4J2 JDK_LOGGING,COMMONS_LOGGING,STDOUT_LOGGING NO_LOGGING或一个完全实现org.apache.ibatis.logging的类名的一个字符串来作为构造函数的参数。


You can also select the implementation by calling one of the following methods:


您也可以通过调用以下方法之一选择实现:


If you choose to call one of these methods, you should do so before calling any other MyBatis method. Also, 
these methods will only switch to the requested log implementation if that implementation is available on the runtime classpath. 
For example, if you try to select Log4J logging and Log4J is not available at runtime, 
then MyBatis will ignore the request to use Log4J and will use it's normal algorithm for discovering logging implementations.


如果你选择调用这些方法其中的一个,你应该在调用任何其他MyBatis的方法之前这样做。
此外,这些方法只会切换到在运行时类路径中所请求的可用日志实现,
例如,如果你想选择Log4J日志记录而Log4J在运行时不可用,然后MyBatis将忽略使用Log4J的请求而使用它发现日志实现的正常算法。


The specifics of SLF4J, Apache Commons Logging, 
Apache Log4J and the JDK Logging API are beyond the scope of this document.
However the example configuration below should get you started. If you would like to know more about these frameworks, 
you can get more information from the following locations:


SLF4J,Apache Commons Logging,Apache Log4J和JDK Logging API的细节超出了本文的范围。
无论如何下面的示例配置应该让你开始。如果你想了解更多关于这些框架的信息,你可以从以下位置获得更多的信息:


To see MyBatis logging statements you may enable logging on a package, a mapper fully qualified class name, a namespace o a fully qualified statement name.


MyBatis日志语句你可以在一个包上启用日志记录,一个映射完全限定类名,或者一个完全合格的命名空间的名字。


Again, how you do this is dependent on the logging implementation in use. 
We'll show how to do it with Log4J. Configuring the logging services is simply a matter of including one or more extra configuration files (e.g. log4j.properties) and sometimes a new JAR file (e.g. log4j.jar). 
The following example configuration will configure full logging services using Log4J as a provider. There are 2 steps.


再次,你怎样做是取决于日志实现的使用。
我们将展示如何用Log4J做到这一点。配置日志服务是一个简单问题包括一个或多个额外的配置文件(如log4j . properties),有时一个新的JAR文件(如log4j.jar)。
下面的示例配置将使用Log4J配置完整的日志服务提供者。有两步。


Step 1: Add the Log4J JAR file


Because we are using Log4J, we will need to ensure its JAR file is available to our application. To use Log4J, 
you need to add the JAR file to your application classpath. You can download Log4J from the URL above.


第一步:添加Log4J JAR文件
因为我们正在使用Log4J,我们需要确保我们的应用程序的JAR文件是可用的。为了使用Log4J,您需要将JAR文件添加到应用程序的类路径中。你可以从上面的URL下载Log4J。


For web or enterprise applications you can add the log4j.jar to your WEB-INF/lib directory, 
or for a standalone application you can simply add it to the JVM -classpath startup parameter.


对于web或企业应用程序可以添加log4j.jar到WEB-INF/lib目录,或一个独立的应用程序可以简单地将其添加到JVM -classpath启动参数。


Step 2: Configure Log4J


Configuring Log4J is simple. Suppose you want to enable the log for this mapper:


第二步:配置Log4J
配置Log4J很简单。假设您想开启这个映射器的日志


Create a file called log4j.properties as shown below and place it in your classpath:


创建一个名为log4j.properties的文件并将其放到类路径,如下所示,:





0 0
原创粉丝点击