2011-01-21 28 views
7

Bằng cách kiểm tra đầu ra nhật ký của IntelliJ IDEA, tôi nhận thấy sự liên kết rất đẹp (do khác với thực tế là tên lớp được căn chỉnh đúng và cắt).liên kết log4j

Bạn làm điều này bằng cách sử dụng log4J như thế nào? Bạn có cần một appender đặc biệt?

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

Trả lời

9

Bạn có thể thực hiện việc này với PatternLayout. Ví dụ, bạn có thể xác định loại logger như:

%20.20c 

Điều này sẽ gây lĩnh vực này luôn được chính xác 20 ký tự rộng, trái đệm với không gian nếu giá trị nhỏ hơn 20 ký tự, và cắt bỏ nó nếu lớn hơn hơn 20.

các PatternLayout cho các bản ghi trong câu hỏi của bạn có thể là một cái gì đó như:

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