How to write in spring application log? - java

My application is currently writing the following lines in Tomcat's localhost.log file.
Jan 09, 2017 4:52:47 PM org.apache.catalina.core.ApplicationContext log
INFO: Destroying Spring FrameworkServlet 'reportDispatcher'
Jan 09, 2017 4:52:47 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
I want to dump these in application.log.
How to achieve this?

Related

Tomcat 404 error not serving Java webapp when running eclipse

I've been struggling for 1 month and multiple employees at my company have come across the same issue. Whenever I run my java project on eclipse using Apache Tomcat and open it in my chrome browser, it shows a 404 error. After multiple reinstalls, when I open localhost, tomcat doesn't even work, now I only receive the Chrome default error message: "The site can't be reached".
Below is a snippet of the logs I receive when I startup my tomcat 7.0 server -->
INFO: Command line argument: -Dfile.encoding=Cp1252
Jun 08, 2021 3:24:43 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [C:\Program Files\Java\jre1.8.0_291\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_291/bin/server;C:/Program Files/Java/jre1.8.0_291/bin;C:/Program Files/Java/jre1.8.0_291/lib/amd64;C:\Program Files (x86)\Razer\ChromaBroadcast\bin;C:\Program Files\Razer\ChromaBroadcast\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files\AdoptOpenJDK\jdk-11.0.8.10-hotspot\bin;C:\Program Files\AdoptOpenJDK\jdk-14.0.2.12-hotspot\bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Users\akpme\AppData\Local\Microsoft\WindowsApps;C:\Program Files\JetBrains\PyCharm Community Edition 2019.2.3\bin;C:\ProgramData\akpme\atom\bin;C:\Users\akpme\AppData\Local\Microsoft\WindowsApps;C:\Users\akpme\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\akpme\AppData\Roaming\npm;C:\Program Files\heroku\bin;C:\cmake\cmake-3.19.2-win64-x64\bin;C:\Users\akpme\AppData\Local\Programs\Python\Python37;C:\Users\akpme\AppData\Local\Programs\Python\Python37\python.exe;C:\Users\akpme\AppData\Local\Programs\Python\Python37\python3.7.exe;C:\Program Files\Git\cmd;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files\Azure Data Studio\bin;C:\Program Files\PuTTY\;C:\Users\akpme\.windows-build-tools\python27\;C:\Users\akpme\AppData\Local\Microsoft\WindowsApps;C:\Program Files\JetBrains\PyCharm Community Edition 2019.2.3\bin;C:\ProgramData\akpme\atom\bin;C:\Users\akpme\AppData\Local\Microsoft\WindowsApps;C:\Users\akpme\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\akpme\AppData\Roaming\npm;C:\Program Files\heroku\bin;C:\Users\akpme\AppData\Local\GitHubDesktop\bin;C:\Program Files\Azure Data Studio\bin;C:\Programming\SaveAway\eclipse;;.]
Jun 08, 2021 3:24:44 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8090"]
Jun 08, 2021 3:24:44 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1785 ms
Jun 08, 2021 3:24:44 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
Jun 08, 2021 3:24:44 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.107
Jun 08, 2021 3:24:45 PM org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
INFO: validateJarFile(C:\Users\akpme\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\InSpirAVE\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Jun 08, 2021 3:24:59 PM org.apache.catalina.startup.TldConfig execute
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jun 08, 2021 3:24:59 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/akpme/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/InSpirAVE/WEB-INF/lib/slf4j-log4j12-1.7.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/akpme/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/InSpirAVE/WEB-INF/lib/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Jun 08, 2021 3:25:00 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Jun 08, 2021 3:25:06 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
WARNING: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [409] milliseconds.
Jun 08, 2021 3:25:06 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'mvc-dispatcher'
Jun 08, 2021 3:25:06 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8090"]
Jun 08, 2021 3:25:06 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 22419 ms
===========================================================================
Chrome Browser Screen:
==========================================================================
If you need anything else please email me at mahit.py#gmail.com.

Apache Tomcat hang after "Initializing started..."

Following are the startup log messages:
Check if Algo ant logger exists
Found Algo logger, starting with Algo ant logging
Buildfile: $ALGOWEBAPPS_HOME/bin/algowebapps-control.xml
Deleting:$ALGO_TOP/algowebapps/webapps/
acm.war,acm470help.war,awl.war,dmcfg.war,Navigator.war,mdc.war,Visualizer.war
Copying 7 file to $ALGO_TOP/algowebapps/webapps
Deleting directory $ALGO_TOP/algowebapps/webapps/awl
Copying 1 file to $ALGO_TOP/algowebapps/webapps/ROOT
Sep 26, 2017 10:18:25 PM 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...
Sep 26, 2017 10:18:25 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-12001
Sep 26, 2017 10:18:26 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8888
Sep 26, 2017 10:18:26 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1145 ms
Sep 26, 2017 10:18:26 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Sep 26, 2017 10:18:26 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
Sep 26, 2017 10:18:26 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive Navigator.war
Load details in $ALGO_TOP/algowebapps/webapps/Navigator//MetaTables.xml
Loaded 11 tables & views
Load details of db jdbc:oracle:thin:#UAT4
Load details of db jdbc:oracle:thin:#UAT4
Sep 26, 2017 10:18:32 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive mdc.war
Sep 26, 2017 10:18:32 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive acm.war
INFO: GridServlet - ==> initializing GridServlet processing
INFO: TreeServlet - ==> initializing TreeServlet processing
==> initializing LoaderServlet
INFO: AjaxStoreServlet - ==> initializing AjaxStoreServlet processing
INFO: ConfigStoreServlet - ==> initializing ConfigStoreServlet processing
INFO: ActionDataServlet - ==> initializing Ricos HTTP Servlet Executer
INFO: ExecuterServlet2 - ==> initializing Ricos HTTP Servlet Executer
INFO: ValidationServlet - ==> initializing ValidationServlet processing
Sep 26, 2017 10:18:32 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive acm470help.war
Sep 26, 2017 10:18:32 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive awl.war
Sep 26, 2017 10:18:32 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive dmcfg.war
2017-09-26 22:18:33,525 DEBUG [dmcfg] Installing into composite=com.algorithmics.log.provider.DailyLogFileProvider com.algorithmics.log.provider.CompositeLogProvider
2017-09-26 22:18:33,533 DEBUG [dmcfg] File path 'log' is relative - prepending ALGO_TOP=/opt/bns/alreu4/Algo/ALGO_TOP com.algorithmics.log.provider.DailyLogFileProvider
2017-09-26 22:18:33,534 DEBUG [dmcfg] Opening file '$ALGO_TOP/log/dmcfg-default-sbuvvrwm471-2017-09-26.log' om.algorithmics.log.provider.DailyLogFileProvider
2017-09-26 22:18:33,541 DEBUG [dmcfg] Installing into composite=com.algorithmics.log.provider.ConsoleLogProvider com.algorithmics.log.provider.CompositeLogProvider
Sep 26, 2017 10:18:36 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive Visualizer.war
Initializing started...
<<<It hangs here indefinitely>>>
Below is what is expected to follow in a normal startup:
[[
Initializing finished...
Sep 26, 2017 10:37:48 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
Sep 26, 2017 10:37:48 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-12001
Sep 26, 2017 10:37:48 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8443
Sep 26, 2017 10:37:48 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 7637 ms
]]
Is downloading Tomcat cource code and enable Tomcat debug mode the only choice to identify the root cause of such issue? But I have no access to the source code of those applications running in Tomcat (I can decompile the jar files in war files though it's a tedious). or there might be better way to figure out the cause?
This seems to be an issue with the deployed application start up. You would have to enable debug logging for the application and see the root cause.
You might also check the context.xml for the webapp and see if it's connecting to an external resource, e.g., a database. The log message explicitly mentions an Oracle jdbc driver, it may be hanging while trying to create a database connection pool.
the problem is now mitigated by a upgrade of NFS server to V4.

Tomcat fails to start using netbeans

Whenever i try to run/debug my project using netbeans, i get the following error
Deployment error: Starting of Tomcat failed.
See the server log for details.
at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:258)
at org.netbeans.modules.maven.j2ee.ExecutionChecker.performDeploy(ExecutionChecker.java:205)
at org.netbeans.modules.maven.j2ee.ExecutionChecker.executionResult(ExecutionChecker.java:123)
at org.netbeans.modules.maven.execute.MavenCommandLineExecutor.run(MavenCommandLineExecutor.java:235)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
But tomcat is started in the background.
Also when i try to start tomcat in debug mode, i get a "Tomcat" failed to start error but tomcat is started in the background.
I have changed the port several times but no luck. I have shut down my anti virus and windows defender but that doesn't help too. I have uninstalled and re installed netbeans 7.4 and 8.0.
PS: I have gone through several stackoverflow posts but couldn't find any answer to help me.
Server log
Jul 22, 2014 1:18:19 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Jul 22, 2014 1:18:19 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Jul 22, 2014 1:18:19 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache#20d04cf3')
Jul 22, 2014 3:12:25 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Jul 22, 2014 3:12:25 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Jul 22, 2014 3:12:25 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache#136da584')
Jul 22, 2014 3:37:06 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Jul 22, 2014 3:37:06 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Jul 22, 2014 3:37:06 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache#ad0db19')
Disabling ipv6 solved the issue for me.
If you use windows 8 you have to do that in the registry. Windows 7 and below, there is an installer for that at the Microsoft fix it site
In NetBeans on Tools > Servers, in Platform tab disable Use IDE Proxy Settings.
I have been banging my head against a wall over this for a few days now.
At first, it would just hang out, waiting to deploy tomcat... forever. After all the troubleshooting a hard reset was the only thing that solved the issue, but it only solved it for a one-time run of the application.The issue at hand is that the prompt for the user and password would not pop-up on my screen...The Only Fix I could find was to turn off the proxy in netbeans/preferences select "no proxy"... and just like that the web application deployed in seconds.

Log4j Warning after removing log4j related files

I am trying to run a mvc sample code in my machine. I have commented all the Log4j imports and commented all the logger statements in code. But still am getting warning in the console. I have removed the resources folder which contains log4j.properties.
Mar 26, 2014 8:03:48 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\jre7\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Riya/software_downloads/eclipse/jre/bin/server;C:/Riya/software_downloads/eclipse/jre/bin;C:/Riya/software_downloads/eclipse/jre/lib/amd64;C:\Program Files\Java\jdk1.7.0_09\bin;C:Program Files\apache-maven-3.2.1\bin;;C:\Riya\software_downloads\eclipse;;.
Mar 26, 2014 8:03:49 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:GeneratingBills' did not find a matching property.
Mar 26, 2014 8:03:49 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8086"]
Mar 26, 2014 8:03:49 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Mar 26, 2014 8:03:49 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 448 ms
Mar 26, 2014 8:03:49 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 26, 2014 8:03:49 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.34
Mar 26, 2014 8:03:53 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Mar 26, 2014 8:03:53 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
Mar 26, 2014 8:03:55 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'spring'
Mar 26, 2014 8:03:55 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8086"]
Mar 26, 2014 8:03:55 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Mar 26, 2014 8:03:55 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6088 ms
If you do not want any logging you could safely ignore that WARN message, it only states there is no log4j configuration done.
If you problem is only the below warning,
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
Add a log4j.properties and add the below single line, it will not show the warning and would switch off all the logging.
log4j.rootLogger=OFF

log4j: File getting created but not getting written

I am using Log4j file appender having the below configuration:
log4j.logger.com.atpl=INFO,ABW
log4j.appender.ABW=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ABW.File=c://atpl-platform-web//atplABW.txt
log4j.appender.ABW.DatePattern='.' yyyy-MM-dd
log4j.appender.ABW.layout=org.apache.log4j.PatternLayout
log4j.appender.ABW.layout.ConversionPattern= [%d] [%t] [%-5p] [%c] ==> %m%n
The file is getting created at the given location all right. The file is getting locked once I start the server. But when I try to log data into that file, its not working.
private static final Logger FILE_LOGGER = Logger
.getLogger(TreeDemoAction.class);
FILE_LOGGER.info(gson.toJson(rootNode));
Also below is the server log on restart.
Nov 2, 2012 3:47:15 PM 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\jdk1.6.0_03\bin;C:\Tomcat 6.0\bin
Nov 2, 2012 3:47:15 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8084
Nov 2, 2012 3:47:15 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 363 ms
Nov 2, 2012 3:47:15 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Nov 2, 2012 3:47:15 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.18
Nov 2, 2012 3:47:15 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\Tomcat 6.0\webapps\atpl-platform-web\WEB-INF\lib\servlet.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
Nov 2, 2012 3:47:17 PM org.apache.catalina.core.ApplicationContext log
INFO: Set web app root system property: 'atpl-platform-web' = [C:\Tomcat 6.0\webapps\atpl-platform-web\]
Nov 2, 2012 3:47:17 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Log4J from [C:\Tomcat 6.0\webapps\atpl-platform-web\WEB-INF\log4j.properties]
Nov 2, 2012 3:47:17 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
AbandonedObjectPool is used (org.apache.commons.dbcp.AbandonedObjectPool#84f665)
LogAbandoned: false
RemoveAbandoned: true
RemoveAbandonedTimeout: 60
Nov 2, 2012 3:47:22 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8084
Nov 2, 2012 3:47:22 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Nov 2, 2012 3:47:22 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/15 config=null
Nov 2, 2012 3:47:22 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 7177 ms
Can anyone guide me with what is wrong here? am i missing something?
Thanks.
Maybe you get the logger package wrong
log4j.logger.com.platform.web=INFO,ABW
log4j.logger.com.atpl=INFO,ABW is OK.
Try following code:
log4j.appender.ABW.File=/atpl-platform-web/atplABW.txt

Categories

Resources