blob: afb245f559bfae484e52cf3818fdc04c1c5d8404 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<!-- $PAGETITLE -->
<TITLE>OpenEJB - Configuring Logging in Tests</TITLE>
<LINK href="http://openejb.apache.org/all.css" rel="stylesheet" type="text/css">
<!--[if IE]><link rel="stylesheet" type="text/css" media="screen, projection" href="openejb.apache.org/ie.css"><![endif]-->
<LINK rel="SHORTCUT ICON" href="http://openejb.apache.org/images/favicon.ico">
<META http-equiv="Content-Type" content="text/html;charset=UTF-8">
</HEAD>
<BODY>
<!-- Delay the loading of the external javascript file needed for labels (as it takes too long to load and visibly holds loading of the page body) -->
<!-- To do this without javascript errors over undefined functions, we need to declare stubs here (that are overrided later by the proper implementations) -->
<SCRIPT language="JavaScript" type="text/javascript">
function doAddLabel(hideTextfieldAfterAddParam)
{
// stub
}
function onAddLabel()
{
// stub
}
function showLabelsInput()
{
// stub
}
</SCRIPT>
<A name="top"></A>
<TABLE class="frameTable" cellpadding="0" cellspacing="0" border="0">
<TR class="Row1">
<TD class="Col1"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col2"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col3"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
</TR>
<TR class="Row2">
<TD class="Col1"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3" id="breadcrumbs">
<!-- $TOP_NAV_BAR -->
<A href="../OPENEJB/index.html" title="Index">Home</A> | <A href="../OPENEJB/download.html" title="Download">Download</A> | <A href="../OPENEJB/mailing-lists.html" title="Mailing Lists">Lists</A> | <A href="http://issues.apache.org/jira/browse/OPENEJB" class="external-link" rel="nofollow">Issues</A>
</TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">&nbsp;</TD>
</TR>
<TR class="Row3">
<TD class="Col1"><IMG alt="" class="Row3Img" id="thinLine" src="http://openejb.apache.org/images/line_sm.gif"></TD>
<TD class="Col2"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col3"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col4"><IMG alt="" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5"><IMG alt="" class="Row3Img" src="http://openejb.apache.org/images/dotTrans.gif"></TD>
</TR>
<TR class="Row4">
<TD class="Col1">
<SPAN id="Navigation">
<H3><A name="Navigation-Overview"></A>Overview</H3>
<UL class="alternate" type="square">
<LI><A href="../OPENEJB/index.html" title="Index">Home</A></LI>
<LI><A href="../OPENEJB/news.html" title="News">News</A></LI>
<LI><A href="../OPENEJB/faq.html" title="FAQ">FAQ</A></LI>
<LI><A href="../OPENEJB/download.html" title="Download">Download</A></LI>
<LI><A href="index.html" title="Index">Documentation</A></LI>
<LI><A href="../OPENEJB/examples.html" title="Examples">Examples</A></LI>
<LI><A href="http://cwiki.apache.org/confluence/display/OPENEJB/Lightening%20Demos" class="external-link" rel="nofollow">Lightning Demos</A></LI>
<LI><A href="../OPENEJB/mailing-lists.html" title="Mailing Lists">Mailing Lists</A></LI>
<LI><A href="../OPENEJB/source-code.html" title="Source Code">Source Code</A></LI>
<LI><A href="http://blogs.apache.org/openejb" class="external-link" rel="nofollow">Project Blog</A></LI>
</UL>
<H3><A name="Navigation-Servers"></A>Servers</H3>
<UL class="alternate" type="square">
<LI><A href="../OPENEJB/local-server.html" title="Local Server">Local</A></LI>
<LI><A href="../OPENEJB/remote-server.html" title="Remote Server">Remote</A></LI>
</UL>
<H3><A name="Navigation-Integrations"></A>Integrations</H3>
<UL class="alternate" type="square">
<LI><A href="tomcat.html" title="Tomcat">Tomcat</A></LI>
<LI><A href="../OPENEJB/geronimo.html" title="Geronimo">Geronimo</A></LI>
<LI><A href="../OPENEJB/webobjects.html" title="WebObjects">WebObjects</A></LI>
</UL>
<H3><A name="Navigation-Community"></A>Community</H3>
<UL class="alternate" type="square">
<LI><A href="../OPENEJB/team.html" title="Team">Team</A></LI>
<LI><A href="../OPENEJB/articles.html" title="Articles">Articles</A></LI>
<LI><A href="http://webchat.freenode.net/?channels=openejb" class="external-link" rel="nofollow">IRC</A></LI>
</UL>
<H3><A name="Navigation-RelatedProjects"></A>Related Projects</H3>
<UL class="alternate" type="square">
<LI><A href="http://activemq.apache.org/" class="external-link" rel="nofollow">ActiveMQ</A></LI>
<LI><A href="http://openjpa.apache.org/" class="external-link" rel="nofollow">OpenJPA</A></LI>
<LI><A href="http://cxf.apache.org/" class="external-link" rel="nofollow">CXF</A></LI>
</UL>
<H3><A name="Navigation-Index"></A>Index</H3>
<UL class="alternate" type="square">
<LI><A href="../OPENEJB/space-index.html" title="Space Index">Site Index</A></LI>
<LI><A href="space-index.html" title="Space Index">Doc Index</A></LI>
</UL>
<H3>
<A name="Navigation-Feeds"></A>
Feeds
</H3>
<UL class="feeds">
<LI>
<A href="http://cwiki.apache.org/confluence/spaces/rss.action?key=OPENEJB&newPages=false">
<IMG src="http://openejb.apache.org/images/rss.gif"></A>
<A class="feedsText" href="http://cwiki.apache.org/confluence/spaces/rss.action?key=OPENEJB&newPages=false">Site</A>
</LI>
<LI><A href="http://cwiki.apache.org/confluence/spaces/blogrss.action?key=OPENEJB">
<IMG src="http://openejb.apache.org/images/rss.gif"></A>
<A class="feedsText" href="http://cwiki.apache.org/confluence/spaces/blogrss.action?key=OPENEJB">News</A>
</LI>
</UL>
</SPAN>
</TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3">
<TABLE id="PageHeader" border="0" width="100%">
<TR>
<TD>
<A href="http://openejb.org/">
<IMG hspace="0" src="http://openejb.apache.org/images/logo_openejb.gif" vspace="0">
</A>
</TD>
<TD align="right">
<A href="http://www.apache.org/">
<IMG src="http://www.apache.org/images/asf-logo.gif" width="258" height="66">
</A>
</TD>
</TR>
<TR>
<TD id="page_title">
<!-- $TITLE -->
Configuring Logging in Tests
</TD>
<TD align="right">
<BR><BR>
<!-- Google CSE Search Box Begins -->
<FORM id="searchbox_010475492895890475512:_t4iqjrgx90" action="http://www.google.com/cse">
<INPUT type="hidden" name="cx" value="010475492895890475512:_t4iqjrgx90">
<INPUT type="hidden" name="cof" value="FORID:0">
<INPUT name="q" type="text" size="25">
<INPUT type="submit" name="sa" value="Search">
</FORM>
<SCRIPT type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_010475492895890475512:_t4iqjrgx90"></SCRIPT>
<!-- Google CSE Search Box Ends -->
</TD>
</TR>
</TABLE>
<P>
<!-- $BODY -->
<DIV id="PageContent">
<H1><A name="ConfiguringLogginginTests-embedded.logging.properties"></A>embedded.logging.properties</H1>
<P>When in embedded mode OpenEJB uses an embedded.logging.properties file packed in our openejb-core jar which use to configure the logging. This logging configuration is a bit lighter than the conf/logging.properties file created in a full standalone OpenEJB setup.</P>
<P>When searching for any config file in the classpath, multiple files with the same name may exist. OpenEJB will always attempt to favor the one closest to the openejb.base variable. This variable is set by default to the current directory where your vm is executing, which is more than likely the directory of your current module. So simply adding a file named embedded.logging.properties to your module may be all that you need to specify a new logging configuration for your tests.</P>
<P>Alternatively, you can set &quot;openejb.logger.external&quot; to &quot;true&quot; as a system property (will not work as an InitialContext property). Then OpenEJB will not attempt to configure logging at all and you can configure logging with Log4j directly using any of its APIs; xml, properties, or code.</P>
<P>There are a couple good reasons for <B>not</B> replacing the embedded.logging.properties file.</P>
<OL>
<LI>If you want to just change 5% of the logging settings, why take control over the other 95% as well.</LI>
<LI>We do occasionally add new logging categories. If you are not replacing the embedded.logging.properties you will pick these up automatically when you upgrade.</LI>
</OL>
<H1><A name="ConfiguringLogginginTests-Overriding%28recommended%29"></A>Overriding (recommended)</H1>
<P>As mentioned in <A href="embedded-configuration.html" title="Embedded Configuration">Embedded Configuration</A> much can be done with simple overriding. The default embedded.logging.properties is quite good and there is really no need to replace it completely if all you want to do is tweak a few values. </P>
<P>You can also put logging tweaks right in your InitialContext properties like so:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
Properties p = <SPAN class="code-keyword">new</SPAN> Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, <SPAN class="code-quote">&quot;org.apache.openejb.client.LocalInitialContextFactory&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.rootLogger&quot;</SPAN>, <SPAN class="code-quote">&quot;fatal,C&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.category.OpenEJB&quot;</SPAN>, <SPAN class="code-quote">&quot;warn&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.category.OpenEJB.options&quot;</SPAN>, <SPAN class="code-quote">&quot;info&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.category.OpenEJB.server&quot;</SPAN>, <SPAN class="code-quote">&quot;info&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.category.OpenEJB.startup&quot;</SPAN>, <SPAN class="code-quote">&quot;info&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.category.OpenEJB.startup.service&quot;</SPAN>, <SPAN class="code-quote">&quot;warn&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.category.OpenEJB.startup.config&quot;</SPAN>, <SPAN class="code-quote">&quot;info&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.category.OpenEJB.hsql&quot;</SPAN>, <SPAN class="code-quote">&quot;info&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.category.CORBA-Adapter&quot;</SPAN>, <SPAN class="code-quote">&quot;info&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.category.Transaction&quot;</SPAN>, <SPAN class="code-quote">&quot;warn&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.category.org.apache.activemq&quot;</SPAN>, <SPAN class="code-quote">&quot;error&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.category.org.apache.geronimo&quot;</SPAN>, <SPAN class="code-quote">&quot;error&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.category.openjpa&quot;</SPAN>, <SPAN class="code-quote">&quot;error&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.appender.C&quot;</SPAN>, <SPAN class="code-quote">&quot;org.apache.log4j.ConsoleAppender&quot;</SPAN>);
p.put(<SPAN class="code-quote">&quot;log4j.appender.C.layout&quot;</SPAN>, <SPAN class="code-quote">&quot;org.apache.log4j.SimpleLayout&quot;</SPAN>);
Context context = <SPAN class="code-keyword">new</SPAN> InitialContext(p);
</PRE>
</DIV></DIV>
<P>Essentially, everything starting with &quot;log4j.&quot; gets applied as overrides on top of the embedded.logging.properties we find in the classpath. This makes it possible to easily tweak the log levels while debugging a particular test.</P>
<P>Note, that InitialContext properties can also be supplied in a jndi.properties file in the classpath or via system properties. The overriding order is as follows: 1 = highest, 4 = lowest.</P>
<OL>
<LI>InitialContext properties</LI>
<LI>jndi.properties in classpath</LI>
<LI>system propertes</LI>
<LI>embedded.logging.properties in classpath</LI>
</OL>
<P>By default there are no logging settings in 1-3, so #4 is the only source of logging information.</P>
<H1><A name="ConfiguringLogginginTests-Defaultembedded.logging.propertiescontents"></A>Default embedded.logging.properties contents</H1>
<P>For your purposes, here are the contents of the default embedded.logging.properties file contained in OpenEJB 3.1.1</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">
log4j.rootLogger = fatal,C
log4j.category.OpenEJB = warn
log4j.category.OpenEJB.server = info
log4j.category.OpenEJB.startup = info
log4j.category.OpenEJB.startup.service = warn
log4j.category.OpenEJB.startup.config = info
log4j.category.OpenEJB.hsql = info
log4j.category.CORBA-Adapter = info
log4j.category.Transaction = warn
log4j.category.org.apache.activemq = error
log4j.category.org.apache.geronimo = error
log4j.category.openjpa = error
log4j.appender.C = org.apache.log4j.ConsoleAppender
log4j.appender.C.layout = org.apache.log4j.SimpleLayout
</PRE>
</DIV></DIV>
<P>Here is that file's location in svn as well as all of the previous versions. Future versions will follow the same pattern.</P>
<UL class="alternate" type="square">
<LI><A href="http://svn.apache.org/repos/asf/openejb/tags/openejb-3.1.1/container/openejb-core/src/main/resources/embedded.logging.properties" class="external-link" rel="nofollow">http://svn.apache.org/repos/asf/openejb/tags/openejb-3.1.1/container/openejb-core/src/main/resources/embedded.logging.properties</A></LI>
<LI><A href="http://svn.apache.org/repos/asf/openejb/tags/openejb-3.1/container/openejb-core/src/main/resources/embedded.logging.properties" class="external-link" rel="nofollow">http://svn.apache.org/repos/asf/openejb/tags/openejb-3.1/container/openejb-core/src/main/resources/embedded.logging.properties</A></LI>
<LI><A href="http://svn.apache.org/repos/asf/openejb/tags/openejb-3.0/container/openejb-core/src/main/resources/embedded.logging.properties" class="external-link" rel="nofollow">http://svn.apache.org/repos/asf/openejb/tags/openejb-3.0/container/openejb-core/src/main/resources/embedded.logging.properties</A></LI>
<LI><A href="http://svn.apache.org/repos/asf/openejb/tags/openejb-3.0-beta-2/container/openejb-core/src/main/resources/embedded.logging.properties" class="external-link" rel="nofollow">http://svn.apache.org/repos/asf/openejb/tags/openejb-3.0-beta-2/container/openejb-core/src/main/resources/embedded.logging.properties</A></LI>
<LI><A href="http://svn.apache.org/repos/asf/openejb/tags/openejb-3.0-beta-1/container/openejb-core/src/main/resources/embedded.logging.properties" class="external-link" rel="nofollow">http://svn.apache.org/repos/asf/openejb/tags/openejb-3.0-beta-1/container/openejb-core/src/main/resources/embedded.logging.properties</A></LI>
</UL>
</DIV>
</P>
</TD>
<TD class="Col4"><IMG src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">
</TD>
</TR>
<TR class="Row5">
<TD class="Col1">&nbsp;</TD>
<TD class="Col2">&nbsp;</TD>
<TD class="Col3">
<BR>
<BR>
<IMG width="100%" height="1" src="http://openejb.apache.org/images/line_light.gif">
<TABLE width="100%">
<TR>
<TD>
<SPAN class="bodyGrey">
<SMALL>
<NOTICE><!-- $FOOTER -->
Apache OpenEJB is an project of The Apache Software Foundation (ASF)
</NOTICE>
<BR>
Site Powered by
<A href="http://atlassian.com/">Atlassian</A>
<A href="http://atlassian.com/confluence/">Confluence</A>
.
</SMALL>
</SPAN>
</TD>
<TD align="right">
<A style="color:#999;font-size:small;font-weight:normal;" href="https://cwiki.apache.org/confluence/pages/editpage.action?spaceKey=OPENEJBx30&title=Configuring%20Logging%20in%20Tests">[ edit ]</A>
</TD>
</TR>
</TABLE>
<BR>
</TD>
<TD class="Col4"><IMG src="http://openejb.apache.org/images/dotTrans.gif"></TD>
<TD class="Col5">&nbsp;</TD>
</TR>
</TABLE>
<!-- Needed for composition plugin -->
<!-- delay the loading of large javascript files to the end so that they don't interfere with the loading of page content -->
<SPAN style="display: none">
<SCRIPT type="text/javascript" language="JavaScript" src="http://cwiki.apache.org/confluence/labels-javascript"></SCRIPT>
<SCRIPT src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</SCRIPT>
<SCRIPT type="text/javascript">
_uacct = "UA-2717626-1";
urchinTracker();
</SCRIPT>
</SPAN>
</BODY>
</HTML>