2015-02-24 47 views
0

我有一個代碼,並得到一個系統日誌消息是這樣的:如何將一個系統日誌消息寫入一個數組?

May 11 10:40:48 scrooge disk-health-nurse[26783]: [ID 702911 user.error] m:SY-mon-full-500 c:H : partition health measures for /var did not suffice - still using 96% of partition space 

有沒有在我能夠把這個代碼陣列在這樣的代碼:

array [0] = May 11 10:40:48 
array [1] = scrooge 
array [2] = scrooge disk-health-nurse[26783]: 
array [3] = [ID 702911 user.error] 
array [4] = m:SY-mon-full-500 
array [5] = c:H : partition health measures for /var did not suffice - still using 96% of partition space 

回答

0

你必須使用您創建這些消息的業務規則知識編寫定製解析器。沒有任何魔術代碼可以幫助你,以及任何知道你想要解析的所有可能字符串的程序員。 你不能只用分隔符來分割這一行。

+0

聽起來很邏輯。但是如果String中有一部分可能是DateTime-Object,那麼是不是有一種要求完整字符串的代碼? – semaxx 2015-02-24 12:55:00

+0

是的。如果您知道DateTime實例的格式,則必須使用Regex。例如,請參閱http://stackoverflow.com/questions/14917203/finding-if-a-string-contains-a-date-and-time。 – EngineerSpock 2015-02-24 12:56:51

相關問題