You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-dev@incubator.apache.org by Cosma Colanicchia <co...@gmail.com> on 2006/07/04 08:15:47 UTC

Logging system used by Trinidad

Hi,

I'm using myfaces, trinidad, facelets and a bit of shale in my project. In
my IDE, JDeveloper 10.1.3, all log entry are correctly displayed and colored
except for the facelets and trinidad ones. Example:

06/07/04 09:57:22 Oracle Containers for J2EE 10g (10.1.3.0.0)  initialized

2006-07-04 09:57:25,604 [INFO ] (org.apache.commons.chain.web.ChainListener)

2006-07-04 09:57:25,995 [INFO ] (org.apache.myfaces.config.FacesConfigurator
)
2006-07-04 09:57:26,276 [INFO ] (org.apache.myfaces.config.FacesConfigurator
)
2006-07-04 09:57:26,386 [INFO ] (org.apache.myfaces.config.FacesConfigurator
)
2006-07-04 09:57:26,464 [INFO ] (org.apache.myfaces.config.FacesConfigurator
)
2006-07-04 09:57:26,636 [INFO ] (org.apache.myfaces.config.FacesConfigurator
)
2006-07-04 09:57:29,839 [INFO ] (org.apache.myfaces.config.FacesConfigurator
)
2006-07-04 09:57:29,870 [INFO ] (org.apache.myfaces.config.FacesConfigurator
)
2006-07-04 09:57:29,995 [INFO ] (org.apache.myfaces.config.FacesConfigurator
)
2006-07-04 09:57:30,151 [INFO ] (org.apache.myfaces.config.FacesConfigurator
)
2006-07-04 09:57:30,292 [WARN ] (
org.apache.myfaces.shared_impl.util.LocaleUt
2006-07-04 09:57:32,527 [WARN ] (
org.apache.myfaces.shared_impl.webapp.webxml
2006-07-04 09:57:32,527 [WARN ] (
org.apache.myfaces.shared_impl.webapp.webxml
2006-07-04 09:57:32,527 [INFO ] (
org.apache.myfaces.webapp.StartupServletCont
2006-07-04 09:57:32,542 [INFO ] (
org.apache.myfaces.webapp.StartupServletCont
2006-07-04 09:57:32,605 [INFO ] (
org.apache.shale.faces.ShaleApplicationFilte
2006-07-04 09:57:32,964 [DEBUG] (javax.faces.webapp.FacesServlet) init begin

2006-07-04 09:57:32,964 [DEBUG] (javax.faces.webapp.FacesServlet) init end

4-lug-2006 9.58.30 org.apache.myfaces.adfinternal.webapp.ConfigParserparseCo
INFO: ADF Faces is running in debug mode. Do not use in a production
environm
2006-07-04 09:58:30,732 [DEBUG] (javax.faces.webapp.FacesServlet) service
beg
4-lug-2006 9.58.30
org.apache.myfaces.adfinternal.application.ViewHandlerImpl
INFO: ADF Faces is running with time-stamp checking enabled. This should not

4-lug-2006 9.58.33 com.sun.facelets.compiler.TagLibraryConfig loadImplicit

INFO: Added Library from:
code-source:/D:/Sviluppo/Non-CVS-Projects/jsf-test/
4-lug-2006 9.58.33 com.sun.facelets.compiler.TagLibraryConfig loadImplicit

INFO: Added Library from:
code-source:/D:/Sviluppo/Non-CVS-Projects/jsf-test/
4-lug-2006 9.58.33 com.sun.facelets.compiler.TagLibraryConfig loadImplicit

INFO: Added Library from:
code-source:/D:/Sviluppo/Non-CVS-Projects/jsf-test/
4-lug-2006 9.58.33 com.sun.facelets.compiler.TagLibraryConfig loadImplicit

INFO: Added Library from:
code-source:/D:/Sviluppo/Non-CVS-Projects/jsf-test/
4-lug-2006 9.58.33 com.sun.facelets.compiler.TagLibraryConfig loadImplicit

INFO: Added Library from:
code-source:/D:/Sviluppo/Non-CVS-Projects/jsf-test/
4-lug-2006 9.58.33 com.sun.facelets.compiler.TagLibraryConfig loadImplicit

INFO: Added Library from:
code-source:/D:/Sviluppo/Non-CVS-Projects/jsf-test/
4-lug-2006 9.58.33 com.sun.facelets.compiler.TagLibraryConfig loadImplicit

INFO: Added Library from:
code-source:/D:/Sviluppo/Non-CVS-Projects/jsf-test/
2006-07-04 09:58:37,467 [INFO ] (
org.apache.myfaces.shared_tomahawk.config.My
2006-07-04 09:58:37,467 [INFO ] (
org.apache.myfaces.shared_tomahawk.config.My
2006-07-04 09:58:37,483 [INFO ] (
org.apache.myfaces.shared_tomahawk.config.My

My IDE marks all the facelets and trinidad log lines (those which start in
INFO:) in red.. seems that the difference is in the logging framework used:
myfaces uses commons logging, while Trinidad uses java.util.logging. It is
only a detail, but having always all those red lines could make me miss some
"real" warning.

How other IDEs shows those lines? Any chance to adopt commons logging in the
Trinidad's ADFLogger class?

Re: Logging system used by Trinidad

Posted by Cosma Colanicchia <co...@gmail.com>.
Ok, I defined a listener in my web.xml and it works very well, thanks a lot!

Cosma


2006/7/4, Frank Felix Debatin <ff...@gmx.net>:
>
> Call JDKToCommonsLogging.activate() somewhere in your start
> up code, and deactivate() in your shutdown code.
>
> > -----Original Message-----
> > From: Cosma Colanicchia [mailto:cosmacol@gmail.com]
> > Sent: Tuesday, July 04, 2006 10:32 AM
> > To: adffaces-dev@incubator.apache.org
> > Subject: Re: Logging system used by Trinidad
> >
> > Thank you very much Frank, but this class has to be
> > "registered" somewhere?
> >
> >
> >
> > 2006/7/4, Frank Felix Debatin <ff...@gmx.net>:
> > >
> > > Hi Cosma,
> > >
> > > I worked around this by writing a simplistic log handler
>
> > that accepts
> > > JDK log messages and send them to commons logging.
> > >
> > > Feel free to use, below.
> > >
> > > Frank Felix
> > >
> > > _______________________
> > >
> > > package whatever;
> > >
> > > import java.util.Map;
> > > import java.util.concurrent.ConcurrentHashMap;
> > > import java.util.logging.*;
> > >
> > > import org.apache.commons.logging.Log; import
> > > org.apache.commons.logging.LogFactory;
> > >
> > > /**
> > > * Writes JDK log messages to commons logging.
> > > */
> > > public class JDKToCommonsLogging
> > > {
> > >     static JDKLogHandler activeHandler;
> > >
> > >     /**
> > >      * Activates this feature.
> > >      */
> > >     public static void activate()
> > >     {
> > >         try
> > >         {
> > >             Logger rootLogger =
> > > LogManager.getLogManager().getLogger("");
> > >             // remove old handlers
> > >             for (Handler handler:
> rootLogger.getHandlers())
> > >             {
> > >                 rootLogger.removeHandler(handler);
> > >             }
> > >             // add our own
> > >             activeHandler = new JDKLogHandler();
> > >             rootLogger.addHandler(activeHandler);
> > >             // done, let's check it right away!!!
> > >
> > > Logger.getLogger(JDKToCommonsLogging.class.getName())
> > >                 .info("activated: sending JDK log
> messages
> > to Commons
> > > Logging");
> > >         }
> > >         catch (Exception exc)
> > >         {
> > >             LogFactory.getLog(JDKToCommonsLogging.class)
> > >                 .error("activation failed", exc);
> > >         }
> > >     }
> > >
> > >     public static void deactivate()
> > >     {
> > >         Logger rootLogger =
> > > LogManager.getLogManager().getLogger("");
> > >         rootLogger.removeHandler(activeHandler);
> > >
> > > Logger.getLogger(JDKToCommonsLogging.class.getName())
> > >             .info("dactivated");
> > >     }
> > >
> > >     private static class JDKLogHandler extends Handler
> > >     {
> > >         private Map<String, Log> cachedLogs = new
> > > ConcurrentHashMap<String, Log>();
> > >
> > >         private Log getLog(String logName)
> > >         {
> > >             Log log = cachedLogs.get(logName);
> > >             if (log==null)
> > >             {
> > >                 log = LogFactory.getLog(logName);
> > >                 cachedLogs.put(logName, log);
> > >             }
> > >             return log;
> > >         }
> > >
> > >         @Override
> > >         public void publish(LogRecord record)
> > >         {
> > >             Log log = getLog(record.getLoggerName());
> > >             String message = record.getMessage();
> > >             Throwable exception = record.getThrown();
> > >             Level level = record.getLevel();
> > >             if (level==Level.SEVERE){
> > >                 log.error(message, exception);
> > >             } else if (level==Level.WARNING) {
> > >                 log.warn(message, exception);
> > >             } else if (level==Level.INFO) {
> > >                 log.info(message, exception);
> > >             } else if (level==Level.CONFIG) {
> > >                 log.debug(message, exception);
> > >             } else {
> > >                 log.trace(message, exception);
> > >             }
> > >         }
> > >
> > >         @Override
> > >         public void flush()
> > >         {
> > >            // nothing to do
> > >         }
> > >
> > >         @Override
> > >         public void close()
> > >         {
> > >             // nothing to do
> > >         }
> > >     }
> > > }
> > >
> > >
> >
>
>

RE: Logging system used by Trinidad

Posted by Frank Felix Debatin <ff...@gmx.net>.
Call JDKToCommonsLogging.activate() somewhere in your start
up code, and deactivate() in your shutdown code. 

> -----Original Message-----
> From: Cosma Colanicchia [mailto:cosmacol@gmail.com] 
> Sent: Tuesday, July 04, 2006 10:32 AM
> To: adffaces-dev@incubator.apache.org
> Subject: Re: Logging system used by Trinidad
> 
> Thank you very much Frank, but this class has to be 
> "registered" somewhere?
> 
> 
> 
> 2006/7/4, Frank Felix Debatin <ff...@gmx.net>:
> >
> > Hi Cosma,
> >
> > I worked around this by writing a simplistic log handler

> that accepts 
> > JDK log messages and send them to commons logging.
> >
> > Feel free to use, below.
> >
> > Frank Felix
> >
> > _______________________
> >
> > package whatever;
> >
> > import java.util.Map;
> > import java.util.concurrent.ConcurrentHashMap;
> > import java.util.logging.*;
> >
> > import org.apache.commons.logging.Log; import 
> > org.apache.commons.logging.LogFactory;
> >
> > /**
> > * Writes JDK log messages to commons logging.
> > */
> > public class JDKToCommonsLogging
> > {
> >     static JDKLogHandler activeHandler;
> >
> >     /**
> >      * Activates this feature.
> >      */
> >     public static void activate()
> >     {
> >         try
> >         {
> >             Logger rootLogger =
> > LogManager.getLogManager().getLogger("");
> >             // remove old handlers
> >             for (Handler handler:
rootLogger.getHandlers())
> >             {
> >                 rootLogger.removeHandler(handler);
> >             }
> >             // add our own
> >             activeHandler = new JDKLogHandler();
> >             rootLogger.addHandler(activeHandler);
> >             // done, let's check it right away!!!
> >
> > Logger.getLogger(JDKToCommonsLogging.class.getName())
> >                 .info("activated: sending JDK log
messages 
> to Commons 
> > Logging");
> >         }
> >         catch (Exception exc)
> >         {
> >             LogFactory.getLog(JDKToCommonsLogging.class)
> >                 .error("activation failed", exc);
> >         }
> >     }
> >
> >     public static void deactivate()
> >     {
> >         Logger rootLogger =
> > LogManager.getLogManager().getLogger("");
> >         rootLogger.removeHandler(activeHandler);
> >
> > Logger.getLogger(JDKToCommonsLogging.class.getName())
> >             .info("dactivated");
> >     }
> >
> >     private static class JDKLogHandler extends Handler
> >     {
> >         private Map<String, Log> cachedLogs = new 
> > ConcurrentHashMap<String, Log>();
> >
> >         private Log getLog(String logName)
> >         {
> >             Log log = cachedLogs.get(logName);
> >             if (log==null)
> >             {
> >                 log = LogFactory.getLog(logName);
> >                 cachedLogs.put(logName, log);
> >             }
> >             return log;
> >         }
> >
> >         @Override
> >         public void publish(LogRecord record)
> >         {
> >             Log log = getLog(record.getLoggerName());
> >             String message = record.getMessage();
> >             Throwable exception = record.getThrown();
> >             Level level = record.getLevel();
> >             if (level==Level.SEVERE){
> >                 log.error(message, exception);
> >             } else if (level==Level.WARNING) {
> >                 log.warn(message, exception);
> >             } else if (level==Level.INFO) {
> >                 log.info(message, exception);
> >             } else if (level==Level.CONFIG) {
> >                 log.debug(message, exception);
> >             } else {
> >                 log.trace(message, exception);
> >             }
> >         }
> >
> >         @Override
> >         public void flush()
> >         {
> >            // nothing to do
> >         }
> >
> >         @Override
> >         public void close()
> >         {
> >             // nothing to do
> >         }
> >     }
> > }
> >
> >
> 


Re: Logging system used by Trinidad

Posted by Cosma Colanicchia <co...@gmail.com>.
Thank you very much Frank, but this class has to be "registered" somewhere?



2006/7/4, Frank Felix Debatin <ff...@gmx.net>:
>
> Hi Cosma,
>
> I worked around this by writing a simplistic log handler
> that accepts JDK log messages and send them to commons
> logging.
>
> Feel free to use, below.
>
> Frank Felix
>
> _______________________
>
> package whatever;
>
> import java.util.Map;
> import java.util.concurrent.ConcurrentHashMap;
> import java.util.logging.*;
>
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
>
> /**
> * Writes JDK log messages to commons logging.
> */
> public class JDKToCommonsLogging
> {
>     static JDKLogHandler activeHandler;
>
>     /**
>      * Activates this feature.
>      */
>     public static void activate()
>     {
>         try
>         {
>             Logger rootLogger =
> LogManager.getLogManager().getLogger("");
>             // remove old handlers
>             for (Handler handler: rootLogger.getHandlers())
>             {
>                 rootLogger.removeHandler(handler);
>             }
>             // add our own
>             activeHandler = new JDKLogHandler();
>             rootLogger.addHandler(activeHandler);
>             // done, let's check it right away!!!
>
> Logger.getLogger(JDKToCommonsLogging.class.getName())
>                 .info("activated: sending JDK log messages
> to Commons Logging");
>         }
>         catch (Exception exc)
>         {
>             LogFactory.getLog(JDKToCommonsLogging.class)
>                 .error("activation failed", exc);
>         }
>     }
>
>     public static void deactivate()
>     {
>         Logger rootLogger =
> LogManager.getLogManager().getLogger("");
>         rootLogger.removeHandler(activeHandler);
>
> Logger.getLogger(JDKToCommonsLogging.class.getName())
>             .info("dactivated");
>     }
>
>     private static class JDKLogHandler extends Handler
>     {
>         private Map<String, Log> cachedLogs = new
> ConcurrentHashMap<String, Log>();
>
>         private Log getLog(String logName)
>         {
>             Log log = cachedLogs.get(logName);
>             if (log==null)
>             {
>                 log = LogFactory.getLog(logName);
>                 cachedLogs.put(logName, log);
>             }
>             return log;
>         }
>
>         @Override
>         public void publish(LogRecord record)
>         {
>             Log log = getLog(record.getLoggerName());
>             String message = record.getMessage();
>             Throwable exception = record.getThrown();
>             Level level = record.getLevel();
>             if (level==Level.SEVERE){
>                 log.error(message, exception);
>             } else if (level==Level.WARNING) {
>                 log.warn(message, exception);
>             } else if (level==Level.INFO) {
>                 log.info(message, exception);
>             } else if (level==Level.CONFIG) {
>                 log.debug(message, exception);
>             } else {
>                 log.trace(message, exception);
>             }
>         }
>
>         @Override
>         public void flush()
>         {
>            // nothing to do
>         }
>
>         @Override
>         public void close()
>         {
>             // nothing to do
>         }
>     }
> }
>
>

RE: Logging system used by Trinidad

Posted by Frank Felix Debatin <ff...@gmx.net>.
Hi Cosma, 

I worked around this by writing a simplistic log handler
that accepts JDK log messages and send them to commons
logging. 

Feel free to use, below.

Frank Felix 

_______________________

package whatever;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Writes JDK log messages to commons logging.
 */
public class JDKToCommonsLogging 
{
    static JDKLogHandler activeHandler;
    
    /**
     * Activates this feature. 
     */
    public static void activate() 
    {
        try
        {
            Logger rootLogger =
LogManager.getLogManager().getLogger("");
            // remove old handlers
            for (Handler handler: rootLogger.getHandlers())
            {
                rootLogger.removeHandler(handler);
            }
            // add our own
            activeHandler = new JDKLogHandler();
            rootLogger.addHandler(activeHandler);
            // done, let's check it right away!!!
 
Logger.getLogger(JDKToCommonsLogging.class.getName())
                .info("activated: sending JDK log messages
to Commons Logging");
        }
        catch (Exception exc)
        {
            LogFactory.getLog(JDKToCommonsLogging.class)
                .error("activation failed", exc);
        }
    }
    
    public static void deactivate()
    {
        Logger rootLogger =
LogManager.getLogManager().getLogger("");
        rootLogger.removeHandler(activeHandler);
 
Logger.getLogger(JDKToCommonsLogging.class.getName())
            .info("dactivated");
    }
    
    private static class JDKLogHandler extends Handler
    {
        private Map<String, Log> cachedLogs = new
ConcurrentHashMap<String, Log>();
        
        private Log getLog(String logName)
        {
            Log log = cachedLogs.get(logName);
            if (log==null)
            {
                log = LogFactory.getLog(logName);
                cachedLogs.put(logName, log);
            }
            return log;
        }
        
        @Override
        public void publish(LogRecord record)
        {
            Log log = getLog(record.getLoggerName());
            String message = record.getMessage();
            Throwable exception = record.getThrown();
            Level level = record.getLevel();
            if (level==Level.SEVERE){
                log.error(message, exception);
            } else if (level==Level.WARNING) {
                log.warn(message, exception);
            } else if (level==Level.INFO) {
                log.info(message, exception);
            } else if (level==Level.CONFIG) {
                log.debug(message, exception);
            } else {
                log.trace(message, exception);
            }
        }
    
        @Override
        public void flush()
        {
           // nothing to do
        }
    
        @Override
        public void close()
        {
            // nothing to do
        }
    }
}