Log4j within Web Application...

Discussion in 'Java' started by schmen, Feb 26, 2004.

  1. schmen

    schmen Guest

    Currently, I expose my logger through a static method on a utility
    class, the logger is statically configured within the utility class.
    I originally went this route in that I needed the logger available to
    my business classes as well as my servlets/jsps.

    Can anyone offer any suggestion that may be better suited for web
    deployment?

    Thanks for any suggestions!
    schmen, Feb 26, 2004
    #1
    1. Advertising

  2. schmen

    Huan Ding Guest

    how about java.util.logging.

    "schmen" <> wrote in message
    news:...
    > Currently, I expose my logger through a static method on a utility
    > class, the logger is statically configured within the utility class.
    > I originally went this route in that I needed the logger available to
    > my business classes as well as my servlets/jsps.
    >
    > Can anyone offer any suggestion that may be better suited for web
    > deployment?
    >
    > Thanks for any suggestions!
    Huan Ding, Feb 26, 2004
    #2
    1. Advertising

  3. schmen

    Aidan Guest

    schmen wrote:

    > Currently, I expose my logger through a static method on a utility
    > class, the logger is statically configured within the utility
    > class. I originally went this route in that I needed the logger
    > available to my business classes as well as my servlets/jsps.
    >
    > Can anyone offer any suggestion that may be better suited for web
    > deployment?
    >
    > Thanks for any suggestions!


    Hmmm, Here is my sloppy solution for class by class logging. Not
    ideal I'm sure but works for me.

    I put log4-?.??.??.jar into WEB-INF/lib and log4j.properties into
    WEB-INF/classes, and code thusly ...

    // Servlet
    import org.apache.log4j.*;
    public class JobParserServlet extends HttpServlet {
    static Logger logger = Logger.getLogger(JobParserServlet.class);
    public void init() {
    logger.debug("Initialising JobParserServlet");
    }
    ....
    }

    or

    //Base Class
    import org.apache.log4j.*;
    public abstract class BasicCommand implements Command {
    public static Logger logger = Logger.getLogger(Command.class);
    public void execute(CommandContext c) throws JobStepException {}
    }

    //Derived Class
    public class CommandSequence extends BasicCommand {
    public void execute() throws JobStepException {
    logger.debug("CommandSequence Executing");
    }
    }

    and here is my untidy hackable log4j.properties file ...

    # Set root logger level to DEBUG and its only appender to LogServer.
    log4j.rootCategory=DEBUG, LogServer

    #log4j.appender.LogServer=org.apache.log4j.net.SocketAppender
    #log4j.appender.LogServer=org.apache.log4j.lf5.LF5Appender
    #log4j.appender.LogServer.Port=4445
    #log4j.appender.LogServer.RemoteHost=aachen

    #Rolling File
    log4j.appender.LogServer=org.apache.log4j.RollingFileAppender
    log4j.appender.LogServer.File=/var/tmp/webapp.log
    log4j.appender.LogServer.MaxFileSize=2048KB
    log4j.appender.LogServer.MaxBackupIndex=2

    # uses PatternLayout.
    log4j.appender.LogServer.layout=org.apache.log4j.PatternLayout
    log4j.appender.LogServer.layout.ConversionPattern=%d [%t] %-5p
    (%c{1}:%L) %m%n
    #log4j.appender.LogServer.layout.ConversionPattern=[%t] %-5p
    (%c{1}:%L) %m%n

    log4j.logger.com.dautelle=WARN, LogServer
    log4j.logger.org.apache.commons=WARN, LogServer
    log4j.logger.org.apache.commons.digester.Digester=WARN, LogServer


    Any help?

    Aidan
    Aidan, Feb 27, 2004
    #3
  4. schmen

    schmen Guest

    I am actually servicing an existing web app, and there are a couple
    key services that are immutable (i.e.) logging, connection pool,
    etc...

    So, Log4j is it for this project.

    Any ideas or opinions as to the best approach to where code should be
    for the log4j initialization and how to expose the loggers to the
    various servlets and business classes?


    "Huan Ding" <> wrote in message news:<>...
    > how about java.util.logging.
    >
    > "schmen" <> wrote in message
    > news:...
    > > Currently, I expose my logger through a static method on a utility
    > > class, the logger is statically configured within the utility class.
    > > I originally went this route in that I needed the logger available to
    > > my business classes as well as my servlets/jsps.
    > >
    > > Can anyone offer any suggestion that may be better suited for web
    > > deployment?
    > >
    > > Thanks for any suggestions!
    schmen, Feb 27, 2004
    #4
  5. schmen

    Chris Guest

    > I am actually servicing an existing web app, and there are a couple
    > key services that are immutable (i.e.) logging, connection pool,
    > etc...
    >
    > So, Log4j is it for this project.
    >
    > Any ideas or opinions as to the best approach to where code should be
    > for the log4j initialization and how to expose the loggers to the
    > various servlets and business classes?
    >

    Only one suggestion: put the log4j jar file in the main /lib directory for
    your app server, not in WEB-INF/lib. You'll have classloader headaches if
    you use log4j from a servlet and then from another class which was not
    created within your webapp.
    Chris, Feb 27, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexandra Stehman

    eclipse, junit, log4j, & finding log4j.xml

    Alexandra Stehman, Jan 19, 2004, in forum: Java
    Replies:
    0
    Views:
    5,770
    Alexandra Stehman
    Jan 19, 2004
  2. Alex Hunsley
    Replies:
    2
    Views:
    12,931
    =?ISO-8859-15?Q?Fr=E9d=E9ric_G=E9din?=
    May 28, 2004
  3. Rodolfo
    Replies:
    0
    Views:
    952
    Rodolfo
    Jul 12, 2004
  4. joes
    Replies:
    1
    Views:
    2,158
  5. Gianni Galore
    Replies:
    0
    Views:
    1,270
    Gianni Galore
    Sep 8, 2010
Loading...

Share This Page