自定义封装Logger demo 小测试

  • 时间:
  • 浏览:4
  • 来源:5分3D_5分排列5

3》Logger文件

public static Logger getLogger() {

     public void error(Object info, Throwable t){

return new Logger(c);

public static void main(String[] args) {

private static void reload() {

测试通过,但貌似可用,不过log4j源码貌似强大应用场景

public boolean isInfoEnabled() {

private Logger(Class c) {

import org.apache.commons.logging.Log;

public void warn(String info) {

public boolean isFatalEnabled() {

public class test {

static Logger log = Logger.getLogger(test.class);

1》  log4j.properties 文件:

System.out.println("***********************");

public void error(String info) {

public boolean isDebugEnabled() {

public boolean isTraceEnabled() {

public void debug(String info) {

System.out.println("log4j configfile path=" + path);

public boolean isWarnEnabled() {

public void setReload(boolean flag) {

log4j.appender.file=org.apache.log4j.RollingFileAppender

log4j.rootLogger=DEBUG,MINA,file

### 控制台 ###

public static Logger getLogger(Class c) {

public void info(String info) {

public boolean isErrorEnabled() {

public static Logger getLogger(String className) {

public static void main(String[] args) {

4:测试 

private Logger() {

2》Log4jConfig:

public class Logger {

import org.apache.log4j.PropertyConfigurator;

public class Log4jConfig {

private static boolean isReload = true;

/**

public void trace(String info) {

private Logger(String className) {

log4j.appender.MINA=org.apache.log4j.ConsoleAppender