|
SSISO Community검색 |
|
SSISO Community메뉴 |
|
SSISO Community카페 |
|
블로그 카테고리 |
|
|
Log4j로 검색한 결과 |
|
등록일:2008-03-14 09:34:27 작성자: 제목:log4j: advanced log |
|
/*
Logging In Java with the JDK 1.4 Logging API and Apache Log4j
by Samudra Gupta
Apress Copyright 2003
ISBN:1590590996
*/
import org.apache.Log4j.Logger;
import org.apache.Log4j.NDC;
public class AdvancedLogging {
private static Logger logger = Logger.getLogger("name");
private String userName = null;
private double balance;
/** Creates a new instance of AdvancedLogging */
public AdvancedLogging(String user) {
this.userName = user;
}
/**
* Deposit some amount
*/
public void deposit(double amount) {
NDC.push(userName);
balance += amount;
logger.info("Deposited " + amount + " new balance: " + balance);
NDC.pop();
}
/**
* withdraw some amount
*/
public void withdraw(double amount) {
NDC.push(userName);
if (balance >= amount) {
balance -= amount;
logger.info("Withdrawn " + amount + " new balance: " + balance);
} else {
System.out.println("Not enough balance");
logger.error("Failed to withdraw: balance: " + balance
+ " attempted withdraw: " + amount);
}
NDC.pop();
}
public static void main(String args[]) {
AdvancedLogging demo = new AdvancedLogging("sam");
demo.deposit(100.50);
demo.withdraw(80);
demo.withdraw(50);
}
} |
|
|
|
|
|