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:
Gunnar Hillert
2012-05-14 15:38:35 -04:00
committed by Gary Russell
parent 218668cb9c
commit fc2e5890a9
73 changed files with 1208 additions and 1105 deletions

View File

@@ -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");
}
}
}
}

View File

@@ -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");
}

View 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>

View File

@@ -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>