java - log4j对齐

标签 java log4j alignment right-align

通过检查 IntelliJ IDEA 的日志输出,我注意到对齐非常好(其中一个原因是类名是右对齐和修剪的)。

如何使用 log4J 执行此操作?你需要一个特殊的 appender 吗?

2011-01-08 00:48:53,938 [   2537]   INFO - ellij.vfs.persistent.FSRecords - Marking VFS as corrupted 
2011-01-08 00:48:53,987 [   2586]   INFO - api.vfs.impl.local.FileWatcher - Native file watcher is operational. 
2011-01-08 00:48:54,034 [   2633]   INFO - s.impl.stores.FileBasedStorage - Document was not loaded for $APP_CONFIG$/other.xml file is null 
2011-01-08 00:48:54,035 [   2634]   INFO - .impl.stores.XmlElementStorage - Document was not loaded for $APP_CONFIG$/other.xml 
2011-01-08 00:48:54,046 [   2645]   INFO - s.impl.stores.FileBasedStorage - Document was not loaded for $APP_CONFIG$/project.default.xml file is null 
2011-01-08 00:48:54,047 [   2646]   INFO - .impl.stores.XmlElementStorage - Document was not loaded for $APP_CONFIG$/project.default.xml 
2011-01-08 00:48:54,051 [   2650]   INFO - s.impl.stores.FileBasedStorage - Document was not loaded for $APP_CONFIG$/options.xml file is null 
2011-01-08 00:48:54,051 [   2650]   INFO - .impl.stores.XmlElementStorage - Document was not loaded for $APP_CONFIG$/options.xml 
2011-01-08 00:48:54,295 [   2894]   INFO - s.impl.stores.FileBasedStorage - Document was not loaded for $APP_CONFIG$/filetypes.xml file is null 
2011-01-08 00:48:54,295 [   2894]   INFO - .impl.stores.XmlElementStorage - Document was not loaded for $APP_CONFIG$/filetypes.xml 
2011-01-08 00:48:54,342 [   2941]   INFO - .history.utils.LocalHistoryLog - local history version mismatch (was: 0, expected: 5), rebuilding... 
2011-01-08 00:48:54,342 [   2941]   INFO - .history.utils.LocalHistoryLog - FS has been rebuild, rebuilding local history... 

最佳答案

您可以使用 PatternLayout 执行此操作.例如,您可以将记录器类别定义为:

%20.20c

这会导致字段始终恰好为 20 个字符宽,如果值小于 20 个字符则用空格向左填充,如果大于 20 个字符则将其截断。

您问题中日志的 PatternLayout 可能类似于:

%d [%7.7r] %6.6p - %c{30} - %m%n

关于java - log4j对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4763988/

相关文章:

java - 在 Java EE 应用程序中显示错误消息时出现意外结果(字段为空时不会出现错误)

JavaFx自定义条形图鼠标事件未触发

java - 检查powerpoint是否已经在Java中打开?

java - 在对 JSP 隐式对象的属性进行强制转换时,我应该添加 try/catch around 吗?

java - ClassCastException : org. slf4j.impl.Log4jLoggerAdapter 无法转换为 ch.qos.logback.classic.Logger

java - Log4j 突然停止记录

javascript - 如何设置 document.documentElement.innerHTML = 'TEXT' 对齐;

java - 如何将 log4j 日志记录集成到我的客户端-服务器程序中?

html - CSS-Grid 列未正确对齐

html - 网格元素具有不同的高度