You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Robert Pepersack <rp...@mdinsurance.state.md.us> on 2004/04/28 14:50:10 UTC
How Do I Find Out If log4j Has Been Configured?
Hi all.
How can I programmatically find out if log4j has already been
configured? I configure log4j in my ejbCreate() method using
PropertyConfigurator.configure("myfile.properties"). I don't want this to
run every time my EJB container creates an instance of my bean class. I've
looked in the book, the code, and the API docs, but I can't find it.
Thanks,
Bob
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: How Do I Find Out If log4j Has Been Configured?
Posted by Robert Pepersack <rp...@mdinsurance.state.md.us>.
CVS?
Which way performs the fastest,
Logger.getRootLogger().getAllAppenders().hasMoreElements() or
Log4jConfigurator.configure()?
Thanks.
At 05:52 PM 04/28/2004 +0000, you wrote:
>Quoting Robert Pepersack <rp...@mdinsurance.state.md.us>:
>
> > Where can I get log4j 1.3? Is it in beta?
> >
>
>It isn't released as a binary yet. You can check out the latest
>CVS. There are
>ways to figure out if Log4j has been configured in 1.2.x. Try this...
>
>http://wiki.apache.org/logging-log4j/Log4JProjectPages/UsefulCode
>
>Look down the page a bit for the code. It isn't bullet proof, but may
>work for
>what you need.
>
>
>Jake
>
>
> > Thanks,
> >
> > Bob
> >
> > At 03:06 PM 04/28/2004 +0200, you wrote:
> > >At 02:50 PM 4/28/2004, you wrote:
> > >>Hi all.
> > >>
> > >>How can I programmatically find out if log4j has already been
> > >>configured? I configure log4j in my ejbCreate() method using
> > >>PropertyConfigurator.configure("myfile.properties"). I don't want this
> > >>to run every time my EJB container creates an instance of my bean
> > >>class. I've looked in the book, the code, and the API docs, but I can't
> > >>find it.
> > >
> > >In log4j 1.3, LoggerRepository has a method called isPristine. For log4j
> > >1.2.8, read pages 82 and 83 of the manual.
> > >
> > >>Thanks,
> > >>
> > >>Bob
> > >
> > >--
> > >Ceki Gülcü
> > >
> > > For log4j documentation consider "The complete log4j manual"
> > > ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp
> > >
> > >
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > >For additional commands, e-mail: log4j-user-help@logging.apache.org
> >
> > Bob Pepersack
> > 410-468-2054
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> > For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org
Bob Pepersack
410-468-2054
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: How Do I Find Out If log4j Has Been Configured?
Posted by WJCarpenter <bi...@carpenter.ORG>.
jk> http://wiki.apache.org/logging-log4j/Log4JProjectPages/UsefulCode
wjc> I'm a little confused by this cite. I presume you're talking
wjc> about the Log4jConfigurator example.
jk> Did you look at the code above the Log4jConfigurator example?
jk> Looks pretty similar to what you are doing below. BTW, if you
jk> think your example is better or otherwise useful, why not add it
jk> to the wiki?
Duh-oh! I did completely miss the sample above Log4jConfigurator.
Thanks for redirecting me. I agree it's pretty similar to what I
posted, and I don't particularly think that mine is better.
Instead, I have finally gotten around to writing a bug report about
the funky default behavior in log4j (which is my main reason for
wondering it log4j is already configured).
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=28692
--
bill@carpenter.ORG (WJCarpenter) PGP 0x91865119
38 95 1B 69 C9 C6 3D 25 73 46 32 04 69 D6 ED F3
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: How Do I Find Out If log4j Has Been Configured?
Posted by Jacob Kjome <ho...@visi.com>.
At 04:21 PM 4/28/2004 -0700, you wrote:
>jk> There are ways to figure out if Log4j has been configured in
>jk> 1.2.x. Try this...
>
>jk> http://wiki.apache.org/logging-log4j/Log4JProjectPages/UsefulCode
>
>I'm a little confused by this cite. I presume you're talking about
>the Log4jConfigurator example.
Did you look at the code above the Log4jConfigurator example? Looks
pretty similar to what you are doing below. BTW, if you think your example
is better or otherwise useful, why not add it to the wiki?
Jake
> That looks like a fairly vanilla
>example of a singleton class to keep yourself from double-dipping
>log4j. That does nothing to tell you if it's already been configured
>by somebody else, or am I misreading it?
>
>We do this around here:
>
> /**
> * log4j has a wacky default if it doesn't get any configuration help
> from the environment.
> * It turns on DEBUG at the RootLogger level. So, everything wrapped
> in isDebugEnabled will
> * be done even though it is written to nowhere. Grrr. This method
> looks for that condition.
> * If all loggers (1) have no appenders, and (2) are at DEBUG level,
> then fix things up by
> * setting the RootLogger at the ERROR level (which will cascade down).
> * @return whether or not corrective action was taken.
> */
> protected static boolean checkForCrazyLog4jDefault()
> {
> org.apache.log4j.Logger rl = org.apache.log4j.Logger.getRootLogger();
> if (!loggerIsThatCrazyWay(rl)) return false;
> Enumeration allLoggers = LogManager.getCurrentLoggers();
> while (allLoggers.hasMoreElements())
> {
> org.apache.log4j.Logger lgr =
> (org.apache.log4j.Logger)allLoggers.nextElement();
> if (! loggerIsThatCrazyWay(lgr)) return false;
> }
> // OK, I guess it *is* that crazy way... change to a different,
> slightly less crazy way
> rl.setLevel(Level.ERROR);
> return true;
> }
> private static boolean loggerIsThatCrazyWay(org.apache.log4j.Logger lgr)
> {
> Enumeration appenders = lgr.getAllAppenders();
> if (appenders.hasMoreElements()) return false;
> Level lvl = lgr.getEffectiveLevel();
> if (lvl != null)
> {
> if (! lvl.equals(Level.DEBUG)) return false;
> }
> return true;
> }
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: How Do I Find Out If log4j Has Been Configured?
Posted by WJCarpenter <bi...@carpenter.ORG>.
jk> There are ways to figure out if Log4j has been configured in
jk> 1.2.x. Try this...
jk> http://wiki.apache.org/logging-log4j/Log4JProjectPages/UsefulCode
I'm a little confused by this cite. I presume you're talking about
the Log4jConfigurator example. That looks like a fairly vanilla
example of a singleton class to keep yourself from double-dipping
log4j. That does nothing to tell you if it's already been configured
by somebody else, or am I misreading it?
We do this around here:
/**
* log4j has a wacky default if it doesn't get any configuration help from the environment.
* It turns on DEBUG at the RootLogger level. So, everything wrapped in isDebugEnabled will
* be done even though it is written to nowhere. Grrr. This method looks for that condition.
* If all loggers (1) have no appenders, and (2) are at DEBUG level, then fix things up by
* setting the RootLogger at the ERROR level (which will cascade down).
* @return whether or not corrective action was taken.
*/
protected static boolean checkForCrazyLog4jDefault()
{
org.apache.log4j.Logger rl = org.apache.log4j.Logger.getRootLogger();
if (!loggerIsThatCrazyWay(rl)) return false;
Enumeration allLoggers = LogManager.getCurrentLoggers();
while (allLoggers.hasMoreElements())
{
org.apache.log4j.Logger lgr = (org.apache.log4j.Logger)allLoggers.nextElement();
if (! loggerIsThatCrazyWay(lgr)) return false;
}
// OK, I guess it *is* that crazy way... change to a different, slightly less crazy way
rl.setLevel(Level.ERROR);
return true;
}
private static boolean loggerIsThatCrazyWay(org.apache.log4j.Logger lgr)
{
Enumeration appenders = lgr.getAllAppenders();
if (appenders.hasMoreElements()) return false;
Level lvl = lgr.getEffectiveLevel();
if (lvl != null)
{
if (! lvl.equals(Level.DEBUG)) return false;
}
return true;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: How Do I Find Out If log4j Has Been Configured?
Posted by Jacob Kjome <ho...@visi.com>.
Quoting Robert Pepersack <rp...@mdinsurance.state.md.us>:
> Where can I get log4j 1.3? Is it in beta?
>
It isn't released as a binary yet. You can check out the latest CVS. There are
ways to figure out if Log4j has been configured in 1.2.x. Try this...
http://wiki.apache.org/logging-log4j/Log4JProjectPages/UsefulCode
Look down the page a bit for the code. It isn't bullet proof, but may work for
what you need.
Jake
> Thanks,
>
> Bob
>
> At 03:06 PM 04/28/2004 +0200, you wrote:
> >At 02:50 PM 4/28/2004, you wrote:
> >>Hi all.
> >>
> >>How can I programmatically find out if log4j has already been
> >>configured? I configure log4j in my ejbCreate() method using
> >>PropertyConfigurator.configure("myfile.properties"). I don't want this
> >>to run every time my EJB container creates an instance of my bean
> >>class. I've looked in the book, the code, and the API docs, but I can't
> >>find it.
> >
> >In log4j 1.3, LoggerRepository has a method called isPristine. For log4j
> >1.2.8, read pages 82 and 83 of the manual.
> >
> >>Thanks,
> >>
> >>Bob
> >
> >--
> >Ceki Gülcü
> >
> > For log4j documentation consider "The complete log4j manual"
> > ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >For additional commands, e-mail: log4j-user-help@logging.apache.org
>
> Bob Pepersack
> 410-468-2054
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: How Do I Find Out If log4j Has Been Configured?
Posted by Robert Pepersack <rp...@mdinsurance.state.md.us>.
Where can I get log4j 1.3? Is it in beta?
Thanks,
Bob
At 03:06 PM 04/28/2004 +0200, you wrote:
>At 02:50 PM 4/28/2004, you wrote:
>>Hi all.
>>
>>How can I programmatically find out if log4j has already been
>>configured? I configure log4j in my ejbCreate() method using
>>PropertyConfigurator.configure("myfile.properties"). I don't want this
>>to run every time my EJB container creates an instance of my bean
>>class. I've looked in the book, the code, and the API docs, but I can't
>>find it.
>
>In log4j 1.3, LoggerRepository has a method called isPristine. For log4j
>1.2.8, read pages 82 and 83 of the manual.
>
>>Thanks,
>>
>>Bob
>
>--
>Ceki Gülcü
>
> For log4j documentation consider "The complete log4j manual"
> ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org
Bob Pepersack
410-468-2054
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
creating my own level
Posted by Guruprasanth <gu...@tarangtech.com>.
hi,
i want to create my own level for my application.I went to the site and
implemented
it.http://wiki.apache.org/logging-log4j/Log4JProjectPages/TraceLevel.But my
req is i need to use log4j.xml.How do i put
log4j.rootLogger=trace#com.tarangtech.eia.TraceLevel,MAIN, STDERR it in xml
file.Can someone help me.
regards
guru
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org
Re: How Do I Find Out If log4j Has Been Configured?
Posted by Ceki Gülcü <ce...@qos.ch>.
At 02:50 PM 4/28/2004, you wrote:
>Hi all.
>
>How can I programmatically find out if log4j has already been
>configured? I configure log4j in my ejbCreate() method using
>PropertyConfigurator.configure("myfile.properties"). I don't want this to
>run every time my EJB container creates an instance of my bean
>class. I've looked in the book, the code, and the API docs, but I can't
>find it.
In log4j 1.3, LoggerRepository has a method called isPristine. For log4j
1.2.8, read pages 82 and 83 of the manual.
>Thanks,
>
>Bob
--
Ceki Gülcü
For log4j documentation consider "The complete log4j manual"
ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org