我找不到一个能够以比通常更好的方式格式化日志输出语句的库。我记得其中一个功能是,它可以根据日志语句出现的“嵌套程度”来“偏移”日志消息。
也就是说,不是这样:
DEBUG | DefaultBeanDefinitionDocumentReader.java| 86 | Loading bean definitions
DEBUG | AbstractAutowireCapableBeanFactory.java| 411 | Finished creating instance of bean 'MS-SQL'
DEBUG | DefaultSingletonBeanRegistry.java| 213 | Creating shared instance of singleton bean 'MySQL'
DEBUG | AutowireCapableBeanFactory.java| 383 | Creating instance of bean 'MySQL'
DEBUG | AutowireCapableBeanFactory.java| 459 | Eagerly caching bean 'MySQL' to allow for resolving potential circular references
DEBUG | AutowireCapableBeanFactory.java| 789 | Another debug message
它会显示类似于这样的内容:
DEBUG | DefaultBeanDefinitionDocumentReader.java| 86 | Loading bean definitions
DEBUG | AbstractAutowireCapableBeanFactory.java | 411 | Finished creating instance of bean 'MS-SQL'
DEBUG | DefaultSingletonBeanRegistry.java | 213 | Creating shared instance of singleton bean 'MySQL'
DEBUG | AutowireCapableBeanFactory.java | 383 | Creating instance of bean 'MySQL'
DEBUG | AutowireCapableBeanFactory.java | 459 | |__ Eagerly caching bean 'MySQL' to allow for resolving potential circular references
DEBUG | AutowireCapableBeanFactory.java | 789 | |__ Another debug message
这是我刚编造的一个例子(非常长的驼峰类名不是我的)。但我记得看过这样干净格式化的日志输出,它们比我以前见过的任何东西都要好,而且除了更加美观之外,它们还更容易阅读,因为它们再现了代码的某些逻辑组织。
然而,我现在找不到那个库了。
我很确定它完全兼容于log4j或sl4j。