Reduce logs generated by SpringMVC application - spring-mvc

I have a SpringMVC 3 application which uses Spring Security, AOP, HIbernate etc.
But when I run it in Tomcat or Jetty, it generates a huge amount of log.
How can I reduce this log?
I want a log level starting from WARNING.
Example of the log:
21:16:08.393 [qtp12506312-25] DEBUG o.s.s.w.s.HttpSessionEventPublisher - Publishing event: org.springframework.security.web.session.HttpSessi onCreatedEvent[source=org.eclipse.jetty.server.session.HashedSess ion:db7nzoxke45es1k02gbug79d#6784961]
21:16:08.394 [qtp12506312-25] DEBUG o.s.s.w.s.HttpSessionRequestCache - DefaultSavedRequest added to Session: DefaultSavedRequest[http://xx.xx.xx.xx:8080/favicon.ico]
21:16:08.394 [qtp12506312-25] DEBUG o.s.s.w.a.ExceptionTranslationFilter - Calling Authentication entry point.
21:16:08.440 [qtp12506312-25] DEBUG o.s.s.web.DefaultRedirectStrategy - Redirecting to 'http://xx.xx.xx.xx:8080/default;jsessionid=db7nzoxke45es1k02gbug79d'
21:16:08.441 [qtp12506312-25] DEBUG o.s.s.w.c.HttpSessionSecurityContextRepository - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
21:16:08.441 [qtp12506312-25] DEBUG o.s.s.w.c.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed
21:16:08.518 [qtp12506312-26] DEBUG o.s.s.web.util.AntPathRequestMatcher - Checking match of request : '/default'; against '/loginform.jsp'
21:16:08.518 [qtp12506312-26] DEBUG o.s.s.web.util.AntPathRequestMatcher - Checking match of request : '/default'; against '/loginform2.jsp'
21:16:08.518 [qtp12506312-26] DEBUG o.s.s.web.util.AntPathRequestMatcher - Checking match of request : '/default'; against '/default'
21:16:08.518 [qtp12506312-26] DEBUG o.s.security.web.FilterChainProxy - /default has an empty filter list

If you are using logback for logging then change the root logger's log lever to WARNING, you can find the logback.xml file in the classpath
Ex:
<root level="WARN">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
If you are using log4j, you can find the log4j.properties file in your classpath. Change the rootlogger level to WARNING again
log4j.rootLogger=WARNING , A1

Related

ArangoDB and gremlin: How to reduce LOGGING

I have installed gremlin (v. 2.6.0) and ArangoDB (v. 2.8.11) and when I run any request through the gremlin.sh shell I get all the debug messages like
11:17:39.713 [main] DEBUG com.arangodb.http.HttpManager - [REQ]http-GET: url=http://localhost:8529/_api/gharial/myDB/edge/E/12712, headers={}
11:17:39.716 [main] DEBUG com.arangodb.http.HttpManager - [RES]http-GET: statusCode=200
11:17:39.716 [main] DEBUG com.arangodb.http.HttpManager - [RES]http-GET: text={"error":false,"code":200,"edge":{"_id":"E/12712"," . . .
I see those are DEBUG messages, so I want to suppress in order not to be flooded by those and only get important messages, like errors or warnings.
To reduce logging one has to change the log level on both server and client side.
Complete steps to fix this:
create config PATH_TO/confs/ directory with inside:
a. file confs/arangod.conf
b. file confs/logback.xml
set env. variable CLASSPATH:
export CLASSPATH=PATH_TO/confs
you can start arangod as follows:
arangod --daemon --pid-file /etc/arangodb/arangodb.pid -c PATH_TO/confs/arangod.conf
The content of confs/arangod.conf should contain:
[log]
## info, warning, or error
level = info
file = PATH_TO/logs/arangodb.log
The content of the confs/logback.xml
<configuration>
<!-- Arango log4j conf -->
<appender name="CONSOLE"
class="ch.qos.logback.core.ConsoleAppender">
<!-- deny all events with a level below INFO, that is TRACE and DEBUG -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<encoder>
<pattern>
%-4relative [%thread] %-5level %logger{30} - %msg%n
</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>
</configuration>

Spring Boot exception: Could not open ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml]

I have developed this proof of concept https://github.com/DISID/disid-proofs/tree/master/spring-boot-weblogic to test the deployment of Spring Boot applications in Weblogic 12c (12.2.1).
The application deploys and starts successfully, but when I try to connect to it (i.e. /accounts?number=1234) the error below is shown:
Error 500--Internal Server Error
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.5.1 500 Internal Server Error
The server encountered an unexpected condition which prevented it
from fulfilling the request.
And the log file has the exception:
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:609)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:510)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:244)
at weblogic.servlet.internal.StubSecurityHelper$ServletInitAction.run
Did I miss something?
Thanks,
I found a workaround putting a dummy dispatcherServlet-servlet.xml file under WEB-INF:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Do not remove this file! -->
</beans>
I've reproduced this issue with WebLogic 12.2.1.0 (plain new install) using spring-boot-sample-war (with an additional weblogic.xml to handle logging). Also tried the latest patchset (WLS PATCH SET UPDATE 12.2.1.0.160419), but the issue remains.
For some reason WebLogic decides it needs to create the DispatcherServlet using it's own configuration as soon as you access the application available on /.
I've put in a service request to Oracle Support and we'll see what they think about this issue.
Update: 'Patch 23124727: CANNOT DEPLOY SPRING BOOT .WAR ON 12.2.1 DUE TO JAVA.IO.FILENOTFOUNDEXCEPTION' is available for Oracle WebLogic Server 12.2.1.0.0 and works with both the spring-boot-sample-war as well as a more advanced application.

400 error (Bad Request) creating a Page with Experience Manager

I have an SDL Tridion 2011 SP1 HR1 image in which Experience Manager is installed. I can successfully browse my staging site, log in to ExM and change content and pages. However, when I try to create a new page I get a 400 (Bad Request) error. This is the logged error:
Unable to update the changes using OData Service.
The remote server returned an error: (400) Bad Request.
Component: Tridion.SiteEdit.FastTrackPublishing
Errorcode: 1003
User: NT AUTHORITY\NETWORK SERVICE
StackTrace Information Details:
at System.Net.HttpWebRequest.GetResponse()
at System.Data.Services.Client.DataServiceContext.SaveResult.BatchRequest(Boolean replaceOnUpdate)
at System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions options)
at Tridion.SiteEdit.FastTrackPublishing.ServiceImplementation.Preview(IEnumerable1 publishedItemsInfo, TcmUri publishingTargetId)
at Tridion.SiteEdit.FastTrackPublishing.ServiceImplementation.Preview(IEnumerable1 publishedItemsInfo, TcmUri publishingTargetId)
at SyncInvokePreview(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
I've just checked the CD log file and can see this error:
012-10-16 12:29:05,782 ERROR JPADAOFactory - Unable to load JPA DAO with name: TrackedRequest and class: com.tridion.storage.TrackedRequestDAO due too exception in DAO construction
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TrackedRequestDAO' defined in URL [jar:file:/C:/ASP.NET/Preview/httpupload/bin/lib/tracking_core.jar!/com/tridion/storage/TrackedRequestDAO.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.tridion.storage.TrackedRequestDAO]: Constructor threw exception; nested exception is com.tridion.configuration.ConfigurationException: Unexpected dialect encountered: . TrackedRequest item type should be configured to use a supported database.
Inline editing was enabled for the already published content when I received the image but I needed to create the Content Type and Page Type myself. I did this in the usual manner, creating a Page, flagging it as a Page Type, adding the prototype content to it, and configuring the settings for naming and storage (for the created content). I also restarted IIS, shutdown the COM+ package and restarted the Tridion Service Host and Publisher services.
Can anyone explain why I'm getting this error, and how to fix it?
EDIT
So the error suggests it's an issue in the storage config. Here are the relevant sections:
<Storage Id="trackingDB" Class="com.tridion.storage.persistence.JPADAOFactory" Type="persistence" dialect="MSSQL">
<Pool CheckoutTimeout="120" IdleTimeout="120" MonitorInterval="60" Size="5" Type="jdbc"/>
<DataSource Class="com.microsoft.sqlserver.jdbc.SQLServerDataSource">
<Property Name="serverName" Value="SDLPE.pe.local"/>
<Property Name="portNumber" Value="1433"/>
<Property Name="databaseName" Value="tridion_tracking"/>
<Property Name="user" Value="encrypted:u9aIOj9uX2IcL1rI6U5ndA=="/>
<Property Name="password" Value="encrypted:vprUfrnluvIQAVRNSMTx5g=="/>
</DataSource>
</Storage>
And:
<Item cached="true" typeMapping="TrackedRequest" storageId="trackingDB"/>
EDIT
I've just been trawling through the log file and found this:
2012-10-16 14:12:43,148 DEBUG ConfigurationItemTypeLoader - Loaded mapping: trackedrequest to storage: trackingDB
2012-10-16 14:12:43,148 DEBUG ConfigurationItemTypeLoader - Loaded mapping: trackingbatch to storage: trackingDB
2012-10-16 14:12:43,148 DEBUG ConfigurationItemTypeLoader - Loaded mapping: synchronizationrecord to storage: trackingDB
2012-10-16 14:12:43,148 DEBUG ConfigurationItemTypeLoader - Loaded mapping: trackingitem to storage: trackingDB
It seems that the config should be picked up correctly, but still it can't read the dialect propely from the relevant storage definition.
In the end the issue was related to having Page Metadata specified for the Page Type. The errors I was seeing logged don't affect the performance of the website so were misleading me.

Deploy WCF Web Service in IIS 7 - Getting Error

I'm trying to add a service reference in VS 2010 to a WCF Web Service I have on a Server 2008/IIS7 server. I put the service into an existing/working ASP.NET site. When I type in the url of the service, it comes up with the standard service screen, but when I try to add the reference to a new website project I'm developing, I get the following error.
The document at the url https://www.nameofsite.net/service.svc?wsdl was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'XML Schema' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
- Report from 'https://www.nameofsite.net/service.svc?wsdl' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
- Report from 'DISCO Document' is 'Discovery document at the URL https://www.nameofsite.net/Service.svc?disco could not be found.'.
- The document format is not recognized.
- Report from 'WSDL Document' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
Metadata contains a reference that cannot be resolved: 'https://www.nameofsite.net/service.svc?wsdl'.
There was no endpoint listening at https://www.nameofsite.net/service.svc?wsdl that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution and adding the service reference again.
I tried adding the mime type svc to IIS and that didn't work. I see that there's a lot of talk about soap 1.1 not communicating with soap 1.2 but I'm too new to this to even follow the instructions I've seen. Please help. Thanks.
Is the service publishing its metadata? Check the httpsGetEnabled flag in the web.config file for the service:
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpsGetEnabled="true"
httpsGetUrl="https://myComputerName/myEndpoint" />
</behavior>
</serviceBehaviors>
</behaviors>
For more info on these tags: ServiceMetaData
You may also need this endpoint configured in your web.config for the service:
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
Some more background:
Web.Config
WSDL vs MEX

External properties loader with Tomcat server

I am trying to deploy a spring mvc webapp into a tomcat server. I have been testing locally using the maven-jetty-plugin. In my spring configuration I am using a properties placeholder, and pulling my properties from an external file:
<context:property-placeholder ignore-resource-not-found="true" ignore-unresolvable="true"/>
<bean id="modelPropertyPlaceholder" class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="searchContextAttributes" value="true"/>
<property name="contextOverride" value="true"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:default.model.properties</value>
<value>file:/etc/app/app.properties</value>
<value>${config}</value>
</list>
</property>
</bean>
This worked with my jetty plugin...however when I deploy the WAR file to the tomcat server I receive the following error:
org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
In my external properties file I have the driver class and connect url defined. as so:
jndi.jpa.rms.datasource=jdbc/testDS
rms.db.driver=com.mysql.jdbc.Driver
rms.db.url=jdbc:mysql://testdatabaseurl:3306/test
rms.db.user=sa
rms.db.password=asfdas
rms.db.checkconnsql=select 1
rms.hibernate.generateddl=false
rms.hibernate.showsql=true
rms.hibernate.dbdialect=org.hibernate.dialect.MySQLDialect
Update:
It seems that tomcat does pickup the external properties file:
14:23:09.803 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'modelPropertyPlaceholder'
14:23:09.810 [main] INFO o.s.w.c.s.ServletContextPropertyPlaceholderConfigurer - Loading properties file from class path resource [default.model.properties]
14:23:09.810 [main] INFO o.s.w.c.s.ServletContextPropertyPlaceholderConfigurer - Loading properties file from URL [file:/etc/app/app.properties]
14:23:09.810 [main] INFO o.s.w.c.s.ServletContextPropertyPlaceholderConfigurer - Loading properties file from ServletContext resource [/${config}]
14:23:09.811 [main] WARN o.s.w.c.s.ServletContextPropertyPlaceholderConfigurer - Could not load properties from ServletContext resource [/${config}]: Could not open ServletContext resource [/${config}]
I'm not sure why tomcat isn't picking up the connection url and driver.
Is this a tomcat issue or am I missing something? Thanks
It's not a Tomcat issue, you must have made some minor mistake and properties are not loaded.
Are properties files located in proper place on your Tomcat environment?
Are you sure that in those properties files you have not left some keys blank?
If both answers to that questions are true, try changing your config with following:
<context:property-placeholder location="ADD_PATH_TO_YOUR_FILES SEPARATED_WITH_SPACES"/>
I guess that you are mixing here two property placeholders, one 'regular' and the other - bounded to servlet context. I can bet that somehow they get overlapped and one of them is getting silently ignored.
I would just stick to property-placeholder.
Old question, but...
Judging from the log output, it appears that Spring has not resolved your ${config} reference, or else this would have been substituted into the path given in the last log message:
Could not load properties from ServletContext resource [/${config}]: Could not open ServletContext resource [/${config}]
Here's a case I just encountered where it resolved ${catalina.home}/conf/myprops.properties correctly but was unable to load the referenced file:
Could not load properties from ServletContext resource [/D:/somepath/apache-tomcat/conf/myprops.properties]: Could not open ServletContext resource [/D:/somepath/apache-tomcat/conf/myprops.properties]
I tracked down the error in my case - I needed to prefix the external file reference with 'file:'. That is, it should have been file:${catalina.home}/conf/myprops.properties
(It is possible the Spring version difference may have impacted on the log output for you though also, and that it did resolve the reference but just did not show this in the output. For reference, I'm using Spring 4.1.6 at present).

Resources