logback-dev
Threads by month
- ----- 2025 -----
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
November 2006
- 5 participants
- 262 discussions

svn commit: r883 - in logback/trunk: logback-core/src/main/java/ch/qos/logback/core/db logback-examples/src/main/java/chapter4/db logback-site/src/site logback-site/src/site/resources/manual/images/chapter4 logback-site/src/site/xdocTemplates/manual
by noreply.seb@qos.ch 08 Nov '06
by noreply.seb@qos.ch 08 Nov '06
08 Nov '06
Author: seb
Date: Wed Nov 8 10:06:07 2006
New Revision: 883
Added:
logback/trunk/logback-site/src/site/resources/manual/images/chapter4/
logback/trunk/logback-site/src/site/resources/manual/images/chapter4/dbAppenderLE.gif (contents, props changed)
logback/trunk/logback-site/src/site/resources/manual/images/chapter4/dbAppenderLEException.gif (contents, props changed)
logback/trunk/logback-site/src/site/resources/manual/images/chapter4/dbAppenderLEProperty.gif (contents, props changed)
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DataSourceConnectionSource.java
logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-driverManager.xml
logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-datasource.xml
logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-drivermanager.xml
logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-jndi.xml
logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-pooled-datasource.xml
logback/trunk/logback-site/src/site/ (props changed)
logback/trunk/logback-site/src/site/site.xml
logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml
Log:
On Work in progress on chapter 4
- DBAppender documentation
- configuration examples
- minor tweaks to site aesthetics
- added illustrations for dbAppender
- modified .svnignore on src/site
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DataSourceConnectionSource.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DataSourceConnectionSource.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DataSourceConnectionSource.java Wed Nov 8 10:06:07 2006
@@ -10,21 +10,19 @@
package ch.qos.logback.core.db;
-
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
-
/**
- * The DataSourceConnectionSource is an implementation of {@link ConnectionSource}
- * that obtains the Connection in the recommended JDBC manner based on
- * a {@link javax.sql.DataSource DataSource}.
- * <p>
- *
- * @author Ray DeCampo
- * @author Ceki Gülcü
+ * The DataSourceConnectionSource is an implementation of
+ * {@link ConnectionSource} that obtains the Connection in the recommended JDBC
+ * manner based on a {@link javax.sql.DataSource DataSource}.
+ * <p>
+ *
+ * @author Ray DeCampo
+ * @author Ceki Gülcü
*/
public class DataSourceConnectionSource extends ConnectionSourceBase {
@@ -32,20 +30,21 @@
@Override
public void start() {
- //LogLog.debug("**********DataSourceConnectionSource.activateOptions called");
if (dataSource == null) {
addWarn("WARNING: No data source specified");
} else {
Connection connection = null;
try {
connection = getConnection();
- } catch(SQLException se) {
- addWarn("Could not get a connection to discover the dialect to use.", se);
+ } catch (SQLException se) {
+ addWarn("Could not get a connection to discover the dialect to use.",
+ se);
}
- if(connection != null) {
+ if (connection != null) {
discoverConnnectionProperties();
- }
- if(!supportsGetGeneratedKeys() && getSQLDialectCode() == ConnectionSource.UNKNOWN_DIALECT) {
+ }
+ if (!supportsGetGeneratedKeys()
+ && getSQLDialectCode() == ConnectionSource.UNKNOWN_DIALECT) {
addWarn("Connection does not support GetGeneratedKey method and could not discover the dialect.");
}
}
Modified: logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-driverManager.xml
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-driverManager.xml (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-driverManager.xml Wed Nov 8 10:06:07 2006
@@ -1,23 +1,22 @@
-<configuration>
-
- <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
- <connectionSource class="ch.qos.logback.classic.db.DriverManagerConnectionSource">
- <driverClass>"com.mysql.jdbc.Driver</driverClass>
- <url>jdbc:mysql://host_name:3306/datebase_name</url>
- <user>logback</user>
- <password>logback</password>
- </connectionSource>
- </appender>
+<?xml version="1.0" encoding="UTF-8" ?>
+<configuration>
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <layout class="ch.qos.logback.classic.PatternLayout">
- <pattern>%level %thread %logger - %msg%n</pattern>
- </layout>
- </appender>
- <root>
- <level value="debug"/>
- <appender-ref ref="STDOUT"/>
- <appender-ref ref="DB"/>
- </root>
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
+ <driverClass>com.mysql.jdbc.Driver</driverClass>
+ <url>jdbc:mysql://host_name:3306/datebase_name</url>
+ <user>username</user>
+ <password>password</password>
+ </connectionSource>
+ </appender>
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="DB" />
+ </root>
</configuration>
Modified: logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-datasource.xml
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-datasource.xml (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-datasource.xml Wed Nov 8 10:06:07 2006
@@ -6,6 +6,10 @@
<connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
<dataSource class="${dataSourceClass}">
+ <!-- Joran cannot substitute variables
+ that are not attribute values. Therefore, we cannot
+ declare the next parameter like the others.
+ -->
<param name="${url-key:-url}" value="${url}"/>
<serverName>${serverName}</serverName>
<databaseName>${databaseName}</databaseName>
Modified: logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-drivermanager.xml
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-drivermanager.xml (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-drivermanager.xml Wed Nov 8 10:06:07 2006
@@ -3,7 +3,8 @@
<configuration>
<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
- <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
+ <connectionSource
+ class="ch.qos.logback.core.db.DriverManagerConnectionSource">
<driverClass>${driverClass}</driverClass>
<url>${url}</url>
<user>${user}</user>
Modified: logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-jndi.xml
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-jndi.xml (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-jndi.xml Wed Nov 8 10:06:07 2006
@@ -4,7 +4,7 @@
<!-- We create a joran rule that will instance and bind the appropriate
data source instance to JNDI. -->
<newRule pattern="configuration/bindDataSourceToJNDI"
- actionClass="org.apache.log4j.db.BindDataSourceToJNDIAction"/>
+ actionClass="ch.qos.logback.core.db.BindDataSourceToJNDIAction"/>
<bindDataSourceToJNDI />
@@ -12,6 +12,10 @@
<connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
<dataSource class="${dataSourceClass}">
+ <!-- Joran cannot substitute variables
+ that are not attribute values. Therefore, we cannot
+ declare the next parameter like the others.
+ -->
<param name="${url-key:-url}" value="${url}"/>
<serverName>${serverName}</serverName>
<databaseName>${databaseName}</databaseName>
Modified: logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-pooled-datasource.xml
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-pooled-datasource.xml (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-pooled-datasource.xml Wed Nov 8 10:06:07 2006
@@ -6,6 +6,10 @@
<connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
<dataSource class="${pooledDataSourceClass}">
+ <!-- Joran cannot substitute variables
+ that are not attribute values. Therefore, we cannot
+ declare the next parameter like the others.
+ -->
<param name="${url-key:-url}" value="${url}"/>
<serverName>${serverName}</serverName>
<databaseName>${databaseName}</databaseName>
Added: logback/trunk/logback-site/src/site/resources/manual/images/chapter4/dbAppenderLE.gif
==============================================================================
Binary file. No diff available.
Added: logback/trunk/logback-site/src/site/resources/manual/images/chapter4/dbAppenderLEException.gif
==============================================================================
Binary file. No diff available.
Added: logback/trunk/logback-site/src/site/resources/manual/images/chapter4/dbAppenderLEProperty.gif
==============================================================================
Binary file. No diff available.
Modified: logback/trunk/logback-site/src/site/site.xml
==============================================================================
--- logback/trunk/logback-site/src/site/site.xml (original)
+++ logback/trunk/logback-site/src/site/site.xml Wed Nov 8 10:06:07 2006
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
-<project name="Logback Main Site">
+<project name="Logback Project">
<skin>
<groupId>ch.qos.logback</groupId>
@@ -10,7 +10,7 @@
<publishDate position="navigation-bottom" format="dd-MM-yyyy"/>
<bannerLeft>
- <name>${project.name}</name>
+ <name>Logback Project</name>
<src>/images/logos/lblogo.jpg</src>
<href>http://logback.qos.ch</href>
</bannerLeft>
@@ -24,7 +24,7 @@
</links>
-->
- <menu name="${project.name}">
+ <menu name="Logback Project">
<item name="Introduction" href="index.html"/>
<item name="News" href="news.html" />
<item name="Download" href="download.html" />
Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml (original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml Wed Nov 8 10:06:07 2006
@@ -1380,9 +1380,10 @@
<h3>SMTPAppender</h3>
<p>
- The <code>SMTPAppender</code> accumulates logging events in a fixed-size
- buffer and sends them in an email when a user specified triggering event occurs.
- By default, the triggering event is taken as the reception of an event
+ The <a href="../xref/ch/qos/logback/classic/net/SMTPAppender.html"><code>SMTPAppender</code></a>
+ accumulates logging events in a fixed-size buffer and sends them in an email when a
+ user specified triggering event occurs.
+ By default, the triggering event is taken as the reception of an event
of level <em>ERROR</em> or higher.
</p>
@@ -1643,17 +1644,331 @@
</configuration></pre></div>
<h3>DBAppender</h3>
+
+ <p>
+ The <a href="../xref/ch/qos/logback/classic/db/DBAppender.html"><code>DBAppender</code></a>
+ inserts loggin events into three database tables in a format
+ independent of the Java programming language.
+ </p>
+ <p>
+ These three tables are <em>logging_event</em>, <em>logging_event_property</em> and
+ <em>logging_event_exception</em>. They all must exist before <code>DBAppender</code>
+ can be used. Logback ships with SQL scripts that will create the tables.
+ They can be found in the found in the
+ <em>logback-classic/src/main/java/ch/qos/logback/classic/db/dialect</em> directory. There
+ is a specific script for each of the most popular database systems.
+ If the script for your particular type of database system is missing, it should be
+ quite easy to write one, taking example on the already existing scripts. If
+ you send them to us, we will gladly include missing scripts in future
+ </p>
+ <p>
+ If the JDBC driver you are using supports the
+ <code>getGeneratedKeys</code> method introduced in
+ JDBC 3.0 specification, then no more steps are required, excluding usual
+ configuration.
+ </p>
+ <p>
+ Otherwise, there must be an <code>SQLDialect</code> appropriate for your
+ database system. Currently, we have dialects for PostgreSQL,
+ MySQL, Oracle and MsSQL. As mentioned previously, an
+ <code>SQLDialect</code> is required only if the JDBC driver for your
+ database system does not support the <code>getGeneratedKeys</code>
+ method.
+ </p>
+ <p>
+ The table below summarizes the database tapes and their support of the
+ <code>getGeneratedKeys()</code> method.
+ </p>
+ <table border="1" cellpadding="4">
+ <tr>
+ <th>RDBMS</th>
+ <th>
+ supports
+ <br />
+ <code>getGeneratedKeys()</code>
+ method
+ </th>
+ <th>
+ specific
+ <br />
+ SQLDialect support
+ </th>
+ </tr>
+ <tr>
+ <td>PostgreSQL</td>
+ <td>NO</td>
+ <td>present and used</td>
+ </tr>
+ <tr>
+ <td>MySQL</td>
+ <td>YES</td>
+ <td>present, but not actually needed or used</td>
+ </tr>
+ <tr>
+ <td>Oracle</td>
+ <td>YES</td>
+ <td>present, but not actually needed or used</td>
+ </tr>
+ <tr>
+ <td>DB2</td>
+ <td>YES</td>
+ <td>not present, and not needed or used</td>
+ </tr>
+ <tr>
+ <td>MsSQL</td>
+ <td>YES</td>
+ <td>not present, and not needed or used</td>
+ </tr>
+ <tr>
+ <td>HSQL</td>
+ <td>NO</td>
+ <td>present and used</td>
+ </tr>
+ </table>
+
+ <p>
+ Experiments show that writing a single event
+ into the database takes approximately 50 milliseconds, on a
+ "standard" PC. If pooled connections are used, this figure
+ drops to under 10 milliseconds. Note that most JDBC drivers
+ already ship with connection pooling support.
+ </p>
+
+ <p>
+ Configuring logback to use <code>DBAppender</code> can be done
+ in several different ways, depending on the tools one has to
+ connect to the database, and the database itself.
+ </p>
+
+ <p>
+ The first example that we will review is a configuration using
+ <code>DriverManagerConnectionSource</code> and a MySQL database.
+ The following configuration file is what one would need.
+ </p>
+
+<em>Example 4.6: <code>DBAppender</code> configuration (logback-examples/src/main/java/chapter4/db/append-toMySQL-with-driverManager.xml)</em>
+<div class="source"><pre><configuration>
+ <b><appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
+ <driverClass>com.mysql.jdbc.Driver</driverClass>
+ <url>jdbc:mysql://host_name:3306/datebase_name</url>
+ <user>username</user>
+ <password>password</password>
+ </connectionSource>
+ </appender></b>
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="DB" />
+ </root>
+</configuration></pre></div>
+ <p>
+ The correct driver must be declared. Here, the <code>com.mysql.jdbc.Driver</code>
+ class is used. The <span class="option">url</span> must begin with <em>jdbc:myslq://</em>.
+ </p>
+
+ <p>Connecting to a database using a <code>DataSource</code> is rather similar:</p>
+
+<em>Example 4.7: <code>DBAppender</code> configuration (logback-examples/src/main/java/chapter4/db/append-with-datasource.xml)</em>
+<div class="source"><pre><configuration>
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <b><connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
+
+ <dataSource class="${dataSourceClass}">
+ </b><!-- Joran cannot substitute variables
+ that are not attribute values. Therefore, we cannot
+ declare the next parameter like the others.
+ -->
+ <b><param name="${url-key:-url}" value="${url_value}"/>
+ <serverName>${serverName}</serverName>
+ <databaseName>${databaseName}</databaseName>
+ </dataSource></b>
+
+ <user>${user}</user>
+ <password>${password}</password>
+ </connectionSource>
+ </appender>
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="DB" />
+ </root>
+</configuration></pre></div>
+ <p>
+ Not that in this configuration sample, we make heavy use of substitution variables.
+ They are sometimes handy when connection details have to be centralised in a
+ single configuration file and shared by logback and other frameworks.
+ </p>
+
+ <p>
+ Once logback is configured properly, the logging events are sent to
+ the specified database. As stated previously, there are three tables
+ used by logback to store logging event data.
+ </p>
+
+ <p>
+ The <em>logging_event</em> table contains the following fields:
+ </p>
+ <table>
+ <tr>
+ <th>Field</th>
+ <th>Type</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td><b>timestmp</b></td>
+ <td><code>big int</code></td>
+ <td>The timestamp that was valid at the logging event's creation.</td>
+ </tr>
+ <tr>
+ <td><b>formatted_message</b></td>
+ <td><code>text</code></td>
+ <td>The message that has been added to the logging event, after formatting with
+ <code>org.slf4j.impl.MessageFormatter</code>, in case object were passed
+ along with the message.</td>
+ </tr>
+ <tr>
+ <td><b>logger_name</b></td>
+ <td><code>varchar</code></td>
+ <td>The name of the logger used to issue the logging request.</td>
+ </tr>
+ <tr>
+ <td><b>level_string</b></td>
+ <td><code>varchar</code></td>
+ <td>The level of the logging event.</td>
+ </tr>
+ <tr>
+ <td><b>reference_flag</b></td>
+ <td><code>smallint</code></td>
+ <td>
+ <p>
+ This field is used by logback to identify logging events that
+ have an exception or <code>MDC</code>property values associated.
+ </p>
+ <p>
+ It's value is computed by
+ <code>ch.qos.logback.classic.db.DBHelper</code>. A logging event that
+ contains <code>MDC</code> or <code>Context</code>
+ properties has a flag number of <em>1</em>. One
+ that contains an exception has a flag number of <em>2</em>. A logging
+ event that contains both elements has a flag number of <em>3</em>.
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td><b>caller_filename</b></td>
+ <td><code>varchar</code></td>
+ <td>The name of the file where the logging request was issued.</td>
+ </tr>
+ <tr>
+ <td><b>caller_class</b></td>
+ <td><code>varchar</code></td>
+ <td>The class where the logging request was issued.</td>
+ </tr>
+ <tr>
+ <td><b>caller_method</b></td>
+ <td><code>varchar</code></td>
+ <td>The name of the method where the logging request was issued.</td>
+ </tr>
+ <tr>
+ <td><b>caller_line</b></td>
+ <td><code>char</code></td>
+ <td>The line number where the logging request was issued.</td>
+ </tr>
+ <tr>
+ <td><b>event_id</b></td>
+ <td><code>int</code></td>
+ <td>The database id of the logging event.</td>
+ </tr>
+ </table>
+
+ <p>
+ The <em>logging_event_property</em> is used to store the keys and values
+ contained in the <code>MDC</code> or the <code>Context</code>.
+ It contains these fields:
+ </p>
+ <table>
+ <tr>
+ <th>Field</th>
+ <th>Type</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td><b>event_id</b></td>
+ <td><code>int</code></td>
+ <td>The database id of the logging event.</td>
+ </tr>
+ <tr>
+ <td><b>mapped_key</b></td>
+ <td><code>varchar</code></td>
+ <td>The key of the <code>MDC</code> property</td>
+ </tr>
+ <tr>
+ <td><b>mapped_value</b></td>
+ <td><code>text</code></td>
+ <td>The value of the <code>MDC</code> property</td>
+ </tr>
+ </table>
+
+ <p>
+ The <em>logging_event_exception</em> table contains the following fields:
+ </p>
+
+ <table>
+ <tr>
+ <th>Field</th>
+ <th>Type</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td><b>event_id</b></td>
+ <td><code>int</code></td>
+ <td>The database id of the logging event.</td>
+ </tr>
+ <tr>
+ <td><b>i</b></td>
+ <td><code>smallint</code></td>
+ <td>The index of the line in the full stack trace.</td>
+ </tr>
+ <tr>
+ <td><b>trace_line</b></td>
+ <td><code>varchar</code></td>
+ <td>The corresponding line</td>
+ </tr>
+ </table>
+
+ <p>
+ To give a more visual example of the work done by <code>DBAppender</code>, here
+ is a screenshot of a MySQL database with content provided by <code>DBAppender</code>.
+ </p>
+
+ <p>The <em>logging_event</em> table:</p>
+ <img src="images/chapter4/dbAppenderLE.gif" alt="Logging Event table" />
+ <p>The <em>logging_event_exception</em> table:</p>
+
+ <img src="images/chapter4/dbAppenderLEException.gif" alt="Logging Event Exception table" />
+ <p>The <em>logging_event_property</em> table:</p>
+
+ <img src="images/chapter4/dbAppenderLEProperty.gif" alt="Logging Event Property table" />
<h3>SyslogAppender</h3>
1
0

svn commit: r882 - logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db
by noreply.seb@qos.ch 07 Nov '06
by noreply.seb@qos.ch 07 Nov '06
07 Nov '06
Author: seb
Date: Tue Nov 7 14:46:11 2006
New Revision: 882
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/BindDataSourceToJNDIAction.java
Log:
added BindDataSourceToJNDIAction.java
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/BindDataSourceToJNDIAction.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/BindDataSourceToJNDIAction.java Tue Nov 7 14:46:11 2006
@@ -0,0 +1,85 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+package ch.qos.logback.core.db;
+
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
+import org.xml.sax.Attributes;
+
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.InterpretationContext;
+import ch.qos.logback.core.util.OptionHelper;
+import ch.qos.logback.core.util.PropertySetter;
+
+/**
+ *
+ * @author Ceki Gulcu
+ *
+ */
+public class BindDataSourceToJNDIAction extends Action {
+
+ static final String DATA_SOURCE_CLASS = "dataSourceClass";
+ static final String URL = "url";
+ static final String USER = "user";
+ static final String PASSWORD = "password";
+
+ /**
+ * Instantiates an a data source and bind it to JNDI
+ * Most of the required parameters are placed in the ec.substitutionProperties
+ */
+ public void begin(
+ InterpretationContext ec, String localName, Attributes attributes) {
+ String dsClassName = ec.getSubstitutionProperty(DATA_SOURCE_CLASS);
+
+ if (OptionHelper.isEmpty(dsClassName)) {
+ addWarn("dsClassName is a required parameter");
+ ec.addError("dsClassName is a required parameter");
+
+ return;
+ }
+
+ String urlStr = ec.getSubstitutionProperty(URL);
+ String userStr = ec.getSubstitutionProperty(USER);
+ String passwordStr = ec.getSubstitutionProperty(PASSWORD);
+
+ try {
+ DataSource ds =
+ (DataSource) OptionHelper.instantiateByClassName(dsClassName, DataSource.class);
+
+ PropertySetter setter = new PropertySetter(ds);
+
+ if (!OptionHelper.isEmpty(urlStr)) {
+ setter.setProperty("url", urlStr);
+ }
+
+ if (!OptionHelper.isEmpty(userStr)) {
+ setter.setProperty("user", userStr);
+ }
+
+ if (!OptionHelper.isEmpty(passwordStr)) {
+ setter.setProperty("password", passwordStr);
+ }
+
+ Context ctx = new InitialContext();
+ ctx.rebind("dataSource", ds);
+ } catch (Exception oops) {
+ addError(
+ "Could not bind datasource. Reported error follows.", oops);
+ ec.addError("Could not not bind datasource of type [" + dsClassName + "].");
+ }
+ }
+
+ public void end(InterpretationContext ec, String name) {
+ }
+}
1
0

07 Nov '06
Author: seb
Date: Tue Nov 7 11:45:21 2006
New Revision: 881
Removed:
logback/trunk/logback-classic/src/test/input/db/
Log:
moved example configurations to example module
moved deleteTables.sql to appropriate package
1
0

svn commit: r880 - in logback/trunk: logback-core/src/main/java/ch/qos/logback/core/db/dialect logback-examples/src/main/java/chapter4/db
by noreply.seb@qos.ch 07 Nov '06
by noreply.seb@qos.ch 07 Nov '06
07 Nov '06
Author: seb
Date: Tue Nov 7 11:44:25 2006
New Revision: 880
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/deleteTables.sql
- copied unchanged from r879, /logback/trunk/logback-classic/src/test/input/db/deleteTables.sql
logback/trunk/logback-examples/src/main/java/chapter4/db/
logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-driverManager.xml
logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-c3p0.xml
logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-datasource.xml
logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-drivermanager.xml
logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-jndi.xml
logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-pooled-datasource.xml
Log:
moved example configurations to example module
moved deleteTables.sql to appropriate package
Added: logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-driverManager.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-toMySQL-with-driverManager.xml Tue Nov 7 11:44:25 2006
@@ -0,0 +1,23 @@
+<configuration>
+
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.classic.db.DriverManagerConnectionSource">
+ <driverClass>"com.mysql.jdbc.Driver</driverClass>
+ <url>jdbc:mysql://host_name:3306/datebase_name</url>
+ <user>logback</user>
+ <password>logback</password>
+ </connectionSource>
+ </appender>
+
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <pattern>%level %thread %logger - %msg%n</pattern>
+ </layout>
+ </appender>
+ <root>
+ <level value="debug"/>
+ <appender-ref ref="STDOUT"/>
+ <appender-ref ref="DB"/>
+ </root>
+</configuration>
Added: logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-c3p0.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-c3p0.xml Tue Nov 7 11:44:25 2006
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
+ <dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
+ <driverClass>${driverClass}</driverClass>
+ <jdbcUrl>${url}</jdbcUrl>
+ <serverName>${serverName}</serverName>
+ <databaseName>${databaseName}</databaseName>
+ <user>${user}</user>
+ <password>${password}</password>
+ <!--
+ <param name="initialConnections" value="10"/>
+ <param name="maxConnections" value="10"/>
+
+ <param name="max-connections" value="100"/>
+ <param name="min-connections" value="5" />
+ <param name="inactivity-timeout" value="200"/>
+ -->
+ </dataSource>
+
+ <user>${user}</user>
+ <password>${password}</password>
+ </connectionSource>
+ </appender>
+
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="DB" />
+ </root>
+</configuration>
+
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-datasource.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-datasource.xml Tue Nov 7 11:44:25 2006
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
+
+ <dataSource class="${dataSourceClass}">
+ <param name="${url-key:-url}" value="${url}"/>
+ <serverName>${serverName}</serverName>
+ <databaseName>${databaseName}</databaseName>
+ </dataSource>
+
+ <user>${user}</user>
+ <password>${password}</password>
+ </connectionSource>
+ </appender>
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="DB" />
+ </root>
+</configuration>
+
+
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-drivermanager.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-drivermanager.xml Tue Nov 7 11:44:25 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
+ <driverClass>${driverClass}</driverClass>
+ <url>${url}</url>
+ <user>${user}</user>
+ <password>${password}</password>
+ </connectionSource>
+ </appender>
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="DB" />
+ </root>
+</configuration>
+
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-jndi.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-jndi.xml Tue Nov 7 11:44:25 2006
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+ <!-- We create a joran rule that will instance and bind the appropriate
+ data source instance to JNDI. -->
+ <newRule pattern="configuration/bindDataSourceToJNDI"
+ actionClass="org.apache.log4j.db.BindDataSourceToJNDIAction"/>
+
+ <bindDataSourceToJNDI />
+
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
+
+ <dataSource class="${dataSourceClass}">
+ <param name="${url-key:-url}" value="${url}"/>
+ <serverName>${serverName}</serverName>
+ <databaseName>${databaseName}</databaseName>
+ </dataSource>
+
+ <user>${user}</user>
+ <password>${password}</password>>
+ </connectionSource>
+ </appender>
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="DB" />
+ </root>
+
+</configuration>
+
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-pooled-datasource.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/db/append-with-pooled-datasource.xml Tue Nov 7 11:44:25 2006
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
+
+ <dataSource class="${pooledDataSourceClass}">
+ <param name="${url-key:-url}" value="${url}"/>
+ <serverName>${serverName}</serverName>
+ <databaseName>${databaseName}</databaseName>
+ <user>${user}</user>
+ <password>${password}</password>
+
+ <initialConnections>10</initialConnections>
+ <maxConnections>10</maxConnections>
+ </dataSource>
+
+ <user>${user}</user>
+ <password>${password}</password>
+ </connectionSource>
+ </appender>
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="DB" />
+ </root>
+</configuration>
+
+
1
0

07 Nov '06
Author: seb
Date: Tue Nov 7 11:16:08 2006
New Revision: 879
Added:
logback/trunk/logback-classic/src/test/input/db/append-toMySQL-with-driverManager.xml
- copied, changed from r870, /logback/trunk/logback-classic/src/test/input/db/dbAppenderUsingConnectionSource.xml
logback/trunk/logback-classic/src/test/input/db/append-with-c3p0.xml
logback/trunk/logback-classic/src/test/input/db/append-with-datasource.xml
logback/trunk/logback-classic/src/test/input/db/append-with-drivermanager.xml
logback/trunk/logback-classic/src/test/input/db/append-with-jndi.xml
logback/trunk/logback-classic/src/test/input/db/append-with-pooled-datasource.xml
logback/trunk/logback-classic/src/test/input/db/deleteTables.sql
Removed:
logback/trunk/logback-classic/src/test/input/db/dbAppenderUsingConnectionSource.xml
Log:
added some db example configs
Copied: logback/trunk/logback-classic/src/test/input/db/append-toMySQL-with-driverManager.xml (from r870, /logback/trunk/logback-classic/src/test/input/db/dbAppenderUsingConnectionSource.xml)
==============================================================================
--- /logback/trunk/logback-classic/src/test/input/db/dbAppenderUsingConnectionSource.xml (original)
+++ logback/trunk/logback-classic/src/test/input/db/append-toMySQL-with-driverManager.xml Tue Nov 7 11:16:08 2006
@@ -2,17 +2,17 @@
<appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
<connectionSource class="ch.qos.logback.classic.db.DriverManagerConnectionSource">
- <param name="driverClass" value="com.mysql.jdbc.Driver"/>
- <param name="url" value="jdbc:mysql://host_name:3306/datebase_name"/>
- <param name="user" value="logback"/>
- <param name="password" value="logback"/>
+ <driverClass>"com.mysql.jdbc.Driver</driverClass>
+ <url>jdbc:mysql://host_name:3306/datebase_name</url>
+ <user>logback</user>
+ <password>logback</password>
</connectionSource>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
- <param name="pattern" value="%p %t %c - %m%n"/>
+ <pattern>%level %thread %logger - %msg%n</pattern>
</layout>
</appender>
<root>
Added: logback/trunk/logback-classic/src/test/input/db/append-with-c3p0.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/db/append-with-c3p0.xml Tue Nov 7 11:16:08 2006
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
+ <dataSource class="com.mchange.v2.c3p0.ComboPooledDataSource">
+ <driverClass>${driverClass}</driverClass>
+ <jdbcUrl>${url}</jdbcUrl>
+ <serverName>${serverName}</serverName>
+ <databaseName>${databaseName}</databaseName>
+ <user>${user}</user>
+ <password>${password}</password>
+ <!--
+ <param name="initialConnections" value="10"/>
+ <param name="maxConnections" value="10"/>
+
+ <param name="max-connections" value="100"/>
+ <param name="min-connections" value="5" />
+ <param name="inactivity-timeout" value="200"/>
+ -->
+ </dataSource>
+
+ <user>${user}</user>
+ <password>${password}</password>
+ </connectionSource>
+ </appender>
+
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="DB" />
+ </root>
+</configuration>
+
+
Added: logback/trunk/logback-classic/src/test/input/db/append-with-datasource.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/db/append-with-datasource.xml Tue Nov 7 11:16:08 2006
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
+
+ <dataSource class="${dataSourceClass}">
+ <param name="${url-key:-url}" value="${url}"/>
+ <serverName>${serverName}</serverName>
+ <databaseName>${databaseName}</databaseName>
+ </dataSource>
+
+ <user>${user}</user>
+ <password>${password}</password>
+ </connectionSource>
+ </appender>
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="DB" />
+ </root>
+</configuration>
+
+
+
Added: logback/trunk/logback-classic/src/test/input/db/append-with-drivermanager.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/db/append-with-drivermanager.xml Tue Nov 7 11:16:08 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
+ <driverClass>${driverClass}</driverClass>
+ <url>${url}</url>
+ <user>${user}</user>
+ <password>${password}</password>
+ </connectionSource>
+ </appender>
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+ <root>
+ <level value="debug" />
+ <appender-ref ref="DB" />
+ </root>
+</configuration>
+
+
Added: logback/trunk/logback-classic/src/test/input/db/append-with-jndi.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/db/append-with-jndi.xml Tue Nov 7 11:16:08 2006
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+ <!-- We create a joran rule that will instance and bind the appropriate
+ data source instance to JNDI. -->
+ <newRule pattern="configuration/bindDataSourceToJNDI"
+ actionClass="org.apache.log4j.db.BindDataSourceToJNDIAction"/>
+
+ <bindDataSourceToJNDI />
+
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
+
+ <dataSource class="${dataSourceClass}">
+ <param name="${url-key:-url}" value="${url}"/>
+ <serverName>${serverName}</serverName>
+ <databaseName>${databaseName}</databaseName>
+ </dataSource>
+
+ <user>${user}</user>
+ <password>${password}</password>>
+ </connectionSource>
+ </appender>
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="DB" />
+ </root>
+
+</configuration>
+
+
Added: logback/trunk/logback-classic/src/test/input/db/append-with-pooled-datasource.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/db/append-with-pooled-datasource.xml Tue Nov 7 11:16:08 2006
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<configuration>
+
+ <appender name="DB" class="ch.qos.logback.classic.db.DBAppender">
+ <connectionSource class="ch.qos.logback.core.db.DataSourceConnectionSource">
+
+ <dataSource class="${pooledDataSourceClass}">
+ <param name="${url-key:-url}" value="${url}"/>
+ <serverName>${serverName}</serverName>
+ <databaseName>${databaseName}</databaseName>
+ <user>${user}</user>
+ <password>${password}</password>
+
+ <initialConnections>10</initialConnections>
+ <maxConnections>10</maxConnections>
+ </dataSource>
+
+ <user>${user}</user>
+ <password>${password}</password>
+ </connectionSource>
+ </appender>
+
+ <!-- Prevent internal logback DEBUG messages from polluting the output. -->
+ <logger name="ch.qos.logback.core.joran"><level value="INFO" /></logger>
+ <logger name="ch.qos.logback.classic.joran"><level value="INFO" /></logger>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="DB" />
+ </root>
+</configuration>
+
+
Added: logback/trunk/logback-classic/src/test/input/db/deleteTables.sql
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/input/db/deleteTables.sql Tue Nov 7 11:16:08 2006
@@ -0,0 +1,4 @@
+
+delete from logging_event_exception;
+delete from logging_event_property;
+delete from logging_event;
1
0

svn commit: r878 - in logback/trunk: logback-examples/src/main/java/chapter4 logback-site/src/site/xdocTemplates/manual
by noreply.seb@qos.ch 07 Nov '06
by noreply.seb@qos.ch 07 Nov '06
07 Nov '06
Author: seb
Date: Tue Nov 7 09:31:30 2006
New Revision: 878
Added:
logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java
- copied, changed from r875, /logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes.java
logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java
Removed:
logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes.java
Modified:
logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml
Log:
one more example
Copied: logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java (from r875, /logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes.java)
==============================================================================
--- /logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes1.java Tue Nov 7 09:31:30 2006
@@ -20,10 +20,11 @@
import ch.qos.logback.core.WriterAppender;
import ch.qos.logback.core.layout.EchoLayout;
-public class ExitWoes {
+public class ExitWoes1 {
public static void main(String[] args) throws Exception {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ lc.reset();//this is to cancel default-config.
WriterAppender writerAppender = new WriterAppender();
writerAppender.setContext(lc);
writerAppender.setLayout(new EchoLayout());
@@ -33,7 +34,7 @@
writerAppender.setImmediateFlush(false);
writerAppender.start();
- Logger logger = lc.getLogger(ExitWoes.class);
+ Logger logger = lc.getLogger(ExitWoes1.class);
logger.debug("Hello world.");
}
Added: logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes2.java Tue Nov 7 09:31:30 2006
@@ -0,0 +1,43 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package chapter4;
+
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.core.WriterAppender;
+import ch.qos.logback.core.layout.EchoLayout;
+
+public class ExitWoes2 {
+
+ public static void main(String[] args) throws Exception {
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ lc.reset();//this is to cancel default-config.
+ WriterAppender writerAppender = new WriterAppender();
+ writerAppender.setContext(lc);
+ writerAppender.setLayout(new EchoLayout());
+
+ OutputStream os = new FileOutputStream("exitWoes2.log");
+ writerAppender.setWriter(new OutputStreamWriter(os));
+ writerAppender.setImmediateFlush(false);
+ writerAppender.start();
+
+ Logger logger = lc.getLogger(ExitWoes2.class);
+
+ logger.debug("Hello world.");
+
+ lc.reset();
+ }
+}
\ No newline at end of file
Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml (original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml Tue Nov 7 09:31:30 2006
@@ -269,7 +269,7 @@
will be lost as illustrated by the next example.
</p>
- <em>Example 4.1: Exiting an application without flushing (<a href="../xref/chapter4/ExitWoes.html">logback-examples/src/main/java/chapter4/ExitWoes.java</a>)</em>
+ <em>Example 4.1: Exiting an application without flushing (<a href="../xref/chapter4/ExitWoes1.html">logback-examples/src/main/java/chapter4/ExitWoes1.java</a>)</em>
<div class="source"><pre>package chapter4;
import java.io.FileOutputStream;
@@ -283,7 +283,7 @@
import ch.qos.logback.core.WriterAppender;
import ch.qos.logback.core.layout.EchoLayout;
-public class ExitWoes {
+public class ExitWoes1 {
public static void main(String[] args) throws Exception {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
@@ -316,9 +316,9 @@
<em>exitWoes1.log</em>
because the Java VM does not flush output streams when it exits.
Calling the <code>reset()</code> method of a <code>LoggerContext</code> ensures that all
- appenders in the hierarchy are closed and their buffers are flushed.
- For most applications this is as simple as including the following statement
- before exiting the application.
+ appenders in the hierarchy are closed and their buffers are flushed. The
+ <code>ExitWoes2</code> class uses this statement and outputs a logging
+ request. <b>DOES NOT WORK ??</b>
</p>
<p>
@@ -1609,6 +1609,13 @@
}</pre></div>
<p>
+ Note that this implementation extends <code>TriggeringPolicyBase</code> instead
+ of implementing <code>TriggeringPolicy</code>. This allows the user to concentrate
+ on the core functions of her <code>TriggeringPolicy</code> and let the base class
+ manage the other functionnalities.
+ </p>
+
+ <p>
Setting the <span class="option">EvaluatorClass</span> option of
<code>SMTPAppender</code> instructs it to use a custom evaluator.
The next configuration file attaches a <code>SMTPAppender</code> to the root logger.
@@ -1621,7 +1628,7 @@
<div class="source"><pre><configuration>
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
- <EvaluatorClass>chapter4.mail.CounterBasedTP</EvaluatorClass>
+ <b><EvaluatorClass>chapter4.mail.CounterBasedTP</EvaluatorClass></b>
<BufferSize>1050</BufferSize>
<SMTPHost>${smtpHost}</SMTPHost>
<To>${to}</To>
@@ -1635,19 +1642,22 @@
</root>
</configuration></pre></div>
+ <h3>DBAppender</h3>
+
+
- <h3>DBAppender</h3>
- <h3>SyslogAppender</h3>
+ <h3>SyslogAppender</h3>
+
<h2>Logback Access</h2>
<h3>SMTPAppender</h3>
1
0

svn commit: r877 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/db logback-core/src/main/java/ch/qos/logback/core/db logback-core/src/main/java/ch/qos/logback/core/db/dialect
by noreply.seb@qos.ch 07 Nov '06
by noreply.seb@qos.ch 07 Nov '06
07 Nov '06
Author: seb
Date: Tue Nov 7 09:30:52 2006
New Revision: 877
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/PostgreSQLDialect.java
Log:
refactoring onrefactored DBAppender and DBAppenderBase to remove all mentions of classic concepts from core module
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/db/DBAppender.java Tue Nov 7 09:30:52 2006
@@ -10,6 +10,7 @@
package ch.qos.logback.classic.db;
+import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@@ -101,7 +102,39 @@
* @author Sébastien Pennec
*/
public class DBAppender extends DBAppenderBase {
-
+ protected static final String insertPropertiesSQL = "INSERT INTO logging_event_property (event_id, mapped_key, mapped_value) VALUES (?, ?, ?)";
+ protected static final String insertExceptionSQL = "INSERT INTO logging_event_exception (event_id, i, trace_line) VALUES (?, ?, ?)";
+ protected static final String insertSQL;
+ protected static final Method GET_GENERATED_KEYS_METHOD;
+
+ static {
+ StringBuffer sql = new StringBuffer();
+ sql.append("INSERT INTO logging_event (");
+ sql.append("timestmp, ");
+ sql.append("formatted_message, ");
+ sql.append("logger_name, ");
+ sql.append("level_string, ");
+ sql.append("thread_name, ");
+ sql.append("reference_flag, ");
+ sql.append("caller_filename, ");
+ sql.append("caller_class, ");
+ sql.append("caller_method, ");
+ sql.append("caller_line) ");
+ sql.append(" VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?,?)");
+ insertSQL = sql.toString();
+ //
+ // PreparedStatement.getGeneratedKeys added in JDK 1.4
+ //
+ Method getGeneratedKeysMethod;
+ try {
+ getGeneratedKeysMethod = PreparedStatement.class.getMethod(
+ "getGeneratedKeys", (Class[]) null);
+ } catch (Exception ex) {
+ getGeneratedKeysMethod = null;
+ }
+ GET_GENERATED_KEYS_METHOD = getGeneratedKeysMethod;
+ }
+
public DBAppender() {
}
@@ -168,4 +201,24 @@
return mergedMap;
}
+
+ @Override
+ protected Method getGeneratedKeysMethod() {
+ return GET_GENERATED_KEYS_METHOD;
+ }
+
+ @Override
+ protected String getInsertExceptionSQL() {
+ return insertExceptionSQL;
+ }
+
+ @Override
+ protected String getInsertPropertiesSQL() {
+ return insertPropertiesSQL;
+ }
+
+ @Override
+ protected String getInsertSQL() {
+ return insertSQL;
+ }
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/DBAppenderBase.java Tue Nov 7 09:30:52 2006
@@ -32,44 +32,17 @@
* @author Sébastien Pennec
*/
public abstract class DBAppenderBase extends AppenderBase {
- protected static final String insertPropertiesSQL = "INSERT INTO logging_event_property (event_id, mapped_key, mapped_value) VALUES (?, ?, ?)";
- protected static final String insertExceptionSQL = "INSERT INTO logging_event_exception (event_id, i, trace_line) VALUES (?, ?, ?)";
- protected static final String insertSQL;
- protected static final Method GET_GENERATED_KEYS_METHOD;
-
- static {
- StringBuffer sql = new StringBuffer();
- sql.append("INSERT INTO logging_event (");
- sql.append("timestmp, ");
- sql.append("formatted_message, ");
- sql.append("logger_name, ");
- sql.append("level_string, ");
- sql.append("thread_name, ");
- sql.append("reference_flag, ");
- sql.append("caller_filename, ");
- sql.append("caller_class, ");
- sql.append("caller_method, ");
- sql.append("caller_line) ");
- sql.append(" VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?,?)");
- insertSQL = sql.toString();
- //
- // PreparedStatement.getGeneratedKeys added in JDK 1.4
- //
- Method getGeneratedKeysMethod;
- try {
- getGeneratedKeysMethod = PreparedStatement.class.getMethod(
- "getGeneratedKeys", (Class[]) null);
- } catch (Exception ex) {
- getGeneratedKeysMethod = null;
- }
- GET_GENERATED_KEYS_METHOD = getGeneratedKeysMethod;
- }
protected ConnectionSource connectionSource;
protected boolean cnxSupportsGetGeneratedKeys = false;
protected boolean cnxSupportsBatchUpdates = false;
protected SQLDialect sqlDialect;
+ protected abstract Method getGeneratedKeysMethod();
+ protected abstract String getInsertSQL();
+ protected abstract String getInsertPropertiesSQL();
+ protected abstract String getInsertExceptionSQL();
+
@Override
public void start() {
@@ -80,7 +53,7 @@
sqlDialect = DBUtil
.getDialectFromCode(connectionSource.getSQLDialectCode());
- if (GET_GENERATED_KEYS_METHOD != null) {
+ if (getGeneratedKeysMethod() != null) {
cnxSupportsGetGeneratedKeys = connectionSource.supportsGetGeneratedKeys();
} else {
cnxSupportsGetGeneratedKeys = false;
@@ -112,14 +85,13 @@
@Override
public void append(Object eventObject) {
- // LoggingEvent event = (LoggingEvent) eventObject;
Connection connection = null;
try {
connection = connectionSource.getConnection();
connection.setAutoCommit(false);
PreparedStatement insertStatement = connection
- .prepareStatement(insertSQL);
+ .prepareStatement(getInsertSQL());
subAppend(eventObject, connection, insertStatement);
@@ -147,7 +119,7 @@
boolean gotGeneratedKeys = false;
if (cnxSupportsGetGeneratedKeys) {
try {
- rs = (ResultSet) GET_GENERATED_KEYS_METHOD.invoke(insertStatement,
+ rs = (ResultSet) getGeneratedKeysMethod().invoke(insertStatement,
(Object[]) null);
gotGeneratedKeys = true;
} catch (InvocationTargetException ex) {
@@ -193,7 +165,7 @@
Set propertiesKeys = mergedMap.keySet();
if (propertiesKeys.size() > 0) {
PreparedStatement insertPropertiesStatement = connection
- .prepareStatement(insertPropertiesSQL);
+ .prepareStatement(getInsertPropertiesSQL());
for (Iterator i = propertiesKeys.iterator(); i.hasNext();) {
String key = (String) i.next();
@@ -223,7 +195,7 @@
int eventId) throws SQLException {
PreparedStatement insertExceptionStatement = connection
- .prepareStatement(insertExceptionSQL);
+ .prepareStatement(getInsertExceptionSQL());
for (short i = 0; i < strRep.length; i++) {
insertExceptionStatement.setInt(1, eventId);
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/PostgreSQLDialect.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/PostgreSQLDialect.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/db/dialect/PostgreSQLDialect.java Tue Nov 7 09:30:52 2006
@@ -15,8 +15,6 @@
*
* @author ceki
*
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
*/
public class PostgreSQLDialect
implements SQLDialect {
1
0

svn commit: r876 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/net logback-examples/src/main/java/chapter4/mail logback-examples/src/main/java/chapter4/socket logback-site/src/site/xdocTemplates/manual
by noreply.seb@qos.ch 06 Nov '06
by noreply.seb@qos.ch 06 Nov '06
06 Nov '06
Author: seb
Date: Mon Nov 6 20:21:29 2006
New Revision: 876
Added:
logback/trunk/logback-examples/src/main/java/chapter4/mail/
logback/trunk/logback-examples/src/main/java/chapter4/mail/CounterBasedTP.java
logback/trunk/logback-examples/src/main/java/chapter4/mail/EMail.java
logback/trunk/logback-examples/src/main/java/chapter4/mail/mail1.xml
logback/trunk/logback-examples/src/main/java/chapter4/mail/mail2.xml
logback/trunk/logback-examples/src/main/java/chapter4/mail/mail3.xml
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java
logback/trunk/logback-examples/src/main/java/chapter4/socket/server1.xml
logback/trunk/logback-examples/src/main/java/chapter4/socket/server2.xml
logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml
Log:
on going work, added SMTPAppender doc + fixes on other examples
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java Mon Nov 6 20:21:29 2006
@@ -18,7 +18,6 @@
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
-import ch.qos.logback.core.util.StatusPrinter;
/**
* A simple {@link SocketNode} based server.
@@ -96,7 +95,7 @@
lc.reset();
configurator.setContext(lc);
configurator.doConfigure(configFile);
- StatusPrinter.print(lc);
+ //StatusPrinter.print(lc);
}
}
}
Added: logback/trunk/logback-examples/src/main/java/chapter4/mail/CounterBasedTP.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/mail/CounterBasedTP.java Mon Nov 6 20:21:29 2006
@@ -0,0 +1,37 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+package chapter4.mail;
+
+import java.io.File;
+import ch.qos.logback.core.rolling.TriggeringPolicyBase;
+
+
+/**
+ * A simple TriggeringPolicy implementation that triggers
+ * email transmission after 1024 events regardless of event level.
+ * */
+public class CounterBasedTP extends TriggeringPolicyBase {
+ boolean started;
+ static int LIMIT = 1024;
+ int counter = 0;
+
+ public boolean isTriggeringEvent(File file, Object event) {
+ counter++;
+
+ if (counter == LIMIT) {
+ counter = 0;
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter4/mail/EMail.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/mail/EMail.java Mon Nov 6 20:21:29 2006
@@ -0,0 +1,66 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+package chapter4.mail;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+
+
+
+/**
+ * This application generates log messages in numbers specified by the
+ * user. It is intended to let users test RollingFileAppender. See
+ * also configuration scripts rolling.properties and rolling.xml.
+ * */
+public class EMail {
+ static public void main(String[] args) throws Exception {
+ if (args.length != 2) {
+ usage("Wrong number of arguments.");
+ }
+
+ int runLength = Integer.parseInt(args[0]);
+ String configFile = args[1];
+
+ if (configFile.endsWith(".xml")) {
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ JoranConfigurator configurator = new JoranConfigurator();
+ lc.reset();
+ configurator.setContext(lc);
+ configurator.doConfigure(configFile);
+ //StatusPrinter.print(lc);
+ }
+
+ Logger logger = LoggerFactory.getLogger(EMail.class);
+
+ for (int i = 1; i <= runLength; i++) {
+ if ((i % 10) < 9) {
+ logger.debug("This is a debug message. Message number: " + i);
+ } else {
+ logger.warn("This is a warning message. Message number: " + i);
+ }
+ }
+
+ logger.error("At last an error.", new Exception("Just testing"));
+ }
+
+ static void usage(String msg) {
+ System.err.println(msg);
+ System.err.println("Usage: java " + EMail.class.getName() +
+ " runLength configFile\n" +
+ " runLength (integer) the number of logs to generate\n" +
+ " configFile a logback configuration file in XML format." +
+ " XML files must have a '.xml' extension.");
+ System.exit(1);
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter4/mail/mail1.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/mail/mail1.xml Mon Nov 6 20:21:29 2006
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!-- ========================================================== -->
+<!-- Sample SMTPAppender configuration using the PatternLayout -->
+<!-- ========================================================== -->
+
+<configuration>
+
+ <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
+ <SMTPHost>ADDRESS-OF-YOUR-SMTP-HOST</SMTPHost>
+ <To>DESTINATION-EMAIL</To>
+ <From>SENDER-EMAIL</From>
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <Pattern>%date %-5level %logger - %message%n</Pattern>
+ </layout>
+ </appender>
+
+ <root>
+ <level value="debug"/>
+ <appender-ref ref="EMAIL" />
+ </root>
+</configuration>
Added: logback/trunk/logback-examples/src/main/java/chapter4/mail/mail2.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/mail/mail2.xml Mon Nov 6 20:21:29 2006
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!-- ======================================================= -->
+<!-- Sample SMTPAppender configuration using the HTMLLayout -->
+<!-- ======================================================= -->
+
+<configuration>
+
+ <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
+ <SMTPHost>${smtpHost}</SMTPHost>
+ <To>${to}</To>
+ <From>${from}</From>
+ <layout class="ch.qos.logback.classic.html.HTMLLayout"/>
+ </appender>
+
+ <root>
+ <level value="debug"/>
+ <appender-ref ref="EMAIL" />
+ </root>
+</configuration>
+
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/mail/mail3.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/mail/mail3.xml Mon Nov 6 20:21:29 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!-- ============================================================= -->
+<!-- Sample SMTPAppender configuration using the HTMLLayout and a -->
+<!-- custom trigger event evaluator. -->
+<!-- ============================================================= -->
+
+<configuration>
+ <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
+ <EvaluatorClass>chapter4.mail.CounterBasedTP</EvaluatorClass>
+ <BufferSize>1050</BufferSize>
+ <SMTPHost>${smtpHost}</SMTPHost>
+ <To>${to}</To>
+ <From>${from}</From>
+ <layout class="ch.qos.logback.classic.html.HTMLLayout"/>
+ </appender>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="EMAIL" />
+ </root>
+</configuration>
+
+
Modified: logback/trunk/logback-examples/src/main/java/chapter4/socket/server1.xml
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/socket/server1.xml (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/socket/server1.xml Mon Nov 6 20:21:29 2006
@@ -12,7 +12,7 @@
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
- <Pattern>%d %-5p [%t] %c - %m%n</Pattern>
+ <Pattern>%date %-5level [%thread] %logger - %message%n</Pattern>
</layout>
</appender>
@@ -32,7 +32,7 @@
</triggeringPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
- <Pattern>%r %-5p %c - %m%n</Pattern>
+ <Pattern>%relative %-5level %logger - %message%n</Pattern>
</layout>
</appender>
Modified: logback/trunk/logback-examples/src/main/java/chapter4/socket/server2.xml
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/socket/server2.xml (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/socket/server2.xml Mon Nov 6 20:21:29 2006
@@ -11,7 +11,7 @@
<!-- Notice the %file and %line patterns in the Pattern. -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
- <Pattern>%date %-5level [%thread] [%file:%line] %logger - %msg%n</Pattern>
+ <Pattern>%date %-5level [%thread] [%file:%line] %logger - %message%n</Pattern>
</layout>
</appender>
Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml (original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml Mon Nov 6 20:21:29 2006
@@ -584,7 +584,7 @@
renames files according to a fixed window algorithm as described below.
</p>
<p>
- The <b>File</b>property, which is configured in the
+ The <b>File</b> property, which is configured in the
<code>FileAppender</code> element, is required. It represents the name of the file
where current logging output will be written. The <b>FileNamePattern</b>
option represents the file name pattern for the archived (rolled over) log files.
@@ -1078,11 +1078,6 @@
<em>5MB</em>, <em>500KB</em> or <em>2GB</em> are all valid.
</p>
<p>
- <b>Althought values expressed in <em>GB</em> are possible,
- we do not recommand setting the <span class="option">MaxFileSize</span>
- option to a value bigger than XXX GB</b>.
- </p>
- <p>
Here is a sample configuration with a <code>RollingFileAppender</code>
using a <code>SizeBasedTriggeringPolicy</code>.
</p>
@@ -1259,7 +1254,7 @@
start <code>SimpleSocketServer</code> with the following command:
</p>
-<div class="source"><pre> java ch.qos.logback.classic.net.SimpleSocketServer 6000 \
+<div class="source"><pre>java ch.qos.logback.classic.net.SimpleSocketServer 6000 \
chapter4/socket/server1.xml
</pre></div>
@@ -1305,7 +1300,7 @@
and attaches it to the root logger.
</p>
- <em>Example 4.1: SocketAppender configuration (<a href="../xref/chapter4/socket/client1.html">logback-examples/src/main/java/chapter4/socket/client1.xml</a>)</em>
+ <em>Example 4.2: SocketAppender configuration (logback-examples/src/main/java/chapter4/socket/client1.xml)</em>
<div class="source"><pre><configuration>
<appender name="SOCKET" class="ch.qos.logback.classic.net.SocketAppender">
@@ -1380,11 +1375,265 @@
As an exercise, you may wish to setup two servers where the first server
tunnels the events it receives from its clients to a second server.
</p>
+
+ <a name="SMTPAppender"/>
+ <h3>SMTPAppender</h3>
+
+ <p>
+ The <code>SMTPAppender</code> accumulates logging events in a fixed-size
+ buffer and sends them in an email when a user specified triggering event occurs.
+ By default, the triggering event is taken as the reception of an event
+ of level <em>ERROR</em> or higher.
+ </p>
+
+ <p>
+ The various options for <code>SMTPAppender</code> are summarized in the following table.
+ </p>
+
+ <table>
+ <tr>
+ <th>Option Name</th>
+ <th>Type</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td><b><span class="option">SMTPHost</span></b></td>
+ <td><code>String</code></td>
+ <td>
+ The host name of the SMTP server. This parameter is mandatory.
+ </td>
+ </tr>
+ <tr>
+ <td><b><span class="option">To</span></b></td>
+ <td><code>String</code></td>
+ <td>
+ The email address of the recipient. Multiple recipients can
+ be specified by separating each recipient with a comma.
+ </td>
+ </tr>
+ <tr>
+ <td><b><span class="option">From</span></b></td>
+ <td><code>String</code></td>
+ <td>
+ The stated originator of the email messages sent by
+ <code>SMTPAppender</code>.
+ </td>
+ </tr>
+ <tr>
+ <td><b><span class="option">Subject</span></b></td>
+ <td><code>String</code></td>
+ <td>
+ <p>
+ The subject of the email. The String can contain a <code>Pattern</code>
+ that <code>PatternLayout</code> uses. In that case, the subject
+ is created just before the transmission of the email, with information
+ about the last logging event that was issued.
+ </p>
+ <p>
+ For example, setting <em>Log: %logger - %msg</em> as the
+ <span class="option">Subject</span> option will send an email with
+ the logger name and message string of the event that triggered the
+ email transmission.
+ </p>
+ <p>
+ By default, <code>SMTPAppender</code> will form a subject with
+ the message of the last logging event.
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td><b><span class="option">BufferSize</span></b></td>
+ <td><code>String</code></td>
+ <td>
+ The <span class="option">BufferSize</span> option takes a positive
+ integer representing the maximum number of logging events to collect in a
+ cyclic buffer. When the <span class="option">BufferSize</span> is reached,
+ oldest events are deleted as new events are added to the buffer.
+ The default size of the cyclic buffer is 512.
+ </td>
+ </tr>
+ <tr>
+ <td><b><span class="option">EvaluatorClass</span></b></td>
+ <td><code>String</code></td>
+ <td>
+ The <span class="option">EvaluatorClass</span> option takes a string
+ value representing the name of the class implementing the
+ <code>TriggeringPolicy</code> interface. A corresponding object will be
+ instantiated and assigned as the triggering event evaluator for the
+ <code>SMTPAppender</code>. In the absence of this option,
+ <code>SMTPAppender</code> is assigned a default evaluator which triggers
+ email transmission as a response to any event of level <em>ERROR</em> or higher.
+ </td>
+ </tr>
+ </table>
+
+ <p>
+ The SMTPAppender keeps only the last <span class="option">BufferSize</span> logging events
+ in its cyclic buffer, throwing away older events when its buffer becomes full.
+ The number of logging events delivered in any e-mail sent by <code>SMTPAppender</code>
+ is upper-bounded by <span class="option">BufferSize</span>. This keeps memory
+ requirements bounded while still delivering the desired amount of application context.
+ </p>
+
+ <p>
+ The <code>SMTPAppender</code> relies on the JavaMail API.
+ It has been tested with JavaMail API version 1.4.
+ The JavaMail API requires the JavaBeans Activation Framework package.
+ You can download the <a href="http://java.sun.com/products/javamail/">JavaMail API</a>
+ and the <a href="http://java.sun.com/beans/glasgow/jaf.html">Java-Beans Activation Framework</a>
+ from their respective websites.
+ Make sure to place these two jar files in the classpath before
+ trying the following examples.
+ </p>
+
+ <p>
+ A sample application called <code>chapter4.mail.EMail</code> takes two parameters.
+ The first parameter is an integer corresponding to the number of logging events
+ to generate. The second parameter is the logback configuration file in XML format.
+ The last logging event generated by chapter4.mail.Email application is always an
+ <em>ERROR</em> event which triggers the transmission of an email message.
+ </p>
+
+ <p>
+ Here is a sample configuration file you can supply to chapter4.mail.Email:
+ </p>
+
+<em>Example 4.3: A sample <code>SMTPAppender</code> configuration (logback-examples/src/main/java/chapter4/mail/mail1.xml)</em>
+<div class="source"><pre><configuration>
+
+ <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
+ <SMTPHost>ADDRESS-OF-YOUR-SMTP-HOST</SMTPHost>
+ <To>DESTINATION-EMAIL</To>
+ <From>SENDER-EMAIL</From>
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <Pattern>%date %-5level %logger - %message%n</Pattern>
+ </layout>
+ </appender>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="EMAIL" />
+ </root>
+</configuration></pre></div>
+
+ <p>
+ Before trying out <code>chapter4.mail.Email</code> application with the above
+ configuration file, you must set the <span class="option">SMTPHost</span>,
+ <span class="option">To</span> and <span class="option">From</span> options
+ to values appropriate for your environment. Once you have set the proper values,
+ execute the following command:
+ </p>
+
+<div class="source"><pre>java chapter4.mail.EMail 300 chapter4/mail/mail.xml</pre></div>
+
+ <p>
+ The chosen recipient should see an email message containing 300 logging events
+ formatted by <code>PatternLayout</code>.
+ </p>
+
+ <p>
+ In another configuration file <em>mail2.xml</em>, the values for the
+ <span class="option">SMTPHost</span>, <span class="option">To</span>
+ and <span class="option">From</span> options are determined by variable
+ substitution. Here is the relevant part of <em>mail2.xml</em>.
+ </p>
+
+<div class="source"><pre>
+ <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
+ <SMTPHost>${smtpHost}</SMTPHost>
+ <To>${to}</To>
+ <From>${from}</From>
+ <layout class="ch.qos.logback.classic.html.HTMLLayout"/>
+ </appender>
+</pre></div>
+
+ <p>
+ You can supply the various values on the command line:
+ </p>
+
+<div class="source"><pre>java -Dfrom=source(a)xyz.com -Dto=recipient(a)xyz.com
+ -DsmtpHost=some_smtp_host chapter4.mail.EMail 10000 chapter4/mail/mail2.xml
+</pre></div>
+ <p>
+ Be sure to replace with the correct values appropriate for your environment.
+ </p>
+
+ <p>
+ Given that the default size of the cyclic buffer is 512,
+ the recipient should see an email message containing 512 events conveniently
+ formatted in an HTML table. Note that this run of the <code>chapter4.mail.Email</code>
+ application generated 10'000 events of which only the last 512 were included in the email.
+ </p>
+
+ <p>
+ By default, the <code>SMTPAppender</code> will initiate the transmission of an email
+ message as a response to an event of level <em>ERROR</em> or higher.
+ However, it is possible to override this default behavior by providing a custom
+ implementation of the <code>TriggeringPolicy</code> interface.
+ </p>
+
+ <p>
+ The <code>SMTPAppender</code> submits each incoming event to its evaluator
+ by calling <code>isTriggeringEvent()</code> method in order to check whether
+ the event should trigger an email or just be placed in the cyclic buffer.
+ The <code>SMTPAppender</code> contains one and only one evaluator object.
+ This object may possess its own state. For illustrative purposes,
+ the <code>CounterBasedTP</code> class listed next, implements a triggering policy whereby
+ every 1024th event triggers an email message.
+ </p>
+<em>Example 4.4: A <code>TriggeringPolicy</code> implementation
+that triggers every 1024th event (<a href="../xref/chapter4/mail/CounterBasedTP.html">logback-examples/src/main/java/chapter4/mail/CounterBasedTP.java</a>)</em>
+<div class="source"><pre>package chapter4.mail;
+import java.io.File;
+import ch.qos.logback.core.rolling.TriggeringPolicyBase;
+public class CounterBasedTP extends TriggeringPolicyBase {
+ boolean started;
+ static int LIMIT = 1024;
+ int counter = 0;
+
+ public boolean isTriggeringEvent(File file, Object event) {
+ counter++;
+
+ if (counter == LIMIT) {
+ counter = 0;
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+}</pre></div>
+ <p>
+ Setting the <span class="option">EvaluatorClass</span> option of
+ <code>SMTPAppender</code> instructs it to use a custom evaluator.
+ The next configuration file attaches a <code>SMTPAppender</code> to the root logger.
+ This appender has a buffer size of 2048 and uses a <code>CounterBasedTP</code> instance
+ as its triggering event evaluator.
+ </p>
+
+<em>Example 4.5: <code>SMTPAppender</code> with custom
+<code>TriggeringPolicy</code> and buffer size (logback-examples/src/main/java/chapter4/mail/mail3.xml)</em>
+
+<div class="source"><pre><configuration>
+ <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
+ <EvaluatorClass>chapter4.mail.CounterBasedTP</EvaluatorClass>
+ <BufferSize>1050</BufferSize>
+ <SMTPHost>${smtpHost}</SMTPHost>
+ <To>${to}</To>
+ <From>${from}</From>
+ <layout class="ch.qos.logback.classic.html.HTMLLayout"/>
+ </appender>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="EMAIL" />
+ </root>
+</configuration></pre></div>
@@ -1392,10 +1641,16 @@
+ <h3>DBAppender</h3>
+ <h3>SyslogAppender</h3>
+
+
<h2>Logback Access</h2>
+
+ <h3>SMTPAppender</h3>
1
0

svn commit: r875 - in logback/trunk: logback-examples/src/main/java/chapter4 logback-examples/src/main/java/chapter4/socket logback-site/src/site/xdocTemplates/manual
by noreply.seb@qos.ch 06 Nov '06
by noreply.seb@qos.ch 06 Nov '06
06 Nov '06
Author: seb
Date: Mon Nov 6 17:43:33 2006
New Revision: 875
Added:
logback/trunk/logback-examples/src/main/java/chapter4/socket/
logback/trunk/logback-examples/src/main/java/chapter4/socket/SocketClient1.java
logback/trunk/logback-examples/src/main/java/chapter4/socket/SocketClient2.java
logback/trunk/logback-examples/src/main/java/chapter4/socket/client1.xml
logback/trunk/logback-examples/src/main/java/chapter4/socket/server1.xml
logback/trunk/logback-examples/src/main/java/chapter4/socket/server2.xml
Modified:
logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes.java
logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml
logback/trunk/logback-site/src/site/xdocTemplates/manual/index.xml
Log:
on going work on chapter 4
Modified: logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes.java
==============================================================================
--- logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes.java (original)
+++ logback/trunk/logback-examples/src/main/java/chapter4/ExitWoes.java Mon Nov 6 17:43:33 2006
@@ -14,6 +14,7 @@
import java.io.OutputStreamWriter;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.WriterAppender;
@@ -22,7 +23,7 @@
public class ExitWoes {
public static void main(String[] args) throws Exception {
- LoggerContext lc = new LoggerContext();
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
WriterAppender writerAppender = new WriterAppender();
writerAppender.setContext(lc);
writerAppender.setLayout(new EchoLayout());
@@ -36,4 +37,4 @@
logger.debug("Hello world.");
}
-}
+}
\ No newline at end of file
Added: logback/trunk/logback-examples/src/main/java/chapter4/socket/SocketClient1.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/socket/SocketClient1.java Mon Nov 6 17:43:33 2006
@@ -0,0 +1,76 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package chapter4.socket;
+
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.net.SocketAppender;
+
+
+/**
+ * This application uses a SocketAppender that log messages to a
+ * server on a host and port specified by the user. It waits for the
+ * user to type a message which will be sent to the server.
+ * */
+public class SocketClient1 {
+ static void usage(String msg) {
+ System.err.println(msg);
+ System.err.println("Usage: java " + SocketClient1.class.getName() +
+ " hostname port\n" + " hostname the name of the remote log server\n" +
+ " port (integer) the port number of the server\n");
+ System.exit(1);
+ }
+
+ static public void main(String[] args) throws Exception {
+ if (args.length != 2) {
+ usage("Wrong number of arguments.");
+ }
+
+ String hostName = args[0];
+ int port = Integer.parseInt(args[1]);
+
+ // Create a SocketAppender connected to hostname:port with a
+ // reconnection delay of 10000 seconds.
+ SocketAppender socketAppender = new SocketAppender();
+ socketAppender.setRemoteHost(hostName);
+ socketAppender.setPort(port);
+ socketAppender.setReconnectionDelay(10000);
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ socketAppender.setContext(lc);
+
+ // SocketAppender options become active only after the execution
+ // of the next statement.
+ socketAppender.start();
+
+ Logger logger = LoggerFactory.getLogger(SocketClient1.class);
+ //logger.addAppender(socketAppender);
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
+
+ while (true) {
+ System.out.println("Type a message to send to log server at " + hostName +
+ ":" + port + ". Type 'q' to quit.");
+
+ String s = reader.readLine();
+
+ if (s.equals("q")) {
+ break;
+ } else {
+ logger.debug(s);
+ }
+ }
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter4/socket/SocketClient2.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/socket/SocketClient2.java Mon Nov 6 17:43:33 2006
@@ -0,0 +1,70 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+package chapter4.socket;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+
+
+/**
+ * This application uses a SocketAppender that log messages to a
+ * server on a host and port specified by the user. It waits for the
+ * user to type a message which will be sent to the server.
+ * */
+public class SocketClient2 {
+ static void usage(String msg) {
+ System.err.println(msg);
+ System.err.println("Usage: java " + SocketClient1.class.getName() +
+ " configFile\n" +
+ " configFile a logback configuration file" +
+ " in XML format.");
+ System.exit(1);
+ }
+
+ static public void main(String[] args) throws Exception {
+ if (args.length != 1) {
+ usage("Wrong number of arguments.");
+ }
+
+ String configFile = args[0];
+
+ if (configFile.endsWith(".xml")) {
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ JoranConfigurator configurator = new JoranConfigurator();
+ lc.reset();
+ configurator.setContext(lc);
+ configurator.doConfigure(configFile);
+ }
+
+ Logger logger = LoggerFactory.getLogger(SocketClient2.class);
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
+
+ while (true) {
+ System.out.println(
+ "Type a message to send to log server. Type 'q' to quit.");
+
+ String s = reader.readLine();
+
+ if (s.equals("q")) {
+ break;
+ } else {
+ logger.debug(s);
+ }
+ }
+ }
+}
Added: logback/trunk/logback-examples/src/main/java/chapter4/socket/client1.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/socket/client1.xml Mon Nov 6 17:43:33 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!-- ==================================================================== -->
+<!-- Sample SocketAppender configuration. -->
+<!-- ==================================================================== -->
+
+<configuration>
+
+ <appender name="SOCKET" class="ch.qos.logback.classic.net.SocketAppender">
+ <RemoteHost>${host}</RemoteHost>
+ <Port>${port}</Port>
+ <ReconnectionDelay>10000</ReconnectionDelay>
+ <IncludeCallerData>${includeCallerData}</IncludeCallerData>
+ </appender>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="SOCKET" />
+ </root>
+
+</configuration>
+
+
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/socket/server1.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/socket/server1.xml Mon Nov 6 17:43:33 2006
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!-- ==================================================================== -->
+<!-- This config file is intended to be used by a SocketServer that logs -->
+<!-- events received from various clients on the console and to a file -->
+<!-- that is rolled over when appropriate. The interesting point to note -->
+<!-- is that it is a configuration file like any other. -->
+<!-- ==================================================================== -->
+
+<configuration>
+
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <Pattern>%d %-5p [%t] %c - %m%n</Pattern>
+ </layout>
+
+ </appender>
+
+ <appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <File>rolling.log</File>
+
+ <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <FileNamePattern>rolling.%i.log</FileNamePattern>
+ <MinIndex>1</MinIndex>
+ <MaxIndex>3</MaxIndex>
+ </rollingPolicy>
+
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <MaxFileSize>8KB</MaxFileSize>
+ </triggeringPolicy>
+
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <Pattern>%r %-5p %c - %m%n</Pattern>
+ </layout>
+ </appender>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="CONSOLE" />
+ <appender-ref ref="ROLLING" />
+ </root>
+</configuration>
+
+
+
Added: logback/trunk/logback-examples/src/main/java/chapter4/socket/server2.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-examples/src/main/java/chapter4/socket/server2.xml Mon Nov 6 17:43:33 2006
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!-- ==================================================================== -->
+<!-- This config file is intended to be used by a SocketServer that logs -->
+<!-- events received from various clients on the console. The interesting -->
+<!-- point to note is that it is a configuration file like any other. -->
+<!-- ==================================================================== -->
+
+<configuration>
+
+ <!-- Notice the %file and %line patterns in the Pattern. -->
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <layout class="ch.qos.logback.classic.PatternLayout">
+ <Pattern>%date %-5level [%thread] [%file:%line] %logger - %msg%n</Pattern>
+ </layout>
+ </appender>
+
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="CONSOLE" />
+ </root>
+</configuration>
+
+
+
Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml (original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/manual/appenders.xml Mon Nov 6 17:43:33 2006
@@ -47,7 +47,8 @@
<p>
Logback delegates the task of writing a logging event to appenders.
- Appenders must imple-ment the <code>ch.qos.logback.core.Appender</code> interface.
+ Appenders must implement the
+ <a href="../xref/ch/qos/logback/core/Appender.html"><code>ch.qos.logback.core.Appender</code></a> interface.
The salient methods of this interface are summarized below:
</p>
<div class="source"><pre>package ch.qos.logback.core;
@@ -96,7 +97,8 @@
<h2>AppenderBase</h2>
<p>
- The <code>ch.qos.logback.core.AppenderSkeleton</code> class is an abstract
+ The <a href="../xref/ch/qos/logback/core/AppenderBase.html">
+ <code>ch.qos.logback.core.AppenderBase</code></a> class is an abstract
class implementing the <code>Appender</code> interface.
It provides basic functionality shared by all appenders,
such as methods for getting or setting their name, their started status,
@@ -211,7 +213,7 @@
<h3>WriterAppender</h3>
<p>
- <code>WriterAppender</code> appends events to a <code>java.io.Writer</code>.
+ <a href="../xref/ch/qos/logback/core/WriterAppender.html"><code>WriterAppender</code></a> appends events to a <code>java.io.Writer</code>.
This class provides basic services that other appenders build upon.
Users do not usually instantiate <code>WriterAppender</code> objects directly.
Since <code>java.io.Writer</code> type cannot be mapped to a string, there is no
@@ -267,8 +269,7 @@
will be lost as illustrated by the next example.
</p>
- <em>Example 4.1: Exiting an application without flushing (logback-examples/src/main/java/chapter4/
- <a href="../xref/chapter4/ExitWoes.html">ExitWoes.java</a>)</em>
+ <em>Example 4.1: Exiting an application without flushing (<a href="../xref/chapter4/ExitWoes.html">logback-examples/src/main/java/chapter4/ExitWoes.java</a>)</em>
<div class="source"><pre>package chapter4;
import java.io.FileOutputStream;
@@ -280,15 +281,15 @@
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.WriterAppender;
-import ch.qos.logback.core.layout.DummyLayout;
+import ch.qos.logback.core.layout.EchoLayout;
public class ExitWoes {
public static void main(String[] args) throws Exception {
- LoggerContext lc = new LoggerContext();
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
WriterAppender writerAppender = new WriterAppender();
writerAppender.setContext(lc);
- writerAppender.setLayout(new DummyLayout());
+ writerAppender.setLayout(new EchoLayout());
OutputStream os = new FileOutputStream("exitWoes1.log");
writerAppender.setWriter(new OutputStreamWriter(os));
@@ -314,12 +315,11 @@
running <code>ExitWoes1</code> will not produce any output in the file
<em>exitWoes1.log</em>
because the Java VM does not flush output streams when it exits.
- Calling the <code>shutdown()</code> method of a <b>XXXXXX</b> ensures that all
+ Calling the <code>reset()</code> method of a <code>LoggerContext</code> ensures that all
appenders in the hierarchy are closed and their buffers are flushed.
For most applications this is as simple as including the following statement
before exiting the application.
</p>
- <p>WHAT TO DO IN LB ???</p>
<p>
The <code>WriterAppender</code> is the super class of four other appenders,
@@ -333,7 +333,8 @@
<h3>ConsoleAppender</h3>
<p>
- The <code>ConsoleAppender</code>, as the name indicates, appends on the console,
+ The <a href="../xref/ch/qos/logback/core/ConsoleAppender.html">
+ <code>ConsoleAppender</code></a>, as the name indicates, appends on the console,
or more precisely on <em>System.out</em> or <em>System.err</em>, the former
being the default target. <code>ConsoleAppender</code> formats events with
a layout specified by the user. Both <em>System.out</em> and <em>System.err</em>
@@ -371,7 +372,8 @@
<h3>FileAppender</h3>
<p>
- The <code>FileAppender</code>, a subclass of <code>WriterAppender</code>,
+ The <a href="../xref/ch/qos/logback/core/FileAppender.html"><code>FileAppender</code></a>,
+ a subclass of <code>WriterAppender</code>,
appends log events into a file. The file to write to is specified by
the <span class="option">File</span> option.
If the file already exists, it is either appended to, or truncated
@@ -464,7 +466,8 @@
<h3>RollingFileAppender</h3>
<p>
- <code>RollingFileAppender</code> extends <code>FileAppender</code> by
+ <a href="../xref/ch/qos/logback/core/rolling/RollingFileAppender.html"><code>RollingFileAppender</code></a>
+ extends <code>FileAppender</code> by
allowing rolling from a log file to another. For example,
<code>RollingFileAppender</code> can log to a <em>log.txt</em> file and,
once a certain condition is met, change its logging target to another file.
@@ -546,7 +549,8 @@
<h3>Rolling policies</h3>
- <p><code>RollingPolicy</code> implementations are responsible for the
+ <p><a href="../xref/ch/qos/logback/core/rolling/RollingPolicy.html"><code>RollingPolicy</code></a>
+ implementations are responsible for the
procedure of the rollover. They manage file renaming and sometimes deleting.</p>
<p>The <code>RollingPolicy</code> interface is rather simple:</p>
@@ -575,7 +579,8 @@
<h4>FixedWindowRollingPolicy</h4>
<p>
- When rolling over, <code>FixedWindowRollingPolicy</code>
+ When rolling over, <a href="../xref/ch/qos/logback/core/rolling/FixedWindowRollingPolicy.html">
+ <code>FixedWindowRollingPolicy</code></a>
renames files according to a fixed window algorithm as described below.
</p>
<p>
@@ -787,7 +792,8 @@
<a name="TimeBasedRollingPolicy" />
<h4>TimeBasedRollingPolicy</h4>
<p>
- <code>TimeBasedRollingPolicy</code> is both easy to configure and quite powerful.
+ <a href="../xref/ch/qos/logback/core/rolling/TimeBasedRollingPolicy.html">
+ <code>TimeBasedRollingPolicy</code></a> is both easy to configure and quite powerful.
It allows the rollover to be made based on time conditions. It is possible to specify
that the rollover must occur each day, or month, for example.
</p>
@@ -1017,7 +1023,8 @@
<a name="TriggeringPolicy"/>
<h3>Triggering policies</h3>
- <p><code>TriggeringPolicy</code> implementations are responsible for instructing
+ <p><a href="../xref/ch/qos/logback/core/rolling/TriggeringPolicy.html"><code>TriggeringPolicy</code></a>
+ implementations are responsible for instructing
the <code>RollingFileAppender</code> to proceed to the rollover.</p>
<p>The <code>TriggeringPolicy</code> interface is pretty simple.</p>
@@ -1045,7 +1052,8 @@
<h4>SizeBasedTriggeringPolicy</h4>
<p>
- <code>SizeBasedTriggeringPolicy</code>
+ <a href="../xref/ch/qos/logback/core/rolling/SizeBasedTriggeringPolicy.html">
+ <code>SizeBasedTriggeringPolicy</code></a>
looks at size of the file being currently written to. If it
grows bigger than the specified size, the
<code>FileAppender</code> using the
@@ -1108,21 +1116,286 @@
<code>SMTPAppender</code>, which will be covered soon, when to send an email
containing the last logging events.
</p>
+
+ <p>
+ In that case, the <code>isTriggeringEvent()</code> method takes <em>null</em>
+ as its first parameter (of type <code>File</code>) and takes the logging event
+ as its second parameter. It is based on that last element that the decision is
+ made to send the email or not. By default, a <code>TriggeringPolicy</code> is
+ included with <code>SMTPAppender</code> that triggers the mail each time an event
+ with a <code>Level</code> of <em>ERROR</em> or more is issued.
+ </p>
+ <a name="Classic"/>
+ <h2>Logback Classic</h2>
+
+ <p><b>Keep this??</b>While logging event are declared as <code>Object</code> in logback core,
+ they are instances of the <code>LoggingEvent</code> class in logback classic.</p>
+
+ <a name="SocketAppender" />
+ <h3>SockerAppender</h3>
+
+ <p>
+ The appenders covered this far were only able to log to local resources.
+ In contrast, the <a href="../xref/ch/qos/logback/classic/net/SocketAppender.html">
+ <code>SocketAppender</code></a> is designed to log to a
+ remote entity by transmitting serialized LoggingEvent objects over the wire.
+ Remote logging is non-intrusive as far as the logging event is concerned.
+ On the receiving end after de-serialization, the event can be logged as
+ if it were generated locally. Multiple <code>SocketAppender</code> instances
+ running of different machines can direct their logging output
+ to a central log server. <code>SocketAppender</code> does not admit an
+ associated layout because it sends serialized events to a remote server.
+ <code>SocketAppender</code> operates above the
+ <em>Transmission Control Protocol (TCP)</em>
+ layer which provides a reliable, sequenced, flow-controlled end-to-end octet stream.
+ Consequently, if the remote server is reachable, then log events
+ will eventually arrive there. Otherwise, if the remote server is down or
+ unreachable, the logging events will simply be dropped. If and when the server
+ comes back up, then event transmission will be resumed transparently.
+ This transparent reconnection is performed by a connector thread which
+ periodically attempts to connect to the server.
+ </p>
+
+ <p>
+ Logging events are automatically buffered by the native TCP implementation.
+ This means that if the link to server is slow but still faster than the
+ rate of event production by the client, the client will not be affected by
+ the slow network connection. However, if the network connection is slower
+ then the rate of event production, then the client can only progress at the
+ network rate. In particular, in the extreme case where the network link
+ to the server is down, the client will be eventually blocked.
+ Alternatively, if the network link is up, but the server is down,
+ the client will not be blocked although the log events will be
+ lost due to server unavailability.
+ </p>
+
+ <p>
+ Even if a <code>SocketAppender</code> is no longer attached to any logger,
+ it will not be garbage collected in the presence of a connector thread.
+ A connector thread exists only if the connection to the server is down.
+ To avoid this garbage collection problem, you should close the <code>SocketAppender</code>
+ explicitly. Long lived applications which create/destroy many
+ <code>SocketAppender</code> instances should be aware of this
+ garbage collection problem. Most other applications can safely ignore it.
+ If the JVM hosting the <code>SocketAppender</code> exits before the
+ <code>SocketAppender</code> is closed, either explicitly or subsequent
+ to garbage collection, then there might be untransmitted data in the
+ pipe which may be lost. This is a common problem on Windows based systems.
+ To avoid lost data, it is usually sufficient to <code>close()</code> the
+ <code>SocketAppender</code> either explicitly or by calling the
+ <code>LoggerContext</code>'s <code>reset()</code> method before exiting the application.
+ </p>
+
+ <p>
+ The remote server is identified by the <span class="option">RemoteHost</span> and
+ <span class="option">Port</span> options.
+ <code>SocketAppender</code> options are listed in the following table.
+ </p>
+ <table>
+ <tr>
+ <th>Option Name</th>
+ <th>Type</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td><b><span class="option">IncludeCallerData</span></b></td>
+ <td><code>boolean</code></td>
+ <td>
+ <p>
+ The <span class="option">IncludeCallerData</span> option takes a boolean value.
+ If true, the caller data will be available to the remote host.
+ By default no caller data is sent to the server.
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td><b><span class="option">Port</span></b></td>
+ <td><code>int</code></td>
+ <td>
+ <p>
+ The port number of the remote server.
+ </p>
+ </td>
+ </tr>
+ <tr>
+ <td><b><span class="option">ReconnectionDelay</span></b></td>
+ <td><code>int</code></td>
+ <td>
+ The <span class="option">ReconnectionDelay</span> option takes a
+ positive integer representing the number of milliseconds to wait between
+ each failed connection attempt to the server.
+ The default value of this option is 30'000 which corresponds to 30 seconds.
+ Setting this option to zero turns off reconnection capability.
+ Note that in case of successful connection to the server, there will be no
+ connector thread present.
+ </td>
+ </tr>
+ <tr>
+ <td><b><span class="option">RemoteHost</span></b></td>
+ <td><code>String</code></td>
+ <td>
+ The host name of the server.
+ </td>
+ </tr>
+ </table>
+
+ <p>
+ The standard logback distribution includes a simple log server application named
+ <code>ch.qos.logback.classic.net.SimpleSocketServer</code> that can service multiple
+ <code>SocketAppender</code> clients. It waits for logging events from
+ <code>SocketAppender</code> clients. After reception by
+ <code>SimpleSocketServer</code>, the events are logged according to local server policy.
+ The <code>SimpleSocketServer</code> application takes two parameters:
+ port and configFile; where port is the port to listen on and configFile is
+ configuration script in XML format.
+ </p>
+
+ <p>
+ Assuming you are in the <em>logback-examples/target/classes/</em> directory,
+ start <code>SimpleSocketServer</code> with the following command:
+ </p>
+
+<div class="source"><pre> java ch.qos.logback.classic.net.SimpleSocketServer 6000 \
+ chapter4/socket/server1.xml
+</pre></div>
+ <p>
+ where 6000 is the port number to listen on and <em>server1.xml</em> is a
+ configuration script that adds a <code>ConsoleAppender</code> and a
+ <code>RollingFileAppender</code> to the root logger.
+ After you have started <code>SimpleSocketServer</code>, you can send it
+ log events from multiple clients using <code>SocketAppender</code>.
+ The examples associated with this manual include two such clients:
+ <code>chapter4.SocketClient1</code> and <code>chapter4.SocketClient2</code>
+ Both clients wait for the user to type a line of text on the console.
+ The text is encapsulated in a logging event of level debug and then sent
+ to the remote server. The two clients differ in the configuration of the
+ <code>SocketAppender</code>. <code>SocketClient1</code> configures the appender
+ programmatically while <code>SocketClient2</code> requires a configuration file.
+ </p>
+
+ <p>
+ Assuming <code>SimpleSocketServer</code> is running on the local host,
+ you connect to it with the following command:
+ </p>
+
+<div class="source"><pre>java chapter4.socket.SocketClient1 localhost 6000</pre></div>
+ <p>
+ Each line that you type should appear on the console of the
+ <code>SimpleSocketServer</code>
+ launched in the previous step. If you stop and restart the
+ <code>SimpleSocketServer</code>
+ the client will transparently reconnect to the new server
+ instance, although the events generated while disconnected
+ will be simply and irrevocably lost.
+ </p>
+ <p>
+ Unlike
+ <code>SocketClient1</code>, the sample application
+ <code>SocketClient2</code> does not configure logback by itself.
+ It requires a configuration file in XML format.
+ The configuration file <em>client1.xml</em>
+ shown below creates a <code>SocketAppender</code>
+ and attaches it to the root logger.
+ </p>
+ <em>Example 4.1: SocketAppender configuration (<a href="../xref/chapter4/socket/client1.html">logback-examples/src/main/java/chapter4/socket/client1.xml</a>)</em>
+<div class="source"><pre><configuration>
+
+ <appender name="SOCKET" class="ch.qos.logback.classic.net.SocketAppender">
+ <RemoteHost>${host}</RemoteHost>
+ <Port>${port}</Port>
+ <ReconnectionDelay>10000</ReconnectionDelay>
+ </appender>
+ <root>
+ <level value ="debug"/>
+ <appender-ref ref="SOCKET" />
+ </root>
+</configuration></pre></div>
+
+
+ <p>
+ Note that in the above configuration scripts the values for the
+ <span class="option">RemoteHost</span>, <span class="option">Port</span> and
+ <span class="option">IncludeCallerData</span> options
+ are not given directly but as substituted variable keys. The values for the variables
+ can be specified as system properties:
+ </p>
+
+<div class="source"><pre>java -Dhost=localhost -Dport=6000 -DincludeCallerData=false \
+ chapter4.socket.SocketClient2 chapter4/socket/client1.xml
+</pre></div>
+ <p>
+ This command should give similar results to the previous
+ <code>SocketClient1</code>
+ example.
+ </p>
+
+ <p>
+ Allow us to repeat for emphasis that serialization of logging events is not
+ intrusive. A de-serialized event carries the same information as any other
+ logging event. It can be manipulated as if it were generated locally;
+ except that serialized logging events by default do not include location
+ information. Here is an example to illustrate the point. First, start
+ <code>SimpleSocketServer</code> with the following command:
+ </p>
- <h2>Logback Classic</h2>
-
- <h2>Logback Access</h2>
+<div class="source"><pre> java ch.qos.logback.classic.net.SimpleSocketServer 6000 \
+ chapter4/socket/server2.xml
+</pre></div>
+
+ <p>
+ The configuration file <em>server2.xml</em> creates a <code>ConsoleAppender</code>
+ whose layout outputs the callers file name and line number along with other
+ information. If you run <code>SocketClient2</code> with the configuration file
+ <em>client1.xml</em> as previously, you will notice that the output on the
+ server side will contain two question marks between parentheses instead of
+ the file name and the line number of the caller:
+ </p>
+
+<div class="source"><pre>2006-11-06 17:37:30,968 DEBUG [Thread-0] [?:?] chapter4.socket.SocketClient2 - Hi</pre></div>
+
+ <p>
+ The outcome can be easily changed by instructing the <code>SocketAppender</code>
+ to include caller data by setting the <span class="option">IncludeCallerData</span>
+ option to true. Using the following command will do the trick:
+ </p>
+
+<div class="source"><pre>java -Dhost=localhost -Dport=6000 -DincludeCallerData=true \
+ chapter4.socket.SocketClient2 chapter4/socket/client1.xml
+</pre></div>
+
+ <p>
+ As deserialized events can be handled in the same way as locally
+ generated events, they even can be sent to a second server for further treatment.
+ As an exercise, you may wish to setup two servers where the first server
+ tunnels the events it receives from its clients to a second server.
+ </p>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <h2>Logback Access</h2>
Modified: logback/trunk/logback-site/src/site/xdocTemplates/manual/index.xml
==============================================================================
--- logback/trunk/logback-site/src/site/xdocTemplates/manual/index.xml (original)
+++ logback/trunk/logback-site/src/site/xdocTemplates/manual/index.xml Mon Nov 6 17:43:33 2006
@@ -38,6 +38,11 @@
page size</em> enabled, or <a
href="http://www.opera.com">Opera</a>.
</p>
+ <p>
+ To run the examples provided in this book, you might have
+ to add the logback jars to your classpath. They are available
+ on our <a href="../download.html">download page</a>.
+ </p>
</div>
<p>The logback manual describes the logback API in considerable
1
0

svn commit: r874 - logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net
by noreply.seb@qos.ch 06 Nov '06
by noreply.seb@qos.ch 06 Nov '06
06 Nov '06
Author: seb
Date: Mon Nov 6 17:42:54 2006
New Revision: 874
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketAppender.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketNode.java
Log:
Added an option to the SocketAppender to call the getCallerData method on logging events before serializing them so that
the caller data is available on the remote machine.
Minor fix to SimpleSocketServer.java
Reformat only on SocketNode.java
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java Mon Nov 6 17:42:54 2006
@@ -18,6 +18,7 @@
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.util.StatusPrinter;
/**
* A simple {@link SocketNode} based server.
@@ -92,8 +93,10 @@
if (configFile.endsWith(".xml")) {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
+ lc.reset();
configurator.setContext(lc);
configurator.doConfigure(configFile);
+ StatusPrinter.print(lc);
}
}
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketAppender.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketAppender.java Mon Nov 6 17:42:54 2006
@@ -119,6 +119,7 @@
int port = DEFAULT_PORT;
ObjectOutputStream oos;
int reconnectionDelay = DEFAULT_RECONNECTION_DELAY;
+ boolean includeCallerData = false;
private Connector connector;
@@ -248,6 +249,9 @@
if (oos != null) {
try {
+ if (includeCallerData) {
+ ((LoggingEvent)event).getCallerData();
+ }
oos.writeObject(event);
// addInfo("=========Flushing.");
oos.flush();
@@ -317,6 +321,11 @@
public int getPort() {
return port;
}
+
+ public void setIncludeCallerData(boolean includeCallerData) {
+ this.includeCallerData = includeCallerData;
+ }
+
/**
* The <b>ReconnectionDelay</b> option takes a positive integer representing
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketNode.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketNode.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketNode.java Mon Nov 6 17:42:54 2006
@@ -39,61 +39,61 @@
*/
public class SocketNode implements Runnable {
- Socket socket;
- LoggerContext context;
- ObjectInputStream ois;
-
- static Logger logger = (Logger) LoggerFactory.getLogger(SocketNode.class);
-
- public SocketNode(Socket socket, LoggerContext context) {
- this.socket = socket;
- this.context = context;
- try {
- ois = new ObjectInputStream(new BufferedInputStream(socket
- .getInputStream()));
- } catch (Exception e) {
- logger.error("Could not open ObjectInputStream to " + socket, e);
- }
- }
-
- // public
- // void finalize() {
- // System.err.println("-------------------------Finalize called");
- // System.err.flush();
- // }
-
- public void run() {
- LoggingEvent event;
- Logger remoteLogger;
-
- try {
- while (true) {
- // read an event from the wire
- event = (LoggingEvent) ois.readObject();
- // get a logger from the hierarchy. The name of the logger is taken to
- // be the name contained in the event.
- remoteLogger = context.getLogger(event.getLoggerRemoteView().getName());
- // apply the logger-level filter
- if (remoteLogger.isEnabledFor(event.getLevel())) {
- // finally log the event as if was generated locally
- remoteLogger.callAppenders(event);
- }
- }
- } catch (java.io.EOFException e) {
- logger.info("Caught java.io.EOFException closing connection.");
- } catch (java.net.SocketException e) {
- logger.info("Caught java.net.SocketException closing connection.");
- } catch (IOException e) {
- logger.info("Caught java.io.IOException: " + e);
- logger.info("Closing connection.");
- } catch (Exception e) {
- logger.error("Unexpected exception. Closing connection.", e);
- }
-
- try {
- ois.close();
- } catch (Exception e) {
- logger.info("Could not close connection.", e);
- }
- }
+ Socket socket;
+ LoggerContext context;
+ ObjectInputStream ois;
+
+ static Logger logger = (Logger) LoggerFactory.getLogger(SocketNode.class);
+
+ public SocketNode(Socket socket, LoggerContext context) {
+ this.socket = socket;
+ this.context = context;
+ try {
+ ois = new ObjectInputStream(new BufferedInputStream(socket
+ .getInputStream()));
+ } catch (Exception e) {
+ logger.error("Could not open ObjectInputStream to " + socket, e);
+ }
+ }
+
+ // public
+ // void finalize() {
+ // System.err.println("-------------------------Finalize called");
+ // System.err.flush();
+ // }
+
+ public void run() {
+ LoggingEvent event;
+ Logger remoteLogger;
+
+ try {
+ while (true) {
+ // read an event from the wire
+ event = (LoggingEvent) ois.readObject();
+ // get a logger from the hierarchy. The name of the logger is taken to
+ // be the name contained in the event.
+ remoteLogger = context.getLogger(event.getLoggerRemoteView().getName());
+ // apply the logger-level filter
+ if (remoteLogger.isEnabledFor(event.getLevel())) {
+ // finally log the event as if was generated locally
+ remoteLogger.callAppenders(event);
+ }
+ }
+ } catch (java.io.EOFException e) {
+ logger.info("Caught java.io.EOFException closing connection.");
+ } catch (java.net.SocketException e) {
+ logger.info("Caught java.net.SocketException closing connection.");
+ } catch (IOException e) {
+ logger.info("Caught java.io.IOException: " + e);
+ logger.info("Closing connection.");
+ } catch (Exception e) {
+ logger.error("Unexpected exception. Closing connection.", e);
+ }
+
+ try {
+ ois.close();
+ } catch (Exception e) {
+ logger.info("Could not close connection.", e);
+ }
+ }
}
1
0