From jira-events at lists.jboss.org Tue Aug 19 18:03:35 2008 Content-Type: multipart/mixed; boundary="===============8673410916314434981==" MIME-Version: 1.0 From: Luca Stancapiano (JIRA) To: jboss-jira at lists.jboss.org Subject: [jboss-jira] [JBoss JIRA] Created: (JBLOGGING-6) DatasourceAppender Date: Tue, 19 Aug 2008 18:03:35 -0400 Message-ID: <27181334.1219183415489.JavaMail.jira@cloud.prod.atl2.jboss.com> --===============8673410916314434981== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable DatasourceAppender ------------------ Key: JBLOGGING-6 URL: https://jira.jboss.org/jira/browse/JBLOGGING-6 Project: JBoss Logging Issue Type: Feature Request Security Level: Public (Everyone can see) Components: jboss-logging-log4j Affects Versions: 1.0.0.GA-slf4j-jboss-logging, 2.0.6.GA-spi Reporter: Luca Stancapiano Assignee: Dimitris Andreadis Fix For: 2.0.6.GA-spi, 1.0.0.GA-slf4j-jboss-logging hi.... what do you think about a DatasourceAppender? This is very simple. I= t overrides getConnection and closeConnection methods of org.apache.log4j.j= dbc.JDBCAppender class and it is configurable by a *-log4j.xml file. Here t= here is an example of xml file: = = = it is the same configuration for JDBCAppender but there is a 'datasource' p= arameter so you can specify the datasource location. Below there is the who= le class: /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This 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; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.logging.appender; import java.sql.Connection; import java.sql.SQLException; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; /** * An extension of the default Log4j JDBCAppender which will use a datasour= ce to * handle datas into database. * = * @version $Revision: 1958 $ * @author Luca Stancapiano */ public class DatasourceAppender extends org.apache.log4j.jdbc.JDBCAppender { /** * URL of the DB for default connection handling */ protected String datasource =3D "java:/DefaultDS"; protected DataSource ds; public void setDatasource(final String datasource) { this.datasource =3D datasource; } /** * I override this method to get a connection from datasource. */ protected Connection getConnection() throws SQLException { if (connection =3D=3D null || connection.isClosed()) { if (ds =3D=3D null) try { InitialContext ic =3D new InitialContext(); ds =3D (DataSource) ic.lookup(datasource); } catch (NamingException e) { e.printStackTrace(); } connection =3D ds.getConnection(); } return connection; } protected void closeConnection(Connection con) { try { connection.close(); } catch (SQLException ex) { ex.printStackTrace(); } } } -- = This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: htt= ps://jira.jboss.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira =20 --===============8673410916314434981==--