Вот как настроить бензопила 2.1 для чтения журналов регистрации, сохраненных с использованием DBAppender .
- Не загружать никакие плагины
- Загрузите драйвер SQL (например,
mysql-connector-java-5.1.36-bin.jar
) и сохраните его в <chainsaw>\repo
. - Отредактируйте сценарий запуска, чтобы добавить jar в путь к классам.Например, в
chainsaw.bat
используйте: set CLASSPATH = "% BASEDIR%" \ etc; "% REPO%" \ log4j \ apache-log4j-extras \ 1.1 \ apache-log4j-extras-1.1.jar; "% REPO%" \ log4j \ log4j \ 1.2.16 \ log4j-1.2.16.jar; "% REPO%" \ javax \ jmdns \ jmdns \ 3.4.1 \ jmdns-3.4.1.jar; "% РЕПО% "\ XStream \ XStream \ 1.1.2 \ XSTREAM-1.1.2.jar;" % REPO% "\ Викисклада VFS \ Викисклада VFS \ 1,0 \ Обще-VFS-1.0.jar;" % REPO% "\ свободного городского-logging \ Обще-каротаж \ 1.1.1 \ Обще-каротаж 1.1.1.jar; "% REPO%" \ ком \ JCraft \ JSch \ 0.1.42 \ JSch-0.1.42.jar; "% REPO%"\ log4j \ апач-бензопила \ 2.1.0-SNAPSHOT \ апач-бензопилой-2.1.0-SNAPSHOT.jar; "% REPO%" \ MySQL-разъем-Java-5.1.36-bin.jar
- При запуске выберите «Использовать файл конфигурации бензопилой»
Вот файл конфигурации, совместимый с DBAppender для входа в систему:
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<plugin name="Logs" class="org.apache.log4j.db.CustomSQLDBReceiver">
<param name="sql"
value="
SELECT
logger_name AS 'LOGGER',
from_unixtime (timestmp/1000) AS 'TIMESTAMP',
level_string AS 'LEVEL',
thread_name AS 'THREAD',
formatted_message AS 'MESSAGE',
(SELECT CONCAT('{{', group_concat(CONCAT(mapped_key, ',', mapped_value) SEPARATOR ','), '}}')
FROM logging_event_property
WHERE logging_event.event_id = logging_event_property.event_id
GROUP BY logging_event_property.event_id) AS 'NDC',
'' AS 'MDC',
caller_class AS 'CLASS',
caller_method AS 'METHOD',
caller_filename AS 'FILE',
caller_line AS 'LINE',
CONCAT('{{application,test,hostname,', (SELECT mapped_value FROM logging_event_property WHERE logging_event.event_id = logging_event_property.event_id AND mapped_key = 'HOSTNAME'), ',log4jid,', event_id,'}}') AS 'PROPERTIES',
IFNULL((SELECT group_concat(trace_line ORDER BY i ASC SEPARATOR '\n')
FROM logging_event_exception
WHERE logging_event.event_id = logging_event_exception.event_id
GROUP BY logging_event_exception.event_id),'') AS 'THROWABLE'
FROM logging_event
WHERE 1=1"/>
<connectionSource class="org.apache.log4j.db.DriverManagerConnectionSource">
<param name="driverClass" value="<driver, eg com.mysql.jdbc.Driver>"/>
<param name="url" value="jdbc:mysql://<url>/<schema>"/>
<param name="user" value="<user>"/>
<param name="password" value="<password>"/>
</connectionSource>
<param name="IDField" value="event_id"/>
<param name="refreshMillis" value="3000"/>
</plugin>
<root>
<level value="debug"/>
</root>
</log4j:configuration>
Select-in-select и where 1=1
предназначены для обхода поведения CustomSQLDBReceiver, связанного с неуклюжей конкатенацией WHERE event_id > -1
или AND event_id > -1
в конце выражения SQL.( См. Строки 306-313. )
Документация для CustomSQLDBReceiver
находится в в его javadoc .
Для Logback-Access (на EC2с ELB) я использую:
<plugin name="Access-Logs" class="org.apache.log4j.db.CustomSQLDBReceiver">
<param name="sql"
value="
SELECT
REPLACE (requestURI, '/', '.') AS 'LOGGER',
from_unixtime (timestmp/1000) AS 'TIMESTAMP',
'INFO' AS 'LEVEL',
IFNULL((SELECT header_value FROM access_event_header WHERE access_event.event_id = access_event_header.event_id AND header_key = 'x-forwarded-for'),'') AS 'THREAD',
requestURL AS 'MESSAGE',
'' AS 'NDC',
'' AS 'MDC',
'' AS 'CLASS',
'' AS 'METHOD',
'' AS 'FILE',
'' AS 'LINE',
CONCAT('{{application,test,hostname,access,log4jid,', event_id,'}}') AS 'PROPERTIES',
(SELECT group_concat(concat(header_key, ': ', header_value) SEPARATOR '\n')
FROM access_event_header
WHERE access_event.event_id = access_event_header.event_id
GROUP BY access_event_header.event_id) AS 'THROWABLE'
FROM access_event
WHERE (SELECT header_value
FROM access_event_header
WHERE access_event.event_id = access_event_header.event_id AND header_key = 'user-agent')
!= 'ELB-HealthChecker/1.0'"/>
<connectionSource class="org.apache.log4j.db.DriverManagerConnectionSource">
<param name="driverClass" value="com.mysql.jdbc.Driver"/>
<param name="url" value=""/>
<param name="user" value=""/>
<param name="password" value=""/>
</connectionSource>
<param name="IDField" value="access_event.event_id"/>
<param name="refreshMillis" value="3000"/>
</plugin>