2011-01-21 8 views
7

Controllando l'output del registro di IntelliJ IDEA, ho notato che l'allineamento era molto bello (dovuto tra l'altro al fatto che i nomi delle classi sono allineati e tagliati correttamente).log4j allineamento

Come si fa a utilizzare log4J? Hai bisogno di un appender speciale?

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... 

risposta

9

Si può fare questo con PatternLayout. Ad esempio, è possibile definire la categoria logger come:

%20.20c 

questo potrebbe causare il campo per essere sempre esattamente 20 caratteri estesi, sinistra-padding con spazi se il valore è inferiore a 20 caratteri, e troncando se maggiore di 20.

Il PatternLayout per i registri della tua domanda potrebbe essere qualcosa di simile:

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