Saturday, November 1, 2014

The parameter must indicate the full path: Mave but we have built basedir variable, which both save


Embedded Jetty in Mave is a great example MATEZA logs. How to convince the server to log the same way as your application if you are using Spring? This article is a continuation edi of slf4j and Spring MVC and Jetty and Maven.
Update 6. 7. 2014: The procedure works only Mave 3.0.x Newer versions Mave used for internal logging slf4j, which complicates a situation that does not work. In that case, use conf \ logging \ simplelogger.properties in the installation directory Mave to fine-tune the configuration. Explanation is the documentation of the Mave.
First demonstration edi of the console: 2013-08-07 17: 40: 18.047: INFO: oejs.ServerConnector: main: Started ServerConnector a5c7c18 @ {HTTP / 1.1 0.0.0.0:8080} {} [INFO] Started Jetty Server [INFO] Console reloading is enabled. Hit ENTER on the console edi to restart the context. edi 17: 40: 45.414 [qtp1433716617-27] DEBUG suinmjss.LoggingController - Accessing onLog ()
These four lines of life show three (!) Outputs from different systems: the first is the actual logging Jetty log shows a pair of Mave and the last line was established convection Spring -> commons-logging -> slf4j -> logback
Jetty can easily throw to use slf4j: because since ancient times (at least since version 8) can be internally logging information through this library. The choice is rather difficult, edi but it is enough edi to know that if the server CLASSPATH appears slf4j, Jetty uses it.
The Mave to resolve dependencies for delivering plug-in Maven Jetty. <Plugin> <groupId> org.eclipse.jetty </ groupId> <artifactId> edi jetty-maven-plugin </ artifactId> <version> 9.0.4.v20130625 </ version> <dependencies> <dependency> <groupId> org. slf4j </ groupId> <artifactId> slf4j-api </ artifactId> <version> 1.7.5 </ version> edi </ dependency> <dependency> <groupId> ch.qos.logback </ groupId> <artifactId> logback-classic </ artifactId> <version> 1.0.13 </ version> </ dependency> </ dependencies> </ plugin>
If we logovali in a normal web application, logback configured via logback.xml to be find themselves in the CLASSPATH. edi Traditionally, this means that thrown into the root package, which under mavenovských conventions to src / main / resources / logback.xml. In the resulting web application, the file himself apparently in WEB-INF / classes.
Jetty, which is embeddnutá in Mave, but these tricks can not use (and do not work or normal procedures for self-running Jetty outside Mave). Practically, there are two ways to enter the path to logback.xml: edi setting the system property from the command line, put into pom.xml.
If you set the system parameter (system property) logback.configurationFile, Jetty uses it to locate the file. The value must contain the absolute path to the file, for example. as follows: edi mvn -Dlogback.configurationFile = C: \ Projects \ maven-jetty-spring-slf4j-demo \ src \ main \ resources \ logback.xml jetty: run
The second option is to introduce a system parameter directly to the pom.xml. Plug-in for Jetty, while supporting the configuration parameter systemProperties, but in this situation it does not work: <plugin> <groupId> org.eclipse.jetty </ groupId> <artifactId> jetty-maven-plugin </ artifactId> <configuration> < systemProperties> <systemProperty> <name> fooprop </ name> <value> 222 </ value> edi </ systemProperty> </ systemProperties>
Documentation Jetty tries vague and not quite successfully explain that why this happens, but at least offers a solution: through another plugin org.codehaus.mojo: properties-maven-plugin: <plugin> <groupId> org.codehaus.mojo </ groupId> <artifactId> properties-maven-plugin </ artifactId> <version> 1.0-alpha-2 </ version> <executions> <execution> <phase> validate </ phase> <goals> <goal> set-system- properties </ goal> </ goals> <configuration> <properties> <property> edi <name> logback.configurationFile </ name> <value> $ {basedir} /src/main/resources/logback.xml </ value> < / property> </ properties> </ configuration> </ execution> </ executions> </ plugin>
From the plug-in will use goal set-system-properties that naviažeme to validate phase: it is one of the initial phases of the life cycle mavenovského compilation project and thus be carried out before the launch Jetty.
The parameter must indicate the full path: Mave but we have built basedir variable, which both saves typing and also is robust across different directory edi structure. Setting logback.xml
Said logback.xml is then simple: <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 = "INFO"> <appender-ref ref = "ST

No comments:

Post a Comment