getting tomcat to log webapp name in logging statements - java

Using tomcat's JULI logging (extension of jdk logging), is it possible to get log statements to include the context path of the webapp (for example /myapp). I have the same webapp deployed a few times with different configuration parameters in the web.xml. It would be very helpful to understand which webapp was spitting out which log statements.
Currently, the log output looks like:
Feb 22, 2012 9:37:57 AM org.mypackage.MyClass init
INFO: Model has been initialized
Feb 22, 2012 9:37:57 AM org.mypackage.MyClass init
INFO: after loading model: 1329921477445
I'd like to be able to include the context path of the webapp (or webapp name) before the class name. Something along these lines:
Feb 22, 2012 9:37:57 AM /mywebapp org.mypackage.MyClass init
INFO: Model has been initialized
Feb 22, 2012 9:37:57 AM /mywebapp org.mypackage.MyClass init
INFO: after loading model: 1329921477445
Thanks,
Matt

Use SLF4J and Logback in your webapps. Do not rely on Java Logging (JULI).

Related

Create an agent in JADE

I'm having trouble creating an agent with JADE.
My structure
/
Applications
jade
lib
jade.jar
jadeExamples.jar
src
examples
hello
HelloWorldAgent.class
HelloWorldAgent.java
My file HelloWorldAgent.java
package examples.hello;
import jade.core.Agent;
public class HelloWorldAgent extends Agent {
protected void setup() {
System.out.println("Hello! My name is "+getLocalName());
}
}
The steps I follow to create an agent :
/Applications/jade/src/examples/hello $ javac *.java
/Applications/jade/src/examples/hello $ java jade.Boot -gui -agents fred:examples.hello.HelloWorldAgent
Myclasspath
/Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home:/Applications/jade/lib/jade.jar:/Applications/jade/lib/jadeExamples.jar:/Applications/jade/src/
The output
Sep 21, 2019 5:28:05 PM jade.core.Runtime beginContainer
INFO: ----------------------------------
This is JADE 4.5.0 - revision 6825 of 23-05-2017 10:06:04
downloaded in Open Source, under LGPL restrictions,
at http://jade.tilab.com/
----------------------------------------
Sep 21, 2019 5:28:05 PM jade.imtp.leap.LEAPIMTPManager initialize
INFO: Listening for intra-platform commands on address:
- jicp://192.168.1.104:1099
Sep 21, 2019 5:28:06 PM jade.core.BaseService init
INFO: Service jade.core.management.AgentManagement initialized
Sep 21, 2019 5:28:06 PM jade.core.BaseService init
INFO: Service jade.core.messaging.Messaging initialized
Sep 21, 2019 5:28:06 PM jade.core.BaseService init
INFO: Service jade.core.resource.ResourceManagement initialized
Sep 21, 2019 5:28:06 PM jade.core.BaseService init
INFO: Service jade.core.mobility.AgentMobility initialized
Sep 21, 2019 5:28:06 PM jade.core.BaseService init
INFO: Service jade.core.event.Notification initialized
Sep 21, 2019 5:28:11 PM jade.mtp.http.HTTPServer <init>
INFO: HTTP-MTP Using XML parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
Sep 21, 2019 5:28:11 PM jade.core.messaging.MessagingService boot
INFO: MTP addresses:
http://192.168.1.104:7778/acc
Hello World! My name is fred
Sep 21, 2019 5:28:11 PM jade.core.AgentContainerImpl joinPlatform
INFO: --------------------------------------
Agent container Main-Container#192.168.1.104 is ready.
--------------------------------------------
My problem
If I change the message in the HelloWorldAgent (e.g. System.out.println("Hello ! My name is "+getLocalName());), it doesn't update when I run my agent (the console says Hello World! My name is fred). And when I create a new class in the hello folder, I can't find my agent in the GUI.
What have I missed?
You have not set the classpath correctly. As mentioned in the accepted answer to 'What is a classpath and how do I set it?', your classpath can contain two entry types:
So, classpaths contain:
JAR files, and
Paths to the top of package hierarchies.
In your case you have reference ONLY the following .jar files :
/Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home
/Applications/jade/lib/jade.jar
/Applications/jade/lib/jadeExamples.jar
Notice that your working path /Applications/jade/src/examples/hello/ is not in the classpath. This means that your custom jade classes are not visible/accessable.
To solve your problem you have to add the additional paths you want to use in your classpaths. Usually you use the directory . to indicate that you want the "current directory" in your classpath.
Keep in mind that you have the JAR file jadeExamples.jar in your classpath. When you have a .class file for your changed HelloWorldAgent class it might not be clear which class the JVM is loading, the one from the JAR file or the .class file from the file system. Do not provide the same class with the same package in your classpath twice or even change the jadeExamples.jar file with a new changed JAR file (this might be even more confusing). Instead, create a new agent in YOUR package/namespace/directory and load it -agents foobar:your.package.and.ClassName, but ensure that the classpath is set correctly .

Figuring out Spring Logging

I've inherited a, well, messy, Spring MVC application. Some things don't work and I want to enable DEBUG or even TRACE logging to get more information and found that even that is not that simple.
When starting the application (by running a Tomcat 8 server from Eclipse), it seems to output two kinds of log messages. Here is an example of the first kind:
Jun 20, 2017 1:47:07 PM org.hibernate.Version logVersion INFO:
HHH000412: Hibernate Core {4.3.8.Final} Jun 20, 2017 1:47:07 PM
org.hibernate.cfg.Environment <clinit> INFO: HHH000206:
hibernate.properties not found Jun 20, 2017 1:47:07 PM
org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021:
Bytecode provider name : javassist
These messages are all in red. The second kind looks like this:
13:47:16.949 [localhost-startStop-1] INFO org.springframework.web.servlet.DispatcherServlet:489 - FrameworkServlet 'spring': initialization started
13:47:16.952 [localhost-startStop-1] INFO org.springframework.web.context.support.XmlWebApplicationContext:583 - Refreshing WebApplicationContext for namespace 'spring-servlet': startup date [Tue Jun 20 13:47:16 IDT 2017]; parent: Root WebApplicationContext
13:47:16.952 [localhost-startStop-1] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader:317 - Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
These are all in black.
Obviously there are at least two active logging formats. This is were it gets weird:
I found numerous log4j2.xml as well as log4j.propertiesfiles. All of them seem to be ignored. Changing them makes no difference. I just deleted them all, and it did not affect the logging output. In addition, log4j 1.2, log4j 2.0.2 and slf4j are all Maven dependencies. pom.xml references version 1.2, other Maven dependencies probably need the other versions.
My question is - how do I configure the logging myself? Placing a log4j.xml file under WEB-INF (were all other property files are located) doesn't make any difference. Neither that placing a log4j.properties file there. I need to somehow turn debug printouts of log4j itself, so I can figure out where it's reading it's configuration from.
I tried adding -Dlog4j.debug as a VM argument to the Tomcat run configuarion. Other than printing -Dlog4j.debug command line argument or something similar, nothing changed.
You can use following code snippet that I have used for my project. Over here class name is FolderReader.class and placed lo4j.properties file in folder "conf".Passing argument "../conf/log4j.properties" as args[2] argument when running the application.
final FileSystemXmlApplicationContext applicationContext = new FileSystemXmlApplicationContext(args[0]);
Logger logger=Logger.getLogger(FolderReader.class);
PropertyConfigurator.configure(args[2]);
logger.info("Intializing beans..");
ServiceContext serviceContext = (ServiceContext) BeanFactoryLocator.getBean("serviceContext");
PropertyConfigurator.configure(args[2]);loads the log4j.properties file from location. Configuration is taken from this property file and formatting is done accordingly.

Tomcat JAASRealm : Getting "Class not added" after starting server

I am using http://blog.frankel.ch/custom-loginmodule-in-tomcat tutorial for tomcat JAASRealm.I have added below in server.xml
Realm className="org.apache.catalina.realm.JAASRealm" appName="CustomLogin"
userClassNames="ch.frankel.blog.loginmodule.PlainUserPrincipal"
roleClassNames="ch.frankel.blog.loginmodule.PlainRolePrincipal"
/>
while starting server i am getting
INFO: Starting Servlet Engine: Apache Tomcat/5.5.27
Jun 8, 2012 1:18:24 PM org.apache.catalina.realm.JAASRealm parseClassNames
SEVERE: Class ch.frankel.blog.loginmodule.PlainUserPrincipal not found! Class no
t added.
Jun 8, 2012 1:18:24 PM org.apache.catalina.realm.JAASRealm parseClassNames
SEVERE: Class ch.frankel.blog.loginmodule.PlainRolePrincipal not found! Class no
t added.
Jun 8, 2012 1:18:24 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Jun 8, 2012 1:18:24 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive CustomLogin.war
I am using tomcat 5.5.27. When i call my servlet authentication is working fine but authorization is having some issue and might be due to "Class not added."
Please help....
It got resolved...I added a jar containing above classes in /server/lib folder and its working fine.

NoClassDefFoundError in Jade Agents?

I created two agents and it runs well. but when I add Ontology class and registered the ontology I can't create the agents... I got following errors..
Jun 1, 2012 8:56:55 AM jade.core.BaseService init
INFO: Service jade.core.management.AgentManagement initialized
Jun 1, 2012 8:56:55 AM jade.core.BaseService init
INFO: Service jade.core.messaging.Messaging initialized
Jun 1, 2012 8:56:55 AM jade.core.BaseService init
INFO: Service jade.core.mobility.AgentMobility initialized
Jun 1, 2012 8:56:55 AM jade.core.BaseService init
INFO: Service jade.core.event.Notification initialized
Jun 1, 2012 8:56:55 AM jade.core.messaging.MessagingService clearCachedSlice
INFO: Clearing cache
Jun 1, 2012 8:56:55 AM jade.mtp.http.HTTPServer <init>
INFO: HTTP-MTP Using XML parser com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser
Jun 1, 2012 8:56:55 AM jade.core.messaging.MessagingService boot
INFO: MTP addresses:
http://169.254.108.164:7778/acc
Jun 1, 2012 8:56:55 AM jade.core.AgentContainerImpl startBootstrapAgents
SEVERE: Cannot create agent STMAgent: An undeclared exception was thrown [nested java.lang.ExceptionInInitializerError]
Jun 1, 2012 8:56:55 AM jade.core.AgentContainerImpl startBootstrapAgents
SEVERE: Cannot create agent REquestAgent: An undeclared exception was thrown [nested java.lang.NoClassDefFoundError: Could not initialize class FruitOntology.FruitOntology]
Jun 1, 2012 8:56:55 AM jade.core.AgentContainerImpl joinPlatform
class paths are correct. Ontology class paths are also correct.. What is the reason for this? Plz help me............
I found error.. it is on my ontology class..
Thank you..
The crucial error message seems to be:
SEVERE: Cannot create agent REquestAgent: An undeclared exception was thrown
[nested java.lang.NoClassDefFoundError:
Could not initialize class FruitOntology.FruitOntology]
Your code is not finding class FruitOntology in the package FruitOntology (which isn't a very good package name - normally, a package name would start with a lower-case letter, and would normally follow the convention of reversing the domain name of the organization).
As you haven't shown any of your code, we can only guess why that error arises. Have you perhaps mis-spelled the name in a configuration file somewhere? Do a grep through your project to see where FruitOntology.FruitOntology occurs. It probably isn't in normal Java code, as you would get a compilation error for missing classes, unless you're using Java Reflection for some reason.

trying to start a tomcat from eclipse and it failed to find index.jsp

type Status report
message /mydirectory/index.jsp
description The requested resource (/mydirectory/index.jsp) is not available.
What could be the issue?
Here is the log file:
Jul 28, 2009 6:16:25 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Testing' did not find a matching property.
Jul 28, 2009 6:16:25 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\Intel\DMIX;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\10.0\DLLShared\;c:\Program Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\SlikSvn\bin\;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\Sun\SDK\bin
Jul 28, 2009 6:16:25 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Jul 28, 2009 6:16:25 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 447 ms
Jul 28, 2009 6:16:25 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Jul 28, 2009 6:16:25 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
If you're using Eclipse 3.4 or 3.5 -- look at the Servers view in Eclipse. Against your server, you should see "Started" and "Synchronized". If it tells you to restart or republish, right-click on your server and do so.
Deploy your file again (you can drag your index.jsp file on to the server). Does it start this time?
If not, something could be wrong with your web.xml. Open the Console view and look at the server log -- do you notice any exceptions etc? You will need to resolve those.
First of all, check your server plug-in configuration:
When Tomcat within Eclipse publishes you Dynamic Web Project, all embedded tomcat useful files (conf, code, work) are stored in this following location:
<path_to_workspace>\.metadata\.plugins\org.eclipse.wst.server.core\tmp[0-9]
Check the deployment architecture, if you need more help regarding tomcat files architecture, see tomcat documentation

Categories

Resources