Linux
RHEL 7.3 syslog 輸出文本換行,沒有新行
當我
cat
的文件,例如/var/log/messages
輸出沒有分隔成新行時,它只是一個很難閱讀的包裝文本,只是一條又一條的消息,沒有新行。是否有某個設置會導致這種情況發生,它發生在我們的幾台伺服器上。舉個例子
當我跑步時,
cat /var/log/messages
我希望看到類似的東西:2016-12-15T11:22:53.212028-06:00 wilkestest.com ntpd[27156]: 0.0.0.0 c615 05 clock_sync 2016-12-15T11:22:54.223136-06:00 wilkestest.com ntpd[27156]: 0.0.0.0 c618 08 no_sys_peer 2016-12-15T11:25:06.228173-06:00 wilkestest.com ntpd[27156]: 0.0.0.0 0628 08 no_sys_peer 2016-12-15T11:25:12.233785-06:00 wilkestest.com ntpd[27156]: 0.0.0.0 0613 03 spike_detect +0.294933 s 2016-12-15T11:29:41.762442-06:00 wilkestest.com kernel: [212901.427412] FS-Cache: Loaded 2016-12-15T11:29:41.771893-06:00 wilkestest.com kernel: [212901.439186] FS-Cache: Netfs 'nfs' registered for caching 2016-12-15T11:29:41.775520-06:00 wilkestest.com kernel: [212901.443275] Key type dns_resolver registered 2016-12-15T11:29:41.784809-06:00 wilkestest.com kernel: [212901.452136] NFS: Registering the id_resolver key type 2016-12-15T11:29:41.784814-06:00 wilkestest.com kernel: [212901.452141] Key type id_resolver registered 2016-12-15T11:29:41.784817-06:00 wilkestest.com kernel: [212901.452142] Key type id_legacy registered
相反,我看到的是:
2016-12-15T11:22:53.212028-06:00 wilkestest.com ntpd[27156]: 0.0.0.0 c615 05 clock_sync 2016-12-15T11:22:54.223136-06:00 wilkestest.com ntpd[27156]: 0.0.0.0 c618 08 no_sys_peer 2016-12-15T11:25:06.228173-06:00 wilkestest.com ntpd[27156]: 0.0.0.0 0628 08 no_sys_peer 2016-12-15T11:25:12.233785-06:00 wilkestest.com ntpd[27156]: 0.0.0.0 0613 03 spike_detect +0.294933 s 2016-12-15T11:29:41.762442-06:00 wilkestest.com kernel: [212901.427412] FS-Cache: Loaded 2016-12-15T11:29:41.771893-06:00 wilkestest.com kernel: [212901.439186] FS-Cache: Netfs 'nfs' registered for caching 2016-12-15T11:29:41.775520-06:00 wilkestest.com kernel: [212901.443275] Key type dns_resolver registered 2016-12-15T11:29:41.784809-06:00 wilkestest.com kernel: [212901.452136] NFS: Registering the id_resolver key type 2016-12-15T11:29:41.784814-06:00 wilkestest.com kernel: [212901.452141] Key type id_resolver registered 2016-12-15T11:29:41.784817-06:00 wilkestest.com kernel: [212901.452142] Key type id_legacy registered
新行的格式被誇大了,我不希望有一個雙倍行距的日誌文件,但我希望日誌中的每條新消息都從一個新日誌開始,而不僅僅是最後一條消息後面的空格。
我想出了答案,只是想在這裡發布,以防它可以幫助其他人。在 /etc/rsyslog.conf 中有一個 $ActionFileDefaultTemplate 的參數設置為 RSYSLOG_ForwardFormat ,它給出了更精確的日期,但在每條消息中刪除了 \n,使用 RSYSLOG_FileFormat 或 RSYSLOG_TraditionalFileFormat 因為該參數將解析被混合在一起的行.