log4j multiple logFactory/logRepository

原创
2017/06/12 17:37
阅读数 154

多个log4j实例:

public class DefaultCoreLogRepository implements InitializingBean {
    @Autowired
    private ConfigService configService;

    private LoggerRepository repository;

    public Logger getLogger(Class<?> type) {
        Logger logger = repository.getLogger(type.getName());
        return logger;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Hierarchy h = new Hierarchy(new RootLogger(Level.DEBUG));
        RepositorySelector repositorySelector = new DefaultRepositorySelector(h);
        repository = repositorySelector.getLoggerRepository();
        String path = configService.getResourcesRootPath() + "coreLogService.properties";
        PropertyConfigurator propertyConfigurator = new PropertyConfigurator();
        propertyConfigurator.doConfigure(path, repository);
    }
}

another log service:

@Component
@Scope("singleton")
public class DefaultLogRepository implements InitializingBean {
    @Autowired
    private ConfigService configService;

    private LoggerRepository repository;

    public Logger getLogger(Class<?> type) {
        Logger logger = repository.getLogger(type.getName());
        return logger;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Hierarchy h = new Hierarchy(new RootLogger(Level.DEBUG));
        RepositorySelector repositorySelector = new DefaultRepositorySelector(h);
        repository = repositorySelector.getLoggerRepository();
        String path = configService.getResourcesRootPath() + "logService.properties";
        PropertyConfigurator propertyConfigurator = new PropertyConfigurator();
        propertyConfigurator.doConfigure(path, repository);
    }
}

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部