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,123 +1,108 @@
|
||||
<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>jdbc</artifactId>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<groupId>org.springframework.integration.samples</groupId>
|
||||
<artifactId>jdbc</artifactId>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Samples (Basic) - JDBC</name>
|
||||
<url>http://www.springsource.org/spring-integration</url>
|
||||
<name>Samples (Basic) - JDBC</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.jdbc.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.jdbc.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>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-jdbc</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-jdbc</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>
|
||||
</dependencies>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.3.162</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -21,8 +21,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
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.jdbc.service.PersonService;
|
||||
@@ -38,109 +37,109 @@ import org.springframework.integration.samples.jdbc.service.PersonService;
|
||||
*/
|
||||
public final class Main {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
|
||||
private static final Logger LOGGER = Logger.getLogger(Main.class);
|
||||
|
||||
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("\n========================================================="
|
||||
+ "\n "
|
||||
+ "\n Welcome to Spring Integration! "
|
||||
+ "\n "
|
||||
+ "\n For more information please visit: "
|
||||
+ "\n http://www.springsource.org/spring-integration "
|
||||
+ "\n "
|
||||
+ "\n=========================================================" );
|
||||
LOGGER.info("\n========================================================="
|
||||
+ "\n "
|
||||
+ "\n Welcome to Spring Integration! "
|
||||
+ "\n "
|
||||
+ "\n For more information please visit: "
|
||||
+ "\n http://www.springsource.org/spring-integration "
|
||||
+ "\n "
|
||||
+ "\n=========================================================" );
|
||||
|
||||
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 PersonService personService = context.getBean(PersonService.class);
|
||||
|
||||
LOGGER.info("\n========================================================="
|
||||
+ "\n "
|
||||
+ "\n Please press 'q + Enter' to quit the application. "
|
||||
+ "\n "
|
||||
+ "\n=========================================================" );
|
||||
final PersonService personService = context.getBean(PersonService.class);
|
||||
|
||||
System.out.println("Please enter a choice and press <enter>: ");
|
||||
System.out.println("\t1. Find person details");
|
||||
System.out.println("\t2. Create a new person detail");
|
||||
System.out.println("\tq. Quit the application");
|
||||
System.out.print("Enter you choice: ");
|
||||
while (true) {
|
||||
final String input = scanner.nextLine();
|
||||
if("1".equals(input.trim()))
|
||||
getPersonDetails(scanner, personService);
|
||||
else if("2".equals(input.trim()))
|
||||
createPersonDetails(scanner,personService);
|
||||
else if("q".equals(input.trim()))
|
||||
break;
|
||||
else
|
||||
System.out.println("Invalid choice\n\n");
|
||||
LOGGER.info("\n========================================================="
|
||||
+ "\n "
|
||||
+ "\n Please press 'q + Enter' to quit the application. "
|
||||
+ "\n "
|
||||
+ "\n=========================================================" );
|
||||
|
||||
System.out.println("Please enter a choice and press <enter>: ");
|
||||
System.out.println("\t1. Find person details");
|
||||
System.out.println("\t2. Create a new person detail");
|
||||
System.out.println("\tq. Quit the application");
|
||||
System.out.print("Enter you choice: ");
|
||||
}
|
||||
System.out.println("Please enter a choice and press <enter>: ");
|
||||
System.out.println("\t1. Find person details");
|
||||
System.out.println("\t2. Create a new person detail");
|
||||
System.out.println("\tq. Quit the application");
|
||||
System.out.print("Enter you choice: ");
|
||||
while (true) {
|
||||
final String input = scanner.nextLine();
|
||||
if("1".equals(input.trim()))
|
||||
getPersonDetails(scanner, personService);
|
||||
else if("2".equals(input.trim()))
|
||||
createPersonDetails(scanner,personService);
|
||||
else if("q".equals(input.trim()))
|
||||
break;
|
||||
else
|
||||
System.out.println("Invalid choice\n\n");
|
||||
|
||||
LOGGER.info("Exiting application...bye.");
|
||||
System.out.println("Please enter a choice and press <enter>: ");
|
||||
System.out.println("\t1. Find person details");
|
||||
System.out.println("\t2. Create a new person detail");
|
||||
System.out.println("\tq. Quit the application");
|
||||
System.out.print("Enter you choice: ");
|
||||
}
|
||||
|
||||
System.exit(0);
|
||||
LOGGER.info("Exiting application...bye.");
|
||||
|
||||
}
|
||||
System.exit(0);
|
||||
|
||||
private static void createPersonDetails(final Scanner scanner,PersonService service) {
|
||||
while(true) {
|
||||
System.out.print("\nEnter the Person's name:");
|
||||
String name = scanner.nextLine();
|
||||
Gender gender;
|
||||
while(true) {
|
||||
System.out.print("Enter the Person's gender(M/F):");
|
||||
String genderStr = scanner.nextLine();
|
||||
if("m".equalsIgnoreCase(genderStr) || "f".equalsIgnoreCase(genderStr)) {
|
||||
gender = Gender.getGenderByIdentifier(genderStr.toUpperCase());
|
||||
break;
|
||||
}
|
||||
}
|
||||
Date dateOfBirth;
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
|
||||
while(true) {
|
||||
System.out.print("Enter the Person's Date of birth in DD/MM/YYYY format:");
|
||||
String dobStr = scanner.nextLine();
|
||||
try {
|
||||
}
|
||||
|
||||
private static void createPersonDetails(final Scanner scanner,PersonService service) {
|
||||
while(true) {
|
||||
System.out.print("\nEnter the Person's name:");
|
||||
String name = scanner.nextLine();
|
||||
Gender gender;
|
||||
while(true) {
|
||||
System.out.print("Enter the Person's gender(M/F):");
|
||||
String genderStr = scanner.nextLine();
|
||||
if("m".equalsIgnoreCase(genderStr) || "f".equalsIgnoreCase(genderStr)) {
|
||||
gender = Gender.getGenderByIdentifier(genderStr.toUpperCase());
|
||||
break;
|
||||
}
|
||||
}
|
||||
Date dateOfBirth;
|
||||
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
|
||||
while(true) {
|
||||
System.out.print("Enter the Person's Date of birth in DD/MM/YYYY format:");
|
||||
String dobStr = scanner.nextLine();
|
||||
try {
|
||||
dateOfBirth = format.parse(dobStr);
|
||||
break;
|
||||
} catch (ParseException e) {
|
||||
//Silently suppress and ask to enter details again
|
||||
}
|
||||
}
|
||||
|
||||
Person person = new Person();
|
||||
person.setDateOfBirth(dateOfBirth);
|
||||
person.setGender(gender);
|
||||
person.setName(name);
|
||||
person = service.createPerson(person);
|
||||
System.out.println("Created person record with id: " + person.getPersonId());
|
||||
System.out.print("Do you want to create another person? (y/n)");
|
||||
}
|
||||
}
|
||||
|
||||
Person person = new Person();
|
||||
person.setDateOfBirth(dateOfBirth);
|
||||
person.setGender(gender);
|
||||
person.setName(name);
|
||||
person = service.createPerson(person);
|
||||
System.out.println("Created person record with id: " + person.getPersonId());
|
||||
System.out.print("Do you want to create another person? (y/n)");
|
||||
String choice = scanner.nextLine();
|
||||
if(!"y".equalsIgnoreCase(choice))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param service
|
||||
* @param input
|
||||
@@ -154,18 +153,18 @@ public final class Main {
|
||||
for(Person person:personList) {
|
||||
System.out.print(
|
||||
String.format("Person found - Person Id: '%d', Person Name is: '%s', Gender: '%s'",
|
||||
person.getPersonId(),person.getName(), person.getGender()));
|
||||
person.getPersonId(),person.getName(), person.getGender()));
|
||||
System.out.println(String.format(", Date of birth: '%1$td/%1$tm/%1$tC%1$ty'", person.getDateOfBirth()));
|
||||
}
|
||||
} else {
|
||||
System.out.println(
|
||||
String.format("No Person record found for name: '%s'.", input));
|
||||
}
|
||||
}
|
||||
System.out.print("Do you want to find another person? (y/n)");
|
||||
String choice = scanner.nextLine();
|
||||
if(!"y".equalsIgnoreCase(choice))
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
28
basic/jdbc/src/main/resources/log4j.xml
Normal file
28
basic/jdbc/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