Details

    • Type: Feature Request Feature Request
    • Status: Resolved Resolved (View Workflow)
    • Priority: Major Major
    • Resolution: Out of Date Out of Date
    • Affects Version/s: None
    • Fix Version/s: 2.0.7.GA-log4j
    • Component/s: jboss-logging-log4j
    • Security Level: Public (Everyone can see)
    • Labels:
      None
    • Similar Issues:
      None

      Description

      hi.... what do you think about a DatasourceAppender? This is very simple. It overrides getConnection and closeConnection methods of org.apache.log4j.jdbc.JDBCAppender class and it is configurable by a *-log4j.xml file. Here there is an example of xml file:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

      <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

      <appender name="DATABASE" class="org.jboss.logging.appender.DatasourceAppender">
      <param name="Threshold" value="INFO"/>
      <param name="datasource" value="java:/PortalDS"/>
      <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value=
      "INSERT INTO JBP_LOGGING_SAMPLES_USERS (log_date, log_type, log_user, operation) VALUES ( '%d

      {yyyy-MM-dd HH:mm:ss.SSS}

      ','%p', '%C;%L', '%C;%L')"/>
      </layout>
      </appender>

      <category name="org.jboss.portal.core.identity.UsersActivityStatsServiceImpl">
      <appender-ref ref="DATABASE"/>
      </category>

      </log4j:configuration>

      it is the same configuration for JDBCAppender but there is a 'datasource' parameter so you can specify the datasource location. Below there is the whole 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 datasource to
      • handle datas into database.
      • @version <tt>$Revision: 1958 $</tt>
      • @author <a href="mailto:jedim@vige.it">Luca Stancapiano</a>
        */
        public class DatasourceAppender extends org.apache.log4j.jdbc.JDBCAppender {

      /**

      • URL of the DB for default connection handling
        */
        protected String datasource = "java:/DefaultDS";
        protected DataSource ds;

      public void setDatasource(final String datasource)

      { this.datasource = datasource; }

      /**

      • I override this method to get a connection from datasource.
        */
        protected Connection getConnection() throws SQLException {
        if (connection == null || connection.isClosed())
        Unknown macro: { if (ds == null) try { InitialContext ic = new InitialContext(); ds = (DataSource) ic.lookup(datasource); } catch (NamingException e) { e.printStackTrace(); } connection = ds.getConnection(); }

      return connection;
      }

      protected void closeConnection(Connection con) {
      try

      { connection.close(); }

      catch (SQLException ex)

      { ex.printStackTrace(); }

      }
      }

        Activity

        Hide
        Luca Stancapiano
        added a comment -

        Hi David. where I find jboss logging spi source codes? I would send a patch to transform it in a OSGI bundle

        Show
        Luca Stancapiano
        added a comment - Hi David. where I find jboss logging spi source codes? I would send a patch to transform it in a OSGI bundle
        Hide
        Luca Stancapiano
        added a comment -

        I have found. I sent a patch here: https://issues.jboss.org/browse/JBLOGGING-51

        thanks anyhow

        Show
        Luca Stancapiano
        added a comment - I have found. I sent a patch here: https://issues.jboss.org/browse/JBLOGGING-51 thanks anyhow
        Hide
        David Lloyd
        added a comment -

        The source code for these projects has recently moved. To get the latest versions, go to:

        https://github.com/dmlloyd/jboss-logging
        https://github.com/dmlloyd/jboss-logmanager
        https://github.com/dmlloyd/jboss-logging-tools

        Show
        David Lloyd
        added a comment - The source code for these projects has recently moved. To get the latest versions, go to: https://github.com/dmlloyd/jboss-logging https://github.com/dmlloyd/jboss-logmanager https://github.com/dmlloyd/jboss-logging-tools
        Hide
        Luca Stancapiano
        added a comment -

        I need 'SPI' project

        Show
        Luca Stancapiano
        added a comment - I need 'SPI' project
        Hide
        David Lloyd
        added a comment -

        Closing this issue because this legacy framework no longer exists. That said, a data source appender isn't a bad idea - if you're still interested in this feature, open a new issue in the LOGMGR project.

        Show
        David Lloyd
        added a comment - Closing this issue because this legacy framework no longer exists. That said, a data source appender isn't a bad idea - if you're still interested in this feature, open a new issue in the LOGMGR project.

          People

          • Assignee:
            David Lloyd
            Reporter:
            Luca Stancapiano
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: