You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Tommy Santoso <To...@osa.de> on 2001/02/28 12:54:24 UTC

ServletOutputLogTarget.java

Avalon Developer team,

I'm using avalon framework at the moment, specially org.apache.log
package.

There are some LogTargets supported,  but it doesn't support Servlet
logging (eg. for tomcat).

I have created ServletOutputLogTarget class, which has this
functionality. This is my first contribution for

avalon-dev, and hope everything goes well.

/*
 * Copyright (C) The Apache Software Foundation. All rights reserved.
 *
 * This software is published under the terms of the Apache Software
License
 * version 1.1, a copy of which has been included with this distribution
in
 * the LICENSE file.
 */

package org.apache.log.output;

import    javax.servlet.ServletContext;
import    org.apache.log.output.DefaultOutputLogTarget;

/**
 * Generic logging interface. Implementations are based on the strategy
 * pattern.
 * @author <a href="mailto:Tommy.Santoso@osa.de">Tommy Santoso</a>
 */
public class ServletOutputLogTarget
     extends DefaultOutputLogTarget
{
     private ServletContext context = null;

     /**
      * Constructor.
      *
      * @param context ServletContext to use for logging.
      */
     public ServletOutputLogTarget(ServletContext context)
     {
          this.context = context;
     }

     /**
      * Logs message to servlet context log file
      *
      * @param message message to log to servlet context log file.
      */
     protected void output(final String message)
     {
          if (context != null){
               synchronized(this){
                    context.log(message);
               }
          }
     }
}


Thanks,

Tommy Santoso




Re: ServletOutputLogTarget.java

Posted by Berin Loritsch <bl...@apache.org>.
Tommy Santoso wrote:
> 
> Avalon Developer team,
> 
> I'm using avalon framework at the moment, specially org.apache.log
> package.
> 
> There are some LogTargets supported,  but it doesn't support Servlet
> logging (eg. for tomcat).
> 
> I have created ServletOutputLogTarget class, which has this
> functionality. This is my first contribution for
> 
> avalon-dev, and hope everything goes well.

Thanks.  Now, I don't know if you've noticed, but in Cocoon we created
this LogTarget independently, about three months ago.  It wasn't
incorporated into the root package because we thought that it was
too specific.

Oh, I think the Context is supposed to be Thread Safe.  Even then,
we are sending a single message--it should be ok.

> 
> /*
>  * Copyright (C) The Apache Software Foundation. All rights reserved.
>  *
>  * This software is published under the terms of the Apache Software
> License
>  * version 1.1, a copy of which has been included with this distribution
> in
>  * the LICENSE file.
>  */
> 
> package org.apache.log.output;
> 
> import    javax.servlet.ServletContext;
> import    org.apache.log.output.DefaultOutputLogTarget;
> 
> /**
>  * Generic logging interface. Implementations are based on the strategy
>  * pattern.
>  * @author <a href="mailto:Tommy.Santoso@osa.de">Tommy Santoso</a>
>  */
> public class ServletOutputLogTarget
>      extends DefaultOutputLogTarget
> {
>      private ServletContext context = null;
> 
>      /**
>       * Constructor.
>       *
>       * @param context ServletContext to use for logging.
>       */
>      public ServletOutputLogTarget(ServletContext context)
>      {
>           this.context = context;
>      }
> 
>      /**
>       * Logs message to servlet context log file
>       *
>       * @param message message to log to servlet context log file.
>       */
>      protected void output(final String message)
>      {
>           if (context != null){
>                synchronized(this){
>                     context.log(message);
>                }
>           }
>      }
> }
> 
> Thanks,
> 
> Tommy Santoso
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org

Re: ServletOutputLogTarget.java

Posted by Peter Donald <do...@apache.org>.
Kewl - will commit it a bit later on ;)


At 12:54  28/2/01 +0100, Tommy Santoso wrote:
>Avalon Developer team,
>
>I'm using avalon framework at the moment, specially org.apache.log
>package.
>
>There are some LogTargets supported,  but it doesn't support Servlet
>logging (eg. for tomcat).
>
>I have created ServletOutputLogTarget class, which has this
>functionality. This is my first contribution for
>
>avalon-dev, and hope everything goes well.
>
>/*
> * Copyright (C) The Apache Software Foundation. All rights reserved.
> *
> * This software is published under the terms of the Apache Software
>License
> * version 1.1, a copy of which has been included with this distribution
>in
> * the LICENSE file.
> */
>
>package org.apache.log.output;
>
>import    javax.servlet.ServletContext;
>import    org.apache.log.output.DefaultOutputLogTarget;
>
>/**
> * Generic logging interface. Implementations are based on the strategy
> * pattern.
> * @author <a href="mailto:Tommy.Santoso@osa.de">Tommy Santoso</a>
> */
>public class ServletOutputLogTarget
>     extends DefaultOutputLogTarget
>{
>     private ServletContext context = null;
>
>     /**
>      * Constructor.
>      *
>      * @param context ServletContext to use for logging.
>      */
>     public ServletOutputLogTarget(ServletContext context)
>     {
>          this.context = context;
>     }
>
>     /**
>      * Logs message to servlet context log file
>      *
>      * @param message message to log to servlet context log file.
>      */
>     protected void output(final String message)
>     {
>          if (context != null){
>               synchronized(this){
>                    context.log(message);
>               }
>          }
>     }
>}
>
>
>Thanks,
>
>Tommy Santoso
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
>
>
Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*