I have a very weird problem with Struts 2.1.8 and SLF4J with Logback. I think I have setup everything as it should be (logback-core, logback-classic, slf4j-api and removed commons-logging from Struts JARs), but the logs look like this:
16:23:59,985 INFO [stdout] (ajp-localhost-127.0.0.1-8009-3) 2013-05-11 16:23:59,985 DEBUG [BasicTilesContainer.java:615] [ODk3Cc2-mn-X8eVfnemQn5WZ.undefined] - Render request recieved for definition 'DocumentList'
Clearly there are two timestamps, and one logging framework is logging through another somewhere, which causes this problem.
JBoss 7.1.1 is used.
Any ideas how to solve this problem?
EDITED:
This is how Logback configuration looks like:
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %5p [%F:%L] [%X{sessionId}] - %m%n</pattern>
</encoder>
</appender>
I had a problem with modules in JBoss 7, but now although they are solved and Logback is really loaded, but the log files still are a mess. They look like if they are logged through JUL:
20:23:46,128 INFO [stdout] (connector_xxxx) 2013-05-11 20:23:46,127 DEBUG [ReConnector.java:83] [] - Next connection attempt in (ms) 20000
It looks like one logger is logging through the other.
Related
I have an application with the name cat_tiger.war that gets deployed as localhost:8080/cat_tiger but I want to change the context path to localhost:8080/cat/lion/ instead. I've added the META-INF/context.xml file as
<?xml version="1.0" encoding="UTF-8"?>
<Context copyXML="true" docBase="cat_tiger" path="/cat/lion"/>
and the server.xml file to be
<Host name="localhost" appBase="webapps"
copyXML="true" deployXML="true"
unpackWARs="true" autoDeploy="true">
but it still deploys as localhost:8080/cat_tiger/
Any ideas as to what else needs to be changed?
EDIT:
[1] Tomcat 8.5.3
[2]
04-Sep-2018 13:50:41.830 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor [/opt/tomcat/conf/Catalina/localhost/cat_tiger.xml] has finished in [2,750] ms
...
...
04-Sep-2018 13:50:39.070 WARNING [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor A docBase [/opt/tomcat/webapps/cat_tiger] inside the host appBase has been specified, and will be ignored
[3] I'm deploying through Netbeans but will have to be deployed in a Docker container eventually.
I don't understand why you are having problems, but I've created the web project using NetBeans 8.2 (File > New Project... > Java Web > Web Application), and successfully changed the context, so perhaps if I give details of my project you can identify where there's a crucial difference.
1 cat_tiger\web\META-INF\context.xml
My file looks identical to yours:
<?xml version="1.0" encoding="UTF-8"?>
<Context copyXML="true" docBase="cat_tiger" path="/cat/lion"/>
[2] Run output
Select the project node, right click and select Run from the popup menu to run on Tomcat 8.5:
ant -f D:\\NB82\\cat_tiger -Dnb.internal.action.name=run -Ddirectory.deployment.supported=true -DforceRedeploy=false -Dnb.wait.for.caches=true -Dbrowser.context=D:\\NB82\\cat_tiger -Duser.properties.file=C:\\Users\\johndoe\\AppData\\Roaming\\NetBeans\\8.2\\build.properties run
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
library-inclusion-in-archive:
library-inclusion-in-manifest:
compile:
compile-jsps:
In-place deployment at D:\NB82\cat_tiger\build\web
Deployment is in progress...
deploy?config=file%3A%2FC%3A%2FUsers%2Fjohndoe%2FAppData%2FLocal%2FTemp%2Fcontext7953615149857268018.xml&path=/cat/lion
OK - Deployed application at context path [/cat/lion]
Start is in progress...
start?path=/cat/lion
OK - Started application at context path [/cat/lion]
run-deploy:
Browsing: http://localhost:8080/cat/lion
run-display-browser:
run:
BUILD SUCCESSFUL (total time: 0 seconds)
Actually, you probably don't need to run the application to see the problem; just select Deploy instead of Run from the popup menu. This is the output I get from Deploy:
ant -f D:\\NB82\\cat_tiger -Dnb.internal.action.name=redeploy -Ddirectory.deployment.supported=true -DforceRedeploy=true -Dnb.wait.for.caches=true -Dbrowser.context=D:\\NB82\\cat_tiger -Duser.properties.file=C:\\Users\\johndoe\\AppData\\Roaming\\NetBeans\\8.2\\build.properties run-deploy
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
library-inclusion-in-archive:
library-inclusion-in-manifest:
compile:
compile-jsps:
Undeploying ...
undeploy?path=/cat_tiger
OK - Undeployed application at context path [/cat_tiger]
In-place deployment at D:\NB82\cat_tiger\build\web
Deployment is in progress...
deploy?config=file%3A%2FC%3A%2FUsers%2Fjohndoe%2FAppData%2FLocal%2FTemp%2Fcontext5063723197082921373.xml&path=/cat/lion
OK - Deployed application at context path [/cat/lion]
Start is in progress...
start?path=/cat/lion
OK - Started application at context path [/cat/lion]
run-deploy:
BUILD SUCCESSFUL (total time: 0 seconds)
[3] Tomcat log
Here are the deployment details in the Tomcat log, where you can see that my deployment shows the context correctly, whereas yours does not:
05-Sep-2018 23:09:09.321 INFO [http-nio-8080-exec-6] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor [C:\apache-tomcat-8.5.20\conf\Catalina\localhost\cat#lion.xml]
05-Sep-2018 23:09:09.334 INFO [http-nio-8080-exec-6] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor [C:\apache-tomcat-8.5.20\conf\Catalina\localhost\cat#lion.xml] has finished in [13] ms
05-Sep-2018 23:09:09.338 INFO [http-nio-8080-exec-5] org.apache.catalina.util.LifecycleBase.start The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/cat/lion]] after start() had already been called. The second call will be ignored.
[4] C:\apache-tomcat-8.5.20\conf\Catalina\localhost\cat#lion.xml
This is the file Tomcat created when deploying the application:
<?xml version="1.0" encoding="UTF-8"?>
<Context copyXML="true" docBase="D:\NB82\cat_tiger\build\web" path="/cat/lion"/>
Note that docBase contains an absolute path.
[5] server.xml
Here's the entire content. I'm using Tomcat 8.5. Note that the <host> element is slightly different to yours, but when I added copyXML="true" deployXML="true" to the <host> element (so it looked like yours) everything continued to work fine:
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<GlobalNamingResources>
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" relaxedQueryChars="[]|{}^+\`"<>"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/>
<Context docBase="C:\apache-tomcat-8.5.20\wtpwebapps\PlusServlet" path="/PlusServlet" reloadable="true" source="org.eclipse.jst.jee.server:PlusServlet"/>
</Host>
</Engine>
</Service>
</Server>
Updated 9/6/2018:
Ignore the answer given above! Even though it happened to work for my configuration, the approach is explicitly disallowed in the Tomcat documentation.
Specifically, path should not be specified within the <Context> of a context.xml file placed within the application's META-INF directory. From the path description in the Common Attributes section of the Tomcat 8.5 documentation for the Context Container:
This attribute must only be used when statically defining a Context in
server.xml. In all other circumstances, the path will be inferred from
the filenames used for either the .xml context file or the docBase.
Even when statically defining a Context in server.xml, this attribute
must not be set unless either the docBase is not located under the
Host's appBase or both deployOnStartup and autoDeploy are false. If
this rule is not followed, double deployment is likely to result.
My unmanaged server extension uses slf4j-log4j logging. When log4j.properties is bundled with the extension, logging works fine.
When it's not bundled but instead placed in Neo4j's conf directory, I assumed
wrapper.java.additional=-Dlog4j.configuration=file:conf/log4j.properties
from neo4j-wrapper.conf would ensure that it's picked up.
However, I don't see the log file being created or the specified log level being used.
The config file must be correct because it works as designed when bundled with the extension.
Adding -Dlog4j.debug as suggested in other posts adds no further information.
Is there something I've missed? I'm using Neo4j 2.1.3 on Mac OS X
Neo4j internally has the logback jars aboard, so every logging using slf4j will be handled by logback.
My approach to logging from an unmanaged extension is as follows:
Set up your logger in the unmanaged extension have a dependency on slf4j-api (do not add and other slf4j implementations to the classpath) and use the logger like this:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger(com.mycompany.UnmanagedExtension.class);
Modify conf/custom-logback.xml and amend at the end:
<appender name="EXTENSIONLOG" class="ch.qos.logback.core.FileAppender">
<file>extensions.log</file>
<encoder>
<pattern>%date{yyyy-MM-dd HH:mm:ss.SSSZ} %-5level [%logger{15}]: %message%n</pattern>
</encoder>
</appender>
<logger name="com.mycompany" level="debug">
<appender-ref ref="EXTENSIONLOG"/>
</logger>
conf/custom-logback.xml is included by Neo4j's internal logback configuration, see https://github.com/neo4j/neo4j/blob/master/community/kernel/src/main/resources/neo4j-logback.xml
I have created Web Application by using JSF 2.0, Log 4j 1.2.14 and JBoss 7. When I run testcase, the log file is created. And the log file can't create when I run web application.
I there is anything I need to configur, please tell me.
Take a look at this maybe can help you.
The following filejboss-deployment-structure.xmlneeds to contain the following:
<jboss-deployment-structure>
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
</jboss-deployment-structure>
Make sure the configuration file (log4j.xml or log4j.properties) is in the classpath of the web application (in this case, in the binaries).
WEB-INF/classes/log4j.properties
If you have both files (log4.properties, log4j.xml) only is considered log4j.xml. The first time you init or use some instance of org.apache.log4j.Logger, log4j search the configuration file in the classpath, then the configuration is loaded.
If you want to see this process of searching and loading more closely, add the following argument to the virtual machine:
-Dlog4j.debug
I've been using the javamelody monitoring plugin for a while in Grails with no problem, but lately I had to move my developments to another computer (I'm now using netbeans 7.1.2). After reinstalling the plugins, I run the app flawlessly in my development environment. But when I run the war to my production environment, the following warnings show up:
log4j:WARN No appenders could be found for logger (net.bull.javamelody).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
The appenders section in Config.groovy is:
appenders {
console name:'stdout', layout:pattern(conversionPattern: '%d [%t] %-5p %c{2} %x - %m%n')
appender new DailyRollingFileAppender (
name: 'dailyAppender',
datePattern: "'.'yyyy-MM-dd",
fileName: "logs/${appName}.log",
layout: pattern(conversionPattern:'%d [%t] %-5p %c{2} %x - %m%n')
)
}
My questions are:
Why aren't these warnings present in the development environment's log ?What are possible consecuences on the application ?
I'm running Grails 1.3.9, Melody 1.2, tomcat 7.0.23
Thanks
It might be different form environment to environment if you have
setup a logging appender in the development section of your Grails
Config.groovy file but not for your production section.
The consequences are that you will not have logging. You may have code in your application that says log.error("Critical Error!") but since this is not linked to any appender you will never see it anywhere.
Check out logging in the documentation.
I am trying to replace log4j in my Grails app with logback but am always getting a
Embedded error: java.lang.reflect.InvocationTargetException
org.apache.log4j.LogManager
when running run-app or test-app.
I have included the following in BuildConfig.groovy which I thought is enough:
inherits("global") {
excludes "slf4j-log4j12"
}
[...]
dependencies {
build 'ch.qos.logback:logback-core:0.9.29', 'ch.qos.logback:logback-classic:0.9.29'
runtime 'ch.qos.logback:logback-core:0.9.29', 'ch.qos.logback:logback-classic:0.9.29'
}
I cannot find any more references to Log4J and have no idea where this call comes from?!
I am also trying replace Grails slf 1.5.8 by 1.6.2 and get the following in the console despite having excluded slf from all Grails modules:
SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
Thanks in advance for any help
Regards,
Jonas
Logback 0.9.21 and above depends on slf4j-api 1.6 which is what that error is telling you.
Add dependencies for org.slf4j:slf4j-api:1.6
This worked for me in BuildConfig.groovy when using Grails 2.1.0:
inherits("global") {
excludes 'grails-plugin-log4j'
}
[...]
dependencies {
compile 'ch.qos.logback:logback-classic:1.0.6'
runtime 'ch.qos.logback:logback-classic:1.0.6'
}
[...]
this.classLoader.rootLoader.addURL(new File("${basedir}/grails-app/conf/").toURI().toURL())
This last line makes Grails properly read grails-app/conf/logback.groovy if you want to set your configuration there.
I used logback 1.0.6. It did not not work. But I use another way. set environment variable "logback.configurationFile={groovy file address}". for example:
grails run-app -Dlogback.configurationFile=c:\log\logback.groovy
You can use this parameter in tomcat or any others that you put your war file in it.
It works for me.
I integrated Logback to Grails a few days ago - my steps to the working solution are here: Grails 2.1.1 - Logback integration
Also, there is just a new Plugin 'round the block: http://grails.org/plugin/logback which seems promising!
Good luck with this issue - it's worth the effort!
It might be helpful for others:
specify the config in Config.groovy
logback = {
appenders {
console name: 'stdout', encoder: pattern(pattern: "%d{dd-MMM-yyyy HH:mm:ss} %-5p %c - %m%n")
rollingFile(
name: 'fileAppender',
file: logFileName,
encoder: pattern(pattern: "%d{dd-MMM-yyyy HH:mm:ss} %-5p %c - %m%n"),
triggeringPolicy: new SizeBasedTriggeringPolicy(maxFileSize: 10*1024*1024), // Max is 10 MB log files
rollingPolicy: new FixedWindowRollingPolicy(fileNamePattern: iLogFileName)
)
}
error fileAppender: 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
info fileAppender: 'org.springframework.web.client',
'com.yourpackage',
'com.linkedin.grails'
debug fileAppender: 'com.yourpackage', // Set debug level for non-grails artifacts, e.g. src/groovy, under the com.yourpackage.package
'grails.app' // Set debug level for all application artifacts
trace fileAppender: 'org.springframework.web.client',
'org.springframework.social',
'com.yourpackage'
root {
info 'stdout', 'fileAppender'
}
}
Include the logback plugin and Exclude the require packages:
in BuildConfig.groovy
inherits("global") {
excludes 'grails-plugin-log4j', 'log4j' //using logback as grails-log4j have serialization issues with spark libraries
}
inside dependencies: include compile 'org.grails.plugins:logback:0.3.1'
Disable Fork mode execution. It will not work with logback.
The above configurations will ONLY work with the WAR mode.
If you even want to control logging during normal local dev mode, Include a logback.xml file in your conf directory.
logback.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="warn">
<appender-ref ref="STDOUT"/>
</root>
<shutdownHook/>
</configuration>