logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sneha Nikum" <snehani...@gmail.com>
Subject Re: Help needed with log4j used with JBOSS server
Date Thu, 24 Jan 2008 07:31:58 GMT
Hi Jacob,
         Firstly, thanks for the mail.
         Here is the config file,

log4j.rootLogger=, A1, A2

# A1 is set to be ConsoleAppender sending its output to System.out

log4j.appender.A1=org.apache.log4j.ConsoleAppender



# A1 uses PatternLayout.

log4j.appender.A1.layout=org.apache.log4j.PatternLayout

# The conversion pattern consists of date in ISO8601 format, level,

# thread name, logger name truncated to its rightmost two components

# and left justified to 17 characters, location information consisting

# of file name (padded to 13 characters) and line number, nested

# diagnostic context, the and the application supplied message

log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-17c{2}- %m%n

# Appender A2 writes to the file "test".

log4j.appender.A2=org.apache.log4j.FileAppender

log4j.appender.A2.File=C:\my_hosted_service\logs\logfile.txt

# Truncate 'logger' if it aleady exists.

log4j.appender.A2.Append=true

# Appender A2 uses the PatternLayout.

log4j.appender.A2.layout=org.apache.log4j.PatternLayout

log4j.appender.A2.layout.ConversionPattern=%d %-5p [%t] %c{2} - %m%n



And this is the way its been used in my code:

import org.apache.log4j.FileAppender;

import org.apache.log4j.Level;

import org.apache.log4j.Logger;

import org.apache.log4j.PatternLayout;

import org.apache.log4j.PropertyConfigurator;

import org.apache.log4j.WriterAppender;

some more imports here....

public class MyFilter implements Filter {

static Logger logger = Logger.getLogger("MyFilter");

public void doFilter(ServletRequest request, ServletResponse response,

FilterChain fChain) throws IOException, ServletException {

PropertyConfigurator.configure("logger.properties"); //property file placed
under WEB-INF/classes

logger.info("Info log message);

logger.debug("debug log message");

// reset of my code

}

Here is how I have used log4j in my code.

I am new to both log4j and JBOSS, so can you please let me know what is the
necessary that i need to do to get my logs under
"C:\my_hosted_service\logs\logfile.txt". I have also checked all the places
but no "logfile.txt" is being created. And i could see my application logs
aswell into the JBOSS server.txt logs along with the server logs.

Thanks and ragards

Sneha






On Jan 23, 2008 10:56 PM, Jacob Kjome <hoju@visi.com> wrote:

>
> First, last I heard, JBoss uses single uber-classloader.  The log4j.jar in
> your own application won't be used if it's already been loaded by JBoss as
> a
> server library.  Even if single classloader concept wasn't used, unless
> JBoss
> allowed you to configure your webapps to use child-first classloading
> behavior, you can't expect your copy of log4j.jar in WEB-INF/lib to be
> used.
>
> Since it's pretty clear that the server-provided log4j.jar is being used
> and
> we know that log4j, by default, loads the first log4j.xml or
> log4j.properties
> (in that order) that it finds at the first use of LogManager.class, you
> are
> correct in thinking that some other log4j configuration file is being
> used....
> at least initially.
>
> Furthermore, from what I remember, JBoss sets it's own logger repository
> selector to separate application logging (and server logging).  So, even
> if
> you see logs showing up in JBoss's configured areas, this might only apply
> to
> the logger repository that the JBoss server is using, not individual
> applications running under JBoss.
>
> That said, I'm not sure why you don't see creation of your log file?  Your
> properties file wasn't atached to the message (I think the list strips
> attachments).  Just paste it as text in the message next time.  When you
> run
> configure(), it should be configuring the logger repository assigned to
> your
> application (again, assuming JBoss is, indeed, setting the repository
> selector
> at startup).  And you shouldn't be calling configure() more than once in
> the
> entirety of your running application, unless you really understand what
> your
> are doing and mean to do it.  That doesn't appear to be the case here.
>
> One thing to check is that the directory you want your log file to appear
> is
> has been created.  Log4j won't do that for you.  If the directory doesn't
> exist, your log file won't exist.  In any case, paste your config and give
> us
> more info on what JBoss is doing as far as setting repository selectors
> and
> whatnot.   I am not an expert in JBoss (haven't used it for years), so
> take
> what I say about it with a grain of salt.
>
>
> Jake
>
>
> On Wed, 23 Jan 2008 10:52:06 +0530
>  "Sneha Nikum" <snehanikum@gmail.com> wrote:
> > Hi Ruchi,
> >     I will surely try this out. But am yet not sure if this is going to
> > work, because the problem here is that the .property file that I have
> > written is simply not used. Its using the .property file that  is in the
> > <JBOSS_HOME>server\default\conf directory. The log4j.xml file is being
> used.
> >   But anyways wil give this a try. Thanks for the prompt reply
> >
> > Thanks and Regards
> > --
> > Sneha Anil Nikum
> > Don't get even with people
> > get AHEAD of them!
> >
> >
> > On Jan 23, 2008 10:44 AM, Ruchi Mishra <ruchi.m@zensar.com> wrote:
> >
> >> Hi Sneha,
> >>
> >> What you can do is create a log4jinitServlet class and in that servlet
> >> configure the path of your properties file.
> >> This servlet need to be mapped in your web.xml file.
> >>
> >> regards
> >> Ruchi
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> ________________________________
> >>
> >> From: Sneha Nikum [mailto:snehanikum@gmail.com]
> >> Sent: Wednesday, January 23, 2008 10:38 AM
> >> To: log4j-user@logging.apache.org
> >> Subject: Help needed with log4j used with JBOSS server
> >>
> >>
> >> Hi,
> >>      I am Sneha, I am working on creating a hosted service, and using
> >> log4j for logging purpose. I am new to it.
> >>     I am trying to log the details to a log file, using a .properties
> >> file. I have placed this file into the WEB-INF->classes directory.
> >> But yet, after I run the project, the log file is not getting created,
> >> the logs are going into the server.log file of JBOSS. I think this
> >> problem has something to do with the class loaders. As JBOSS also has
> >> its own log4j.jar .
> >>
> >>    I have attached with this mail the property file.
> >>   Also in the main code,
> >> I create an instance of the Logger class as below:
> >> static
> >> Logger logger = Logger.getLogger("MyLogger" );
> >> And also within each fuction configure the properties as:
> >> PropertyConfigurator.configure("logger.properties");
> >> Can you please help me with this problem? If this is not the right
> place
> >> to mail my doubts, can you please point me towards the right person?
> >> Waiting for your reply.
> >>
> >> Thanks and Regards
> >>
> >> --
> >> Sneha Anil Nikum
> >> Don't get even with people
> >> get AHEAD of them!
> >>
> >>
> >> DISCLAIMER:
> >> This email may contain confidential or privileged information for the
> >> intended recipient(s) and the views expressed in the same are not
> >> necessarily the views of Zensar Technologies Ltd. If you are not the
> >> intended recipient or have received this e-mail by error, its use is
> >> strictly prohibited, please delete the e-mail and notify the sender.
> Zensar
> >> Technologies Ltd. does not accept any liability for virus infected
> mails.
> >>
> >
> >
> >
> > --
> > Sneha Anil Nikum
> > Don't get even with people
> > get AHEAD of them!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
Sneha Anil Nikum
Don't get even with people
get AHEAD of them!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message