Decreasing log level in Eclipse WTP with Tomcat 7 - eclipse

I am running Tomcat 7 from within Eclipse WTP (Juno) and I cannot seem to tune down the logging level. It logs everything from debug which is too verbose to be of any use (I want it log from INFO). The logging.properties file is as follows:
handlers = java.util.logging.ConsoleHandler
.handlers = java.util.logging.ConsoleHandler
.level=INFO
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

Adding both of these per the FAQ that Tom Chatt cites:
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file="${workspace_loc}/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/conf/logging.properties"
to the arguments to the server's launch configuration will get you what you want.
${workspace_loc} is literal; Eclipse will substitute it with your workspace directory.
tmp0 may be tmp1 or such instead; use the same path that's in the server's configuration.
Assumes that you've placed the logging.properties file there, of course.
That way you'll see the file in the Project Explorer window under Servers.
You should start by copying the one from the Tomcat conf directory.
This all assumes that you're intent on using JULI.
Works for me with Tomcat 8.0 and Eclipse Mars.
No idea why it didn't work for Tom.
I did see ClassNotFounds, for the obvious reason, when I used the wrong class name from someone's post.
I'd advise against the approach of Tom Chatt, since that will affect all of the other uses of that JVM.

I had this same issue, wanting to configure the logging levels of Tomcat 7 in Eclipse WTP. I tried putting a logging.properties in the /src directory of my web app. No effect. I tried modifying the logging.properties file in the /conf directory of my Tomcat installation, but no effect there either. I discovered Eclipse WTP's "shadow" Tomcat area, under my workspace directory, in .metadata/.plugins/org.eclipse.wst.server.core/tmp0, and put a logging.properties file in the /conf directory under there. No effect.
I discovered a number of articles (e.g., this FAQ at eclipse.org) noting that while Tomcat in "real life" automatically runs with a logging manager called "JULI", for some reason the Tomcat running inside Eclipse WTP does not run with JULI. I tried adding
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
to the VM args in my Tomcat run config, but that just got me ClassNotFound errors. (And yes, I did have tomcat-juli.jar in my classpath, so no idea why it wasn't finding it.)
Finally, it occurred to me to try modifying the logging.properties instance in my jdk jre/lib. Jackpot! It turns out that's the one that does have an effect on the logging done by Tomcat-in-Eclipse. So, the moral of this long tale is that if all you want to do is just simply configure the logging while you're running in Eclipse, with a simple little statement like:
myapp.mypackage.level=FINE
Then $JAVAHOME/lib/logging.properties is the place to put it.

To solve this I followed the tomcat log4j guide at http://tomcat.apache.org/tomcat-7.0-doc/logging.html. This will make tomcat use log4j.
Next set up a log4j config in $CATALINA_HOME/lib.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="null" class="org.apache.log4j.varia.NullAppender" />
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n" />
</layout>
</appender>
<category name="org.package.domain">
<priority value="INFO" />
<appender-ref ref="console" />
</category>
</log4j:configuration>

Related

Drools Eclipse Plugin ignores source level

I have installed the Drools Eclipse Plugin org.drools.eclipse 7.36.0.Final into my Eclipse 2020_03 running with a Oracle JDK 1.8.0_92. I have downloaded und unzipped drools-distribution-7.36.0.Final and added the binaries/ directory as Drools > Installed Drools Runtimes in the Eclipse Preferences.
As soon as I use any Java 1.5+ features (generics, foreach loops, closures, ...) I get error markers in the Rule Editor saying that there are syntax errors and those features require source level 1.5 (1.8 for closures).
My .drl files and the project itself seem to be fine, because I can compile and run via maven without errors. So it's not a blocking issue, but it's annoying that I cannot seem to get syntax checks for .drl files working properly in my IDE.
I have searched the internet and tried out all kinds of things:
I have set the JDT source levels in my project and workspace to 1.8
I have checked Installed JREs in the properties and only the one JDK 1.8.0_92 is listed
I have created a kmodule.xml file in /src/main/resources/META-INF/ with this content
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<configuration>
<property key="drools.dialect.java.compiler.lnglevel" value="1.8" />
<property key="drools.dialect.java.compiler" value="ECLIPSE" />
<property key="drools.compiler.lnglevel" value="1.8" />
</configuration>
<kbase name="rules">
<ksession name="codegen-rules"/>
</kbase>
</kmodule>
I have created a kie.properties.conf file in /src/main/resources/META-INF/ with this content:
drools.dialect.java.compiler.lnglevel=1.8
drools.dialect.java.compiler=ECLIPSE
drools.compiler.lnglevel=1.8
I have added the properties in the VM args section of my eclipse.ini file:
-Ddrools.dialect.java.compiler.lnglevel=1.8
-Ddrools.dialect.java.compiler=ECLIPSE
-Ddrools.compiler.lnglevel=1.8
But all of these do not seem to have any effect and it keeps giving me the same error markers.
How can I tell the Rule Editor that I want to enable Java 1.8 source level when syntax checking my .drl files?
I have run into this issue as well using the latest eclipse release and the latest drools release.
Using Eclipse 2019-03 and the Jboss Tools Integration Stack here does work. So either something broke in later eclipse releases or in the later drools versions. The integration stack uses 7.21.0.Final
I have not dug into what exactly broke but even if I did I don't know who I would report it to :(

Eclipse + Tomcat 8 - application double deployment

I'm developing for Tomcat 8 under Eclipse Mars.
This is my application context in published server.xml:
<Context docBase="C:\automation\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\webapps\ROOT" path="" reloadable="false"/>
<Context docBase="AutomationWeb" path="/automation" reloadable="true" source="org.eclipse.jst.jee.server:AutomationWeb"/>
No other contexts defined there. But when I open tomcat manager app I see 2 contexts for my application:
One with "/AutomationWeb" path,
other with "/automation" path
My app has no context.xml
What I've discovered:
They share display name from my application's web.xml
My application can run on both paths.
The one with /AutomationWeb path is not actually reloadable
If I remove my application(Web Module) from Tomcat server in Eclipse, both entries disappear from tomcat manager app.
Deleting server in Eclipse and deleting contents of \workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\ didn't help.
How can I remove undesired application context with /AutomationWeb path? What configs should i check?
Solved it by changing publish directory from webapps to webappsauto. It seems the problem was in server.xml because of this statement:
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

Eclipse Luna - Getting error - 'Could not publish server configuration for Tomcat v7.0 Server at localhost. Multiple Contexts have a path of "/abc"

I am using Eclipse Luna and getting
Could not publish server configuration for Tomcat v7.0 Server at localhost.
Multiple Contexts have a path of /TestProject.
However I can fix this by making path for docbase = / in context string in server.xml as in context docBase="abc" path="/" reloadable="true" source="org.eclipse.jst.jee.server:abc"/> docBase="xyz" path="/TestProject" reloadable="true" source="org.eclipse.jst.jee.server:xyz"/>
So I wanted to know what role does attribute 'path' play in context and how do I fix it permanently. I have seen the path get carried over when I copy a application to another application.
Go to [workspace folder]->Servers->[Tomcat folder] then open server.xml file and search for <Context> tag. There will be multiple <Context> tags, remove the duplicates. Restart your server. Hope this helps.
This is related to the server.xml file. I had the same problem, and I just switched to a new workspace and now it works!
In your eclipse tomcat, open server.xml and search "/abc", you will get this line, please keep only one and remove duplicate lines
<Context docBase="abc" path="/abc" reloadable="true" source="org.eclipse.jst.jee.server:abc"/>
Go to [workspace folder]->Servers->[Tomcat folder] then open server.xmlfile and search for the <Context> tag. There will be multiple <Context> tags, remove the duplicates, something like this:
<Context docBase="service-name" path="/path of your service" reloadable="true"
source="org.eclipse.jst.jee.server:your-service-name" />
<Context ................... />
so remove this second <Context> tag.

What should I do with custom Log4j appender dependancies

I've written a custom log4j appender that creates a new Solr document for each log entry and I'm having problems deploying it to JBoss.
The source is viewable on github but the real problem is trying to use the appender from JBoss.
The relevent bits of jboss-log4j.xml look like this:
<appender name="SOLR" class="com.stuartgrimshaw.solrIndexAppender.SolrIndexAppender" />
<root>
<priority value="${jboss.server.log.threshold}"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
<appender-ref ref="SOLR"/>
</root>
The dependencies for Solr are all available in the .war file that's supplied, but I'm guessing that when the appender is initialised quite early on in the boot process, that application hasn't been deployed yet, which is why I see this error in the log:
2009-11-29 10:40:57,715 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] (main) Error installing to Create: name=jboss.system:service=Logging,type=Log4jService state=Configured mode=Manual requiredState=Create
java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/SolrServerException
Is there any way I can delay the initialization till the solr app has been deployed, or is there a way to deploy the Solr app so it's libraries are visible to jboss while it boots?
I think you could either deploy the Solr libs in server/[jboss-configuration]/lib (in JBoss 4 that is, might be the same in newer versions), then they are available at boot time.
Or don't use the JBoss log4j configuration and define your own log4j.xml in your WAR (either in a JAR in lib or in classes). It will be loaded by the application classloader when it is deployed.
As you've discovered, you'd have to put your JAR into the JBoss config's lib directory in order to refer to its types in jboss-log4j.xml, but this is generally not good practise.
A pretty straightward alternative is to invoke the log4j API programmatically from inside your application. If you have a WAR, then define a ServetContextListener (or something similar) which is invoked when the WAR deploys, and which attaches your appender. Similarly, when undeployed, it detaches the appender.
See the answer to this previous question for how to get started doing this.
I am guessing that this is to manage your log files and make them easier to search, a la Splunk???? However, this feels like a fairly odd way of doing this.. kind of the "look, I can make a dog walk on it's hind legs" kind of thing... Cool, but why would you want to?
I think a much simpler, more robust approach is to a) grab Splunk Free Edition! b) have a seperate process that consumes your log files from disk and send them to Solr using Solr4J.
I think requiring Solr, just to do logging adds a huge level of complexity.

What is the "source" attribute of the Context element of an Apache Tomcat configuration file for?

It's somehow related to Eclipse. For example:
<Host>
<Context docBase="foo" path="/foo" reloadable="true"
source="org.eclipse.jst.j2ee.server:foo" />
</Host>
Eclipse WTP adds the source attribute to the project-related <Context> element to identify the location of the source code associated with the context (thus, the actual project in the workspace which has been deployed to this server from inside Eclipse).
If you wondered about this due to a warning during Tomcat's startup, since Tomcat 6.0.16 any "unrecognized" XML tags and attributes in the context.xml or server.xml will produce a warning about it during the startup, although there's actually no means of a DTD.
Just ignore it. Tomcat shall work fine and Eclipse is happy with it. It won't occur in real production environment with a worthfully WAR file.