Skip to content

Instantly share code, notes, and snippets.

@juven
Created December 13, 2013 15:38
Show Gist options
  • Save juven/7946091 to your computer and use it in GitHub Desktop.
Save juven/7946091 to your computer and use it in GitHub Desktop.
(ns clj-demo.analyze-log
(:require [clojure.java.io :as io]
[clj-time.format :as fmt]))
; sample lines in httpd.log
; 50.16.207.27 - - [03/Jul/2011:22:03:46 -0500] "GET /........."
; somple out
; #<DateTime 2011-07-04T03:03:46.000Z>
(def httpd-format (fmt/formatter "[dd/MMM/yyyy:HH:mm:ss Z]"))
(defn parse-time [line]
(fmt/parse httpd-format
(re-find #"\[.+\]" line)))
(with-open [reader (io/reader (io/resource "httpd.log"))]
(doseq [line (line-seq reader)]
(println (parse-time line))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment