INTSAMPLES-52 - All Samples should use Log4J
INTSAMPLES-52 - Standardize Log4j PatternLayout
Standardize Log4j PatternLayout to **%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n**.
This commit is contained in:
committed by
Gary Russell
parent
218668cb9c
commit
fc2e5890a9
@@ -1,118 +1,103 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.springframework.integration.samples</groupId>
|
||||
<artifactId>enricher</artifactId>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<groupId>org.springframework.integration.samples</groupId>
|
||||
<artifactId>enricher</artifactId>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Samples (Basic) - Enricher</name>
|
||||
<url>http://www.springsource.org/spring-integration</url>
|
||||
<name>Samples (Basic) - Enricher</name>
|
||||
<url>http://www.springsource.org/spring-integration</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.integration.version>2.1.0.RELEASE</spring.integration.version>
|
||||
<slf4j.version>1.6.4</slf4j.version>
|
||||
<junit.version>4.10</junit.version>
|
||||
</properties>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<spring.integration.version>2.1.0.RELEASE</spring.integration.version>
|
||||
<log4j.version>1.2.16</log4j.version>
|
||||
<junit.version>4.10</junit.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo.springsource.org.milestone</id>
|
||||
<name>Spring Framework Maven Milestone Repository</name>
|
||||
<url>https://repo.springsource.org/milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>repo.springsource.org.milestone</id>
|
||||
<name>Spring Framework Maven Milestone Repository</name>
|
||||
<url>https://repo.springsource.org/milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.8</version>
|
||||
<configuration>
|
||||
<additionalProjectnatures>
|
||||
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
|
||||
</additionalProjectnatures>
|
||||
<additionalBuildcommands>
|
||||
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
|
||||
</additionalBuildcommands>
|
||||
<downloadSources>true</downloadSources>
|
||||
<downloadJavadocs>true</downloadJavadocs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<compilerArgument>-Xlint:all</compilerArgument>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<configuration>
|
||||
<mainClass>org.springframework.integration.samples.enricher.Main</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.8</version>
|
||||
<configuration>
|
||||
<additionalProjectnatures>
|
||||
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
|
||||
</additionalProjectnatures>
|
||||
<additionalBuildcommands>
|
||||
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
|
||||
</additionalBuildcommands>
|
||||
<downloadSources>true</downloadSources>
|
||||
<downloadJavadocs>true</downloadJavadocs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<compilerArgument>-Xlint:all</compilerArgument>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2</version>
|
||||
<configuration>
|
||||
<mainClass>org.springframework.integration.samples.enricher.Main</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
|
||||
<!-- Testing -->
|
||||
<!-- Testing -->
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Integration -->
|
||||
<!-- Spring Integration -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-core</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-core</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging -->
|
||||
<!-- Logging -->
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Embedded Database -->
|
||||
<!-- Embedded Database -->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.3.162</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.3.162</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -19,8 +19,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.samples.enricher.service.UserService;
|
||||
@@ -35,108 +34,108 @@ import org.springframework.integration.samples.enricher.service.UserService;
|
||||
*/
|
||||
public final class Main {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
|
||||
private static final Logger LOGGER = Logger.getLogger(Main.class);
|
||||
|
||||
private static final String LINE_SEPARATOR = "\n==========================================================================";
|
||||
private static final String EMPTY_LINE = "\n ";
|
||||
private static final String LINE_SEPARATOR = "\n==========================================================================";
|
||||
private static final String EMPTY_LINE = "\n ";
|
||||
|
||||
private Main() { }
|
||||
private Main() { }
|
||||
|
||||
/**
|
||||
* Load the Spring Integration Application Context
|
||||
*
|
||||
* @param args - command line arguments
|
||||
*/
|
||||
public static void main(final String... args) {
|
||||
/**
|
||||
* Load the Spring Integration Application Context
|
||||
*
|
||||
* @param args - command line arguments
|
||||
*/
|
||||
public static void main(final String... args) {
|
||||
|
||||
LOGGER.info(LINE_SEPARATOR
|
||||
+ EMPTY_LINE
|
||||
+ "\n Welcome to Spring Integration! "
|
||||
+ EMPTY_LINE
|
||||
+ "\n For more information please visit: "
|
||||
+ "\n http://www.springsource.org/spring-integration "
|
||||
+ EMPTY_LINE
|
||||
+ LINE_SEPARATOR );
|
||||
LOGGER.info(LINE_SEPARATOR
|
||||
+ EMPTY_LINE
|
||||
+ "\n Welcome to Spring Integration! "
|
||||
+ EMPTY_LINE
|
||||
+ "\n For more information please visit: "
|
||||
+ "\n http://www.springsource.org/spring-integration "
|
||||
+ EMPTY_LINE
|
||||
+ LINE_SEPARATOR );
|
||||
|
||||
final AbstractApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/*-context.xml");
|
||||
final AbstractApplicationContext context =
|
||||
new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/*-context.xml");
|
||||
|
||||
context.registerShutdownHook();
|
||||
context.registerShutdownHook();
|
||||
|
||||
final Scanner scanner = new Scanner(System.in);
|
||||
final Scanner scanner = new Scanner(System.in);
|
||||
|
||||
final UserService service = context.getBean(UserService.class);
|
||||
final UserService service = context.getBean(UserService.class);
|
||||
|
||||
LOGGER.info(LINE_SEPARATOR
|
||||
+ EMPTY_LINE
|
||||
+ "\n Please press 'q + Enter' to quit the application. "
|
||||
+ EMPTY_LINE
|
||||
+ LINE_SEPARATOR
|
||||
+ EMPTY_LINE
|
||||
+ "\n This example illustrates the usage of the Content Enricher. "
|
||||
+ EMPTY_LINE
|
||||
+ "\n Usage: Please enter 1 or 2 or 3 + Enter "
|
||||
+ EMPTY_LINE
|
||||
+ "\n 3 different message flows are triggered. For sample 1+2 a "
|
||||
+ "\n user object containing only the username is passed in. "
|
||||
+ "\n For sample 3 a Map with the 'username' key is passed in and enriched "
|
||||
+ "\n with the user object using the 'user' key. "
|
||||
+ EMPTY_LINE
|
||||
+ "\n 1: In the Enricher, pass the full User object to the request channel. "
|
||||
+ "\n 2: In the Enricher, pass only the username to the request channel. "
|
||||
+ "\n 3: In the Enricher, pass only the username to the request channel. "
|
||||
+ EMPTY_LINE
|
||||
+ LINE_SEPARATOR);
|
||||
LOGGER.info(LINE_SEPARATOR
|
||||
+ EMPTY_LINE
|
||||
+ "\n Please press 'q + Enter' to quit the application. "
|
||||
+ EMPTY_LINE
|
||||
+ LINE_SEPARATOR
|
||||
+ EMPTY_LINE
|
||||
+ "\n This example illustrates the usage of the Content Enricher. "
|
||||
+ EMPTY_LINE
|
||||
+ "\n Usage: Please enter 1 or 2 or 3 + Enter "
|
||||
+ EMPTY_LINE
|
||||
+ "\n 3 different message flows are triggered. For sample 1+2 a "
|
||||
+ "\n user object containing only the username is passed in. "
|
||||
+ "\n For sample 3 a Map with the 'username' key is passed in and enriched "
|
||||
+ "\n with the user object using the 'user' key. "
|
||||
+ EMPTY_LINE
|
||||
+ "\n 1: In the Enricher, pass the full User object to the request channel. "
|
||||
+ "\n 2: In the Enricher, pass only the username to the request channel. "
|
||||
+ "\n 3: In the Enricher, pass only the username to the request channel. "
|
||||
+ EMPTY_LINE
|
||||
+ LINE_SEPARATOR);
|
||||
|
||||
while (!scanner.hasNext("q")) {
|
||||
while (!scanner.hasNext("q")) {
|
||||
|
||||
final String input = scanner.nextLine();
|
||||
final String input = scanner.nextLine();
|
||||
|
||||
User user = new User("foo", null, null);
|
||||
User user = new User("foo", null, null);
|
||||
|
||||
if ("1".equals(input)) {
|
||||
if ("1".equals(input)) {
|
||||
|
||||
final User fullUser = service.findUser(user);
|
||||
printUserInformation(fullUser);
|
||||
final User fullUser = service.findUser(user);
|
||||
printUserInformation(fullUser);
|
||||
|
||||
} else if ("2".equals(input)) {
|
||||
} else if ("2".equals(input)) {
|
||||
|
||||
final User fullUser = service.findUserByUsername(user);
|
||||
printUserInformation(fullUser);
|
||||
final User fullUser = service.findUserByUsername(user);
|
||||
printUserInformation(fullUser);
|
||||
|
||||
} else if ("3".equals(input)) {
|
||||
} else if ("3".equals(input)) {
|
||||
|
||||
final Map<String, Object> userData = new HashMap<String, Object>();
|
||||
userData.put("username", "foo_map");
|
||||
final Map<String, Object> userData = new HashMap<String, Object>();
|
||||
userData.put("username", "foo_map");
|
||||
|
||||
final Map<String, Object> enrichedUserData = service.findUserWithUsernameInMap(userData);
|
||||
final Map<String, Object> enrichedUserData = service.findUserWithUsernameInMap(userData);
|
||||
|
||||
final User fullUser = (User) enrichedUserData.get("user");
|
||||
final User fullUser = (User) enrichedUserData.get("user");
|
||||
|
||||
printUserInformation(fullUser);
|
||||
printUserInformation(fullUser);
|
||||
|
||||
} else {
|
||||
LOGGER.info("\n\n Please enter '1', '2', or '3' <enter>:\n\n");
|
||||
}
|
||||
} else {
|
||||
LOGGER.info("\n\n Please enter '1', '2', or '3' <enter>:\n\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info("\n\nExiting application...bye.");
|
||||
LOGGER.info("\n\nExiting application...bye.");
|
||||
|
||||
System.exit(0);
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static void printUserInformation(User user) {
|
||||
private static void printUserInformation(User user) {
|
||||
|
||||
if (user != null) {
|
||||
LOGGER.info("\n\n User found - Username: '{}', Email: '{}', Password: '{}'.\n\n",
|
||||
new Object[] {user.getUsername(), user.getEmail(), user.getPassword()});
|
||||
if (user != null) {
|
||||
LOGGER.info(String.format("\n\n User found - Username: '%s', Email: '%s', Password: '%s'.\n\n",
|
||||
user.getUsername(), user.getEmail(), user.getPassword()));
|
||||
|
||||
} else {
|
||||
LOGGER.info("\n\n No User found for username: 'foo'.\n\n");
|
||||
}
|
||||
} else {
|
||||
LOGGER.info("\n\n No User found for username: 'foo'.\n\n");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.integration.samples.enricher.service.impl;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.integration.samples.enricher.User;
|
||||
|
||||
/**
|
||||
@@ -27,28 +26,28 @@ import org.springframework.integration.samples.enricher.User;
|
||||
*/
|
||||
public class SystemService {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SystemService.class);
|
||||
private static final Logger LOGGER = Logger.getLogger(SystemService.class);
|
||||
|
||||
/** Default Constructor. */
|
||||
public SystemService() {
|
||||
super();
|
||||
super();
|
||||
}
|
||||
|
||||
public User findUser(User user) {
|
||||
|
||||
LOGGER.info("Calling method 'findUser' with parameter {}", user);
|
||||
LOGGER.info(String.format("Calling method 'findUser' with parameter %s", user));
|
||||
|
||||
final User fullUser = new User(user.getUsername(),
|
||||
"secret",
|
||||
user.getUsername() + "@springintegration.org");
|
||||
"secret",
|
||||
user.getUsername() + "@springintegration.org");
|
||||
return fullUser;
|
||||
}
|
||||
|
||||
public User findUserByUsername(String username) {
|
||||
|
||||
LOGGER.info("Calling method 'findUserByUsername' with parameter: {}", username);
|
||||
LOGGER.info(String.format("Calling method 'findUserByUsername' with parameter: %s", username));
|
||||
|
||||
return new User(username, "secret", username + "@springintegration.org");
|
||||
return new User(username, "secret", username + "@springintegration.org");
|
||||
|
||||
}
|
||||
|
||||
|
||||
28
basic/enricher/src/main/resources/log4j.xml
Normal file
28
basic/enricher/src/main/resources/log4j.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<!-- Appenders -->
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- Loggers -->
|
||||
<logger name="org.springframework.integration">
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.integration.samples">
|
||||
<level value="info" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<configuration>
|
||||
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d %5p | %t | %-55logger{55} | %m %n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework.integration">
|
||||
<level value="INFO" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework">
|
||||
<level value="INFO" />
|
||||
</logger>
|
||||
|
||||
<root>
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="CONSOLE" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user