0

我正在尝试将我的应用程序配置为不使用log4j.properties,而是用于BasicConfigurator配置我在log4j.properties. 我无法弄清楚如何设置文件的位置,但没有成功。

Logger log = Logger.getLogger(pjp.getSignature().getDeclaringTypeName());
PatternLayout layout = new PatternLayout();
FileAppender familyservices = new FileAppender();

familyservices.setLayout(layout);
familyservices.setName("com.cambiahealth.engine.rest.family");
familyservices.setFile("/usr/regence/logs/datasvc/v1.0/familyservice.log");
log.addAppender(familyservices);

BasicConfigurator.configure(familyservices);
4

1 回答 1

2
ConsoleAppender console = new ConsoleAppender(); //create appender
  //configure the appender
  String PATTERN = "%d [%p|%c|%C{1}] %m%n";
  console.setLayout(new PatternLayout(PATTERN)); 
  console.setThreshold(Level.FATAL);
  console.activateOptions();
  //add appender to any Logger (here is root)
  Logger.getRootLogger().addAppender(console);

  FileAppender fa = new FileAppender();
  fa.setName("FileLogger");
  fa.setFile("mylog.log");
  fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
  fa.setThreshold(Level.DEBUG);
  fa.setAppend(true);
  fa.activateOptions();

  /add appender to any Logger (here is root)
  Logger.getRootLogger().addAppender(fa)
  //repeat with all other desired appenders
于 2013-06-02T15:30:45.923 回答