4.DBAppender를 이용한 logging
logging_event 테이블의 컬럼정보
Field | Type | Description |
---|---|---|
timestamp | big int |
The timestamp that was valid at the logging event’s creation. |
formatted_message | text |
The message that has been added to the logging event, after formatting with org.slf4j.impl.MessageFormatter , in case objects were passed along with the message. |
logger_name | varchar |
The name of the logger used to issue the logging request. |
level_string | varchar |
The level of the logging event. |
reference_flag | smallint |
This field is used by logback to identify logging events that have an exception or Its value is computed by |
caller_filename | varchar |
The name of the file where the logging request was issued. |
caller_class | varchar |
The class where the logging request was issued. |
caller_method | varchar |
The name of the method where the logging request was issued. |
caller_line | char |
The line number where the logging request was issued. |
event_id | int |
The database id of the logging event. |
logging_event_property 테이블의 컬럼정보
Field | Type | Description |
---|---|---|
event_id | int |
The database id of the logging event. |
mapped_key | varchar |
The key of the MDC property |
mapped_value | text |
The value of the MDC property |
logging_event_exception 테이블의 컬럼정보
Field | Type | Description |
---|---|---|
event_id | int |
The database id of the logging event. |
i | smallint |
The index of the line in the full stack trace. |
trace_line | varchar |
The corresponding line |
database script 파일은 logback-classic jar 파일의 ch/qos/logback/classic/db/script/ 폴더에 데이타 베이스 별로 sql파일이 있습니다.
<property file="src/main/java/com/hello/logback/db/logback-db.properties" /> <appender name="DB" class="ch.qos.logback.classic.db.DBAppender"> <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource"> <driverClass>${driver}</driverClass> <url>${url}</url> <user>${user}</user> <password>${password}</password> </connectionSource> </appender>
property 파일을 이용하여 외부파일을 이용할수 있습니다.
5.SMTPAppender를 이용한 logging
구글smtp를 이용한 예제입니다.
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender"> <smtpHost>smtp.gmail.com</smtpHost> <!-- ssl --> <smtpPort>465</smtpPort> <SSL>true</SSL> <!-- tls를 사용할경우 <smtpPort>587</smtpPort> <STARTTLS>true</STARTTLS> --> <asynchronousSending>false</asynchronousSending> <username>xxxx</username> <password>xxxx</password> <to>yyyy@gmail.com</to> <subject>TEST-LOG: %logger{20} - %m</subject> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern> %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n </Pattern> </layout> </appender>
Evaluator , 필더를 이용하시면 세부적인 조건을 주실수 있습니다.(ex:error가 10번 이상 발생하였슬경우 발송 , 메일발송후 10분뒤 메일발송등) <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> 추가하시면 현재상태를 콘솔로 확인할수 있습니다.
이외에도 ServerSocketAppender , SSLServerSocketAppender , SyslogAppender 등이 있다.