使用记录正则表达式解析一行日志
(defrecord Logline [datetime action user id])
(def pattern #"(\d{8}-\d{2}:\d{2}:\d{2}.\d{3})\|.*\|(\w*),(\w*),(\d*)")
(defn parser [line]
(if-let [[_ dt a u i] (re-find pattern line)]
(->Logline dt a u i)))
定义一个示例行:
(def sample "20170426-17:20:04.005|bip.com|1.0.0|alert|Update,john,12")
测试一下:
(parser sample)
结果:
#user.Logline{:datetime "20170426-17:20:04.005", :action "Update", :user "john", :id "12"}