28
28
<body >
29
29
<section name =" Logging" >
30
30
<p ></p >
31
- <p >MyBatis 는 내부 로그 팩토리를 사용하여 로깅 정보를 제공한다. 내부 로그 팩토리는 로깅 정보를 다른 로그 구현체 중
32
- 하나에 전달한다.</p >
31
+ <p >MyBatis provides logging information through the use of an
32
+ internal log factory. The internal log factory will delegate logging
33
+ information to one of the following log implementations:
34
+ </p >
33
35
<ul >
34
36
<li >
35
37
SLF4J
44
46
JDK logging
45
47
</li >
46
48
</ul >
47
- <p >로깅 솔루션은 내부 MyBatis 로그 팩토리의 런타임 체크를 통해 선택된다. MyBatis 로그 팩토리는 가능하면 첫번째
48
- 구현체를 사용할 것이다(위 로깅 구현체의 나열 순서는 내부적으로 선택하는 우선순위이다). 만약 MyBatis 가 위 구현체중
49
- 하나도 찾지 못한다면, 로깅을 하지 않을 것이다.</p >
50
- <p >많은 환경은 애플리케이션 서버(좋은 예는 Tomcat 과 WebSphere)의 클래스패스의 일부로 JCL 을 사용한다. 이러한 환경을
51
- 아는 것이 중요하다. MyBatis 는 로깅 구현체로 JCL 을 사용할 것이다. WebSphere 와 같은 환경에서 Log4J 설정은 무시될
52
- 것이다. 왜냐하면 WebSphere 는 자체 JCL 구현체를 제공하기 때문이다. 이러한 사항은 불만스러울수 있다. 왜냐하면
53
- MyBatis 는 당신의 Log4J 설정을 무시하는 것처럼 보일수도 있기 때문이다. (사실 MyBatis 는 당신의 Log4J 설정을
54
- 무시한다. 왜냐하면 MyBatis 는 이러한 환경에서 JCL 을 사용할 것이기 때문이다.) 만약 당신의 애플리케이션이
55
- 클래스패스에 JCL 을 포함한 환경에서 돌아가지만 다른 로깅 구현체 중 하나를 더 선호한다면, 다음의 메서드 중 하나를
56
- 호출하여 다른 로깅 구현체를 선택 할 수 있다.</p >
49
+ <p >The logging solution chosen is based on runtime introspection by
50
+ the internal MyBatis log factory. The MyBatis log factory will use
51
+ the first logging implementation it finds (implementations are
52
+ searched in the above order). If MyBatis finds none of the above
53
+ implementations, then logging will be disabled.
54
+ </p >
55
+ <p >Many environments ship Commons Logging as a part of the application server
56
+ classpath (good examples include Tomcat and WebSphere). It is
57
+ important to know that in such environments, MyBatis will use Commons Logging as
58
+ the logging implementation. In an environment like WebSphere this
59
+ will mean that your Log4J configuration will be ignored because
60
+ WebSphere supplies its own proprietary implementation of Commons Logging. This
61
+ can be very frustrating because it will appear that MyBatis is
62
+ ignoring your Log4J configuration (in fact, MyBatis is ignoring your
63
+ Log4J configuration because MyBatis will use Commons Logging in such
64
+ environments). If your application is running in an environment
65
+ where Commons Logging is included in the classpath but you would
66
+ rather use one of the other logging implementations you can select a
67
+ different logging implementation by calling one of the following
68
+ methods:
69
+ </p >
57
70
<source ><![CDATA[ org.apache.ibatis.logging.LogFactory.useSlf4jLogging();
58
71
org.apache.ibatis.logging.LogFactory.useLog4JLogging();
59
72
org.apache.ibatis.logging.LogFactory.useJdkLogging();
60
73
org.apache.ibatis.logging.LogFactory.useCommonsLogging();
61
74
org.apache.ibatis.logging.LogFactory.useStdOutLogging();]]> </source >
62
- <p >MyBatis 메서드를 호출하기 전에 위 메서드 중 하나를 호출해야 한다. 이 메서드들은 런타임 클래스패스에 구현체가
63
- 존재하면 그 로그 구현체를 사용하게 한다. 예를 들어, Log4J 로깅을 선택했지만 런타임에 Log4J 구현체가 클래스패스에
64
- 없다면, MyBatis 는 Log4J 구현체의 사용을 무시하고 로깅 구현체를 찾아 다시 사용할 것이다.</p >
65
- <p >Jakarta Commons 로깅, Log4J 그리고 JDK 로깅 API 에 대한 설명은 이 문서의 범위를 벗어난다. 이러한 로깅 관련
66
- 프레임워크에 대해 좀더 알고 싶다면, 개별 위치에서 좀더 많은 정보를 얻을 수 있을 것이다.</p >
75
+ <p >If you choose to call one of these methods, you should do so
76
+ before calling any other MyBatis method. Also, these methods
77
+ will only switch to the requested log implementation if that
78
+ implementation is available on the runtime classpath. For example, if
79
+ you try to select Log4J logging and Log4J is not available at runtime,
80
+ then MyBatis will ignore the request to use Log4J and will use it's
81
+ normal algorithm for discovering logging implementations.
82
+ </p >
83
+ <p >The specifics of SLF4J, Apache Commons Logging, Apache Log4J and the JDK
84
+ Logging API are beyond the scope of this document. However the
85
+ example configuration below should get you started. If you would like
86
+ to know more about these frameworks, you can get more information from
87
+ the following locations:
88
+ </p >
67
89
<ul >
90
+ <li >
91
+ <a href =" http://www.slf4j.org/" >SLF4J</a >
92
+ </li >
68
93
<li >
69
94
<a href =" http://commons.apache.org/logging" >Apache Commons Logging</a >
70
95
</li >
@@ -76,52 +101,111 @@ org.apache.ibatis.logging.LogFactory.useStdOutLogging();]]></source>
76
101
</li >
77
102
</ul >
78
103
<subsection name =" Logging Configuration" >
79
- <p >MyBatis 가 실제로 사용하는 로그 클래스는 MyBatis 패키지에 포함되어 있지 않다. MyBatis 로깅 구문을 보기 위해서는,
80
- java.sql 패키지의 클래스에 대해 로깅을 활성화해야 할 것이다. 해당되는 클래스 목록들이다.</p >
81
- <ul >
82
- <li ><code >java.sql.Connection</code ></li >
83
- <li ><code >java.sql.PreparedStatement</code ></li >
84
- <li ><code >java.sql.Resultset</code ></li >
85
- <li ><code >java.sql.Statement</code ></li >
86
- </ul >
87
- <p >Log4J 를 사용하는 방법을 보여줄 것이다. 로깅 서비스는 하나 이상이 설정파일(예를 들면, log4j.properties)과 새로운
88
- JAR 파일(예를 들면, log4j.jar)을 사용한다. 다음의 예제는 Log4J 를 사용하여 로깅 서비스를 설정할 것이다. 두가지 단계를
89
- 거친다.</p >
104
+ <p >To see MyBatis logging statements you may enable logging on a
105
+ package, a mapper fully qualified class name, a namespace
106
+ o a fully qualified statement name.
107
+ </p >
108
+ <p >Again, how you do this is dependent on the logging implementation
109
+ in use. We'll show how to do it with Log4J. Configuring the
110
+ logging services is simply a matter of including one or more extra
111
+ configuration files (e.g. log4j.properties) and sometimes a new JAR
112
+ file (e.g. log4j.jar). The following example configuration will
113
+ configure full logging services using Log4J as a provider. There
114
+ are 2 steps.
115
+ </p >
90
116
<p ></p >
91
- <h4 >첫번째 단계 : Log4J JAR 파일 추가하기</h4 >
92
- <p >Log4J 를 사용하기 때문에, 애플리케이션에 JAR 파일이 있어야 한다. Log4J 를 사용하기 위해, 애플리케이션의
93
- 클래스패스에 JAR 파일을 추가할 필요가 있다. 위 URL 에서 Log4J 를 다운로드 할 수 있다.</p >
94
- <p >웹이나 기업용 애플리케이션에서는 WEB-INF/lib 디렉터리에 log4j.jar 파일을 추가할 수 있다. 단독으로 실행되는
95
- 애플리케이션에서는 JVM 의 –classpath 시작 파라미터에서 간단히 추가할 수 있다.</p >
117
+ <h4 >
118
+ Step 1: Add the Log4J JAR file
119
+ </h4 >
120
+ <p >Because we are using Log4J, we will need to ensure its
121
+ JAR file is available to our application. To use Log4J, you need to
122
+ add the JAR file to your application classpath. You can download
123
+ Log4J from the URL above.
124
+ </p >
125
+ <p >For web or enterprise applications you can add the <code >log4j.jar</code > to
126
+ your <code >WEB-INF/lib</code > directory, or for a standalone application you can
127
+ simply add it to the JVM <code >-classpath</code > startup parameter.
128
+ </p >
96
129
<p ></p >
97
- <h4 >두번째 단계 : Log4J 설정하기</h4 >
98
- <p >Log4J 를 설정하는 것은 간단하다. 먼저 log4j.properties 파일을 만들어서 다음처럼 설정하면 된다.</p >
130
+ <h4 >
131
+ Step 2: Configure Log4J
132
+ </h4 >
133
+ <p >Configuring Log4J is simple. Suppose you want to enable the log for this mapper:
134
+ </p >
135
+ <source ><![CDATA[ package org.mybatis.example;
136
+ public interface BlogMapper {
137
+ @Select("SELECT * FROM blog WHERE id = #{id}")
138
+ Blog selectBlog(int id);
139
+ }]]> </source >
140
+ <p >Create a file called <code >log4j.properties</code >
141
+ as shown below and place it in your classpath:
142
+ </p >
99
143
<source ><![CDATA[ # Global logging configuration
100
144
log4j.rootLogger=ERROR, stdout
101
145
# MyBatis logging configuration...
102
- #log4j.logger.org.apache.ibatis=DEBUG
103
- #log4j.logger.java.sql.Connection=DEBUG
104
- #log4j.logger.java.sql.Statement=DEBUG
105
- #log4j.logger.java.sql.PreparedStatement=DEBUG
106
- #log4j.logger.java.sql.ResultSet=DEBUG
146
+ log4j.logger.org.mybatis.example.BlogMapper=TRACE
107
147
# Console output...
108
148
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
109
149
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
110
150
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n]]> </source >
111
- <p >위 파일은 에러만을 리포트하는 최소한의 설정이다. 파일의 두번째 라인은 stdout appender 에 에러만을 출력한다.
112
- appender 는 출력(예를 들면, 콘솔, 파일, 데이터베이스 등)을 모으는 컴포넌트이다. 로그를 최대한 출력하기 위해서는
113
- 다음처럼 설정을 변경해야 한다.</p >
114
- <p ></p >
115
- <source >log4j.rootLogger=DEBUG, stdout</source >
116
- <p ></p >
117
- <p >두번째 라인을 위처럼 변경하면, Log4J 는 ‘stdout’ appender 에 모든 로깅 이벤트를 출력한다. finer 레벨로 레벨을
118
- 조정하고자 한다면, 위 파일에서 ‘SqlMap 로깅 설정’(4 번째라인에서 8 번째라인까지) 에서 각 클래스별로 설정할 수 있다.
119
- PreparedStatement 에 대해 콘솔에 DEBUG 레벨로 로깅(SQL 구문)을 하고 싶다면, 다음처럼 7 번째 라인을 수정하면 된다.</p >
151
+ <p >
152
+ The above file will cause log4J to report detailed logging for
153
+ <code >org.mybatis.example.BlogMapper</code >
154
+ and just errors for the rest of the classes of your application.
155
+ </p >
156
+ <p >
157
+ If you want to tune the logging at a finer level you can turn logging
158
+ on for specific statements instead of the whole mapper file.
159
+ The following line will enable logging just for the <code >selectBlog</code >
160
+ statement:
161
+ </p >
162
+
163
+ <source >log4j.logger.org.mybatis.example.BlogMapper.selectBlog=TRACE</source >
164
+
165
+ <p >By the contrary you may want want to enable logging for a group of mappers.
166
+ In that case you should add as a logger the root package where your mappers reside:</p >
167
+
168
+ <source >log4j.logger.org.mybatis.example=TRACE</source >
169
+
170
+ <p >There are queries that can return huge result sets. In that cases you may want to see the
171
+ SQL stamentent but not the results. For that purpose SQL statements are logged with DEBUG level
172
+ (FINE in JDK logging) and results with TRACE level (FINER in JDK logging), so in case
173
+ you want to see the statement but not the result, set the level to DEBUG.
174
+ </p >
175
+
176
+ <source >log4j.logger.org.mybatis.example=DEBUG</source >
177
+
178
+ <p >But what about if you are not using mapper interfaces but mapper XML files like this one?
179
+ </p >
180
+
181
+ <source ><![CDATA[ <?xml version="1.0" encoding="UTF-8" ?>
182
+ <!DOCTYPE mapper
183
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
184
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
185
+ <mapper namespace="org.mybatis.example.BlogMapper">
186
+ <select id="selectBlog" parameterType="int" resultType="Blog">
187
+ select * from Blog where id = #{id}
188
+ </select>
189
+ </mapper>]]> </source >
190
+
191
+ <p >In that case you can enable logging for the whole XML file by adding
192
+ a logger for the namespace as shown below:</p >
193
+
194
+ <source >log4j.logger.org.mybatis.example.BlogMapper=TRACE</source >
195
+
196
+ <p >Or for an specific statement:</p >
197
+
198
+ <source >log4j.logger.org.mybatis.example.BlogMapper.selectBlog=TRACE</source >
120
199
121
- <source >log4j.logger.java.sql.PreparedStatement=DEBUG</source >
200
+ <p >Yes, as you may have noticed, there is no difference in configuring
201
+ logging for mapper interfaces or for XML mapper files.</p >
122
202
123
- <p >log4j.properties 파일에서 남은 설정은 appender 를 설정하기 위해 사용된다. 하지만 이 내용은 이 문서의 범위를 벗어난다.
124
- 어쨌든 Log4J 웹사이트에서 좀더 많은 정보를 찾을 수 있다.</p >
203
+ <p >The remaining configuration in the <code >log4j.properties</code > file is used
204
+ to configure the appenders, which is beyond the scope of this
205
+ document. However, you can find more information at the Log4J
206
+ website (URL above). Or, you could simply experiment with it to see
207
+ what effects the different configuration options have.
208
+ </p >
125
209
</subsection >
126
210
</section >
127
211
</body >
0 commit comments