No log statement is printing using websphere 8.0 - java

I have one application running in WAS8.
we have a jar - commons-logging-1.1.1.jar in WEB-INF/lib
we have one properties file - commons-logging.properties
the content of the file is
priority=1
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
we have org.apache.commons.logging.LogFactory file in WebContent/META-INF/services
the content of the file is
org.apache.commons.logging.impl.Log4jFactory
The log files are created but nothing is written in it. It is not showing any error in the log files in log of appserver.
Please let me know if I am missing something.
Please note: if I keep commons-logging.properties in /opt/IBM/WebSphere/80/AppServer/profiles/AppSrv01/properties, then it works perfectly fine. It is writing in the log files. But as I heard it is not standard practice so I can't keep the file in that place. I have to find some alternative way.
Please help me.

If it is not a requirement to have separate log files for your web application, you can simply remove the commons-log jar and properties from your module (war) and your log statements will write to SystemOut.log according to the log level settings in the WebSphere console (which can be changed at runtime, by the way).
If you must separate application logging, you can refer to this infocenter article that lays out the combination of commons-log jar location, commons-log properties values, and application classloader settings (Parent-First, Parent-Last, commons-log.jar bundled or not, etc) to achieve the desired results.

Related

How to read log4j properties file out of classpath

I am facing a task to put log4j.properties configuration file to the JBoss server instead of putting this configuration to the project as stated in official JBoss documentation here: https://developer.jboss.org/thread/231514
If I got this right, log4j logger finds configuration within classpath automatically, but what is the way (if there is any) of loading this file from server directory (e.g. wildfly/modules/x/y/log4j.properties)?
You can use -Dlog4j.configuration=file:[path-to-your-external-file] while starting the server.
This is the answer I was looking for.

Deploying Spring Application on Tomcat 8.5.9 returns 404 1034 error in localhost access log

New poster here so I'll dive right in. Sorry if I miss any important information, let me know and I'll update you.
My problem is that when I go to my application: localhost:8080/GettingStartedSpringMVC/ - I get a 404 error on the screen and a 404 1034 error on the logs but that is it, no other useful information in any log I can find.
I am creating a basic Spring MVC Web application in Java. I am following the "Spring in Action" vol. 4. I have identical code including the test case, which returns success. When I go to "Export > WAR file" and put it into my local Apache instance the WAR file successfully explodes. I am able to access localhost:8080, localhost:8080/test/index.html, and even localhost:8080/GettingStartedSpringMVC/helloworld.html which are .html files I created to make sure deployment was going normally - the last one is inside the project that I cannot access. I have the logs in my apache tomcat instance but there doesn't appear to be anything useful in them - unless I don't know where to look.
If I could find an error, I would be happy to look into it but I can't manage to find anything. Not sure how to post files either - just copy/paste? If anything is needed, I'll add it.
Did you check Catalina.out and other server logs inside logs folder?
Also, double check if your static files are not in web-inf which is not accessible.
In addition, check that javac is on the path of you are using JSP
Turns out there was an error in one of the files that meant it did not scan for all the components. Also, was not able to confirm but there potentially may have been an issue with the WAR bringing necessary JAR files. I placed them in the lib file instead of relying on the Eclipse linking.
Thanks,

tomcat, 2 webapps, 2 log4js, but both apps log to one file

To elaborate on that, I have a Tomcat server version 7.0.27 running Java 1.6.0_27.
I have two wars, each with their own log4j jar, also using slf4j with slf4j-log4j. Each war has it's own configuration file (log4j.xml).
war 1 should use file log-1.log and war 2 should use file log-2.log but both are logging into log-1.log.
I've checked there are no other log4j jars in the tomcat installation so I'm not sure where the problem is. I've also turned off shared class loading but that made no difference. My next step is to turn on verbose class loader logging and/or start debugging log4j but maybe someone here knows why this is and can save me some time. Thanks for any input on this.
Update:
Ok think I got this one. The log4j xml files are fine. After doing a verbose:class I can see that log4j.jar is only getting loaded once and from neither web application.
I'm working with Documentum. They have a runtime jar required to use their libraries that is an empty jar with a manifest file. The manifest points to a bunch of jars. In other words, they don't use maven... Anyway ... one of those jars happens to be logj4 found in the Documentum installation. So it seems both webapps are using that one. I think this is the problem. To be confirmed...
If you are placing Documentum's runtime jar on your top-level classpath, and that runtime jar is referencing log4j.jar, then it will only load once. You don't have to use that runtime jar, though, or you can use it in just your Documentum .war, if one is non-Documentum.
You didn't post your properties file but i can think of some reasons:
You don't have an appender that writes to the different files, i.e you need appender1 to write to log1.log and appender2 writing to log2.txt
You have the appenders set up right but both the applications are using the same logger, so they both write to the same file.
You have 2 loggers, each with its own appender, but in your code you are not initializing the correct logger:
//there is no logger called com.sample, so it defaults to root logger that has appender that writes to log1.txt
Logger logger = Logger.getLogger(com.sample.MyClass.class);
If you post your properties file and your logger init code it'll be easier to help you.

Log4J Event Viewer Problem

I am develloping 2 applications and publishing them on Websphere Aplication Server.
Since I need to write errors that occur on both applications on the event viewer I put the log4j JAR file on the lib folder of Websphere Aplication Server and the file os being loaded successfully.
I have also created the log4j.properties file under src root package of both applications with different variable names and source designation ("Application A" and "Application B").
When an execption is caught it is being logged to the Event Viewer for both cases.
The problem is that the source name presented is the same "Application A" even if the error occured on Application B...
Can anyone help?
Thanks
I'm not sure what you mean by "applications with different variable names and source designation" — that you use differently named loggers in both applications and direct output to different appenders?
Still, I see one problem with your configuration: when you put your log4j jar into WAS lib folder, it's loaded with the class loader common for both your applications (a bootstrap class loader or extension class loader, depending where this "lib" directory is) — and that means log4j is loaded only ONCE. Considering how log4j is initialized (with a static code section), it is also initialized ONCE, meaning that at most one log4j.properties is read.
Try removing log4j from the WAS lib directory and deploy it with every application, see where it gets you.

"log4j:WARN Please initialize the log4j system properly" error

I have a web application, in which one of the JSPs contain:
PropertyConfigurator.configure(System.getenv("MY_HOME") + "/cfg/log4j.properties");
I double-checked that MY_HOME is setup
The Tomcat web server says:
log4j:WARN No appenders could be found for logger (com.mycompany.data.JobData).
log4j:WARN Please initialize the log4j system properly.
The same setup works fine in one of the other servers.
Any hints?
The problem is that no logs are created
Not related to your answer, but this helps too.
If it's a web application, the easiest way is to make sure that your log4j.properties is situated in WEB-INF/classes folder in your WAR file. When your application will be deployed, log4J will be configured.
The PropertyConfigurator must be called before anything in your system attempts to log to avoid this warning. You may find setting the log4j configuration on the command line more reliable.
Or you could ignore the warning. ;)
BTW: You don't want to call this method too often, ideally only once.
You can try this, its helps to me.
http://www.log4j.ru/articles/HelloWorld.html
I was able to find the solution to this problem running a Eclipse Dynamic Web Project in Apache Tomcat 6. Bascially, you need to load the log4j properties file out of your context.
Two basic steps
(1) Get the log4j.properties file into the "class directory" of the war file.
(2) Read the log4j properties file out of the current context. I found the best way to do this is to access the current thread's context and work from there.
For the first step above, alter the Eclipse build process to add an additional directory that will eventually load into the WEB-INF/classes directory in the war file. Specifically....
(1) In Eclipse, right click your project in the project explorer, select 'New'->'Folder'. You can name the folder anything, but the standard in this case is 'resources'. The new folder should appear at the root level of your project.
(2) Move the log4j.properties file into this new folder.
(3) Right click the project again, and select 'Build-Path'->'Configure Build Path'. Select the 'Sources' tab. Click the 'Add Folder' button. Browse to find your new folder you created in step (1) above. Select 'OK'.
(4) Once back to the eclipse Project Explorer view, note that the folder has now moved to the 'Java Resources' area (ie it's no longer at the root due to eclipse presentation abstraction).
(5) Clean build your project.
(6) To validate that the .properties file now exists in WEB-INF/classes in your war file, export a war file to an easy location (right click Project -> Export -> War file) and checkout the contents. Note that the log4j.properties file now appears in the WEB-INF/classes.
Now for the second step above, accessing the context to read the file. Add the following code where attempting to read the file. Note that this reads this out of the war file context, so this 'should' work as the war file moves from server to server.
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
PropertyConfigurator.configure(classLoader.getResourceAsStream("log4j.properties") );

Categories