Fornax-Platform
Forum

 « Return to Thread: logging with fornax-oaw-m2-plugin

Re: logging with fornax-oaw-m2-plugin

by polly.c.chang :: Rate this Message:

Reply to Author | View in Thread

Hi Karsten,

That's great!  And would you mind sharing what the config looks like in the workflow? 

Thanks!
--Polly


On Mon, Jun 29, 2009 at 11:02 AM, Karsten Thoms <thoms@...> wrote:
To give you a quick help here is the source:

import java.net.URL;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;
import org.openarchitectureware.workflow.WorkflowContext;
import org.openarchitectureware.workflow.issues.Issues;
import org.openarchitectureware.workflow.lib.AbstractWorkflowComponent2;
import org.openarchitectureware.workflow.monitor.ProgressMonitor;

/**
 * Use this workflow component to initialize the logging subsystem.
 *
 * <h2>Example</h2>
 *
 * <pre>
 * &lt;component class=&quot;gts.ise.common.oaw.workflow.LoggingConfiguratorComponent&quot;&gt;
 *   &lt;log4jConfig value=&quot;log4j.xml&quot;/&gt;
 * &lt;/component&gt;
 * </pre>
 *
 */
public class LoggingConfiguratorComponent extends AbstractWorkflowComponent2 {
       private static final Log LOG = LogFactory.getLog(LoggingConfiguratorComponent.class);
       private String log4jConfig;
       private URL log4jConfigURL;

       @Override
       protected void checkConfigurationInternal(Issues issues) {
               if (log4jConfig!=null) {
                       log4jConfigURL = Thread.currentThread().getContextClassLoader().getResource(log4jConfig);
                       if (log4jConfigURL==null) {
                               issues.addError("Invalid URL specified for 'log4jConfig'");
                       }
               }
       }

       @Override
       protected void invokeInternal(WorkflowContext ctx, ProgressMonitor mon,
                       Issues issues) {
               if (log4jConfigURL!=null) {
                       if (log4jConfig.endsWith(".xml")) {
                               DOMConfigurator.configure(log4jConfigURL);
                       } else if (log4jConfig.endsWith(".properties")) {
                               PropertyConfigurator.configure(log4jConfigURL);
                       }
                       LOG.info("Configured log4j with "+log4jConfig);
               }
       }

       /**
        * Sets the log4j configuration to be used.
        * @param log4jConfig Resource URL of the log4j configuration. The URL must end with
        * file extensions ".xml" or ".properties". The referred configuration must be loadable
        * by the current thread's context classloader.
        */
       public void setLog4jConfig(String log4jConfig) {
               this.log4jConfig = log4jConfig;
       }

}


----- Original Message -----
From: "Polly C. Chang" <polly.c.chang@...>
To: fornax-developer@...
Sent: Monday, June 29, 2009 4:51:33 PM (GMT+0100) Europe/Berlin
Subject: Re: [Fornax-developer] logging with fornax-oaw-m2-plugin

------------------------------------------------------------------------------


------------------------------------------------------------------------------
_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer


------------------------------------------------------------------------------

_______________________________________________
Fornax-developer mailing list
Fornax-developer@...
https://lists.sourceforge.net/lists/listinfo/fornax-developer

 « Return to Thread: logging with fornax-oaw-m2-plugin