alphordered includes, standardised on use 'log' as alias for timbre.
This commit is contained in:
Simon Brooke 2020-02-12 21:13:36 +00:00
parent 0d686a9b63
commit 2f22b733c1
No known key found for this signature in database
GPG key ID: A7A4F18D1D4DF987
8 changed files with 62 additions and 42 deletions

View file

@ -5,7 +5,7 @@
[environ.core :refer [env]] [environ.core :refer [env]]
[noir.io :as io] [noir.io :as io]
[smeagol.configuration :refer [config]] [smeagol.configuration :refer [config]]
[taoensso.timbre :as timbre])) [taoensso.timbre :as log]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; ;;;;
@ -52,7 +52,7 @@
"Return `true` if this `username`/`password` pair match, `false` otherwise" "Return `true` if this `username`/`password` pair match, `false` otherwise"
[username password] [username password]
(let [user ((keyword username) (get-users))] (let [user ((keyword username) (get-users))]
(timbre/info (str "Authenticating " username " against " password-file-path)) (log/info (str "Authenticating " username " against " password-file-path))
(and user (and user
(:password user) (:password user)
(or (or
@ -92,7 +92,7 @@
Return `true` if password was successfully changed. Subsequent to user change, their Return `true` if password was successfully changed. Subsequent to user change, their
password will be encrypted." password will be encrypted."
[username oldpass newpass] [username oldpass newpass]
(timbre/info (format "Changing password for user %s" username)) (log/info (format "Changing password for user %s" username))
(let [users (get-users) (let [users (get-users)
keywd (keyword username) keywd (keyword username)
user (keywd users) user (keywd users)
@ -110,10 +110,10 @@
{keywd {keywd
(merge user (merge user
{:password (password/encrypt newpass)})}))) {:password (password/encrypt newpass)})})))
(timbre/info (str "Successfully changed password for user " username)) (log/info (str "Successfully changed password for user " username))
true)) true))
(catch Exception any (catch Exception any
(timbre/error any (log/error any
(format "Changing password failed for user %s failed: %s (%s)" (format "Changing password failed for user %s failed: %s (%s)"
username (.getName (.getClass any)) (.getMessage any))) username (.getName (.getClass any)) (.getMessage any)))
false)))) false))))
@ -138,7 +138,7 @@
`email` address and `admin` flag; *or*, modify an existing user. Return true `email` address and `admin` flag; *or*, modify an existing user. Return true
if user is successfully stored, false otherwise." if user is successfully stored, false otherwise."
[username newpass email admin] [username newpass email admin]
(timbre/info "Trying to add user " username) (log/info "Trying to add user " username)
(cond (cond
(not (string? username)) (throw (Exception. "Username must be a string.")) (not (string? username)) (throw (Exception. "Username must be a string."))
(zero? (count username)) (throw (Exception. "Username cannot be zero length")) (zero? (count username)) (throw (Exception. "Username cannot be zero length"))
@ -160,10 +160,10 @@
(locking password-file-path (locking password-file-path
(spit password-file-path (spit password-file-path
(assoc users (keyword username) (merge user full-details))) (assoc users (keyword username) (merge user full-details)))
(timbre/info "Successfully added user " username) (log/info "Successfully added user " username)
true) true)
(catch Exception any (catch Exception any
(timbre/error any (log/error any
(format "Adding user %s failed: %s (%s)" (format "Adding user %s failed: %s (%s)"
username (.getName (.getClass any)) (.getMessage any))) username (.getName (.getClass any)) (.getMessage any)))
false))))) false)))))
@ -177,10 +177,10 @@
(locking password-file-path (locking password-file-path
(spit password-file-path (spit password-file-path
(dissoc users (keyword username))) (dissoc users (keyword username)))
(timbre/info (str "Successfully deleted user " username)) (log/info (str "Successfully deleted user " username))
true) true)
(catch Exception any (catch Exception any
(timbre/error any (log/error any
(format "Deleting user %s failed: %s (%s)" (format "Deleting user %s failed: %s (%s)"
username (.getName (.getClass any)) (.getMessage any))) username (.getName (.getClass any)) (.getMessage any)))
false)))) false))))

View file

@ -5,7 +5,7 @@
[clojure.string :as s] [clojure.string :as s]
[environ.core :refer [env]] [environ.core :refer [env]]
[noir.io :as io] [noir.io :as io]
[taoensso.timbre :as timbre])) [taoensso.timbre :as log]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; ;;;;
@ -73,7 +73,7 @@
and optionally a key :transform, whose value is a function of one and optionally a key :transform, whose value is a function of one
argument to be used to transform the value of that key." argument to be used to transform the value of that key."
[m tuples] [m tuples]
(timbre/debug (log/debug
"transform-map:\n" "transform-map:\n"
(with-out-str (clojure.pprint/pprint m))) (with-out-str (clojure.pprint/pprint m)))
(reduce (reduce
@ -112,11 +112,11 @@
file is read (if it is specified and present), but that individual file is read (if it is specified and present), but that individual
values can be overridden by environment variables." values can be overridden by environment variables."
(try (try
(timbre/info (str "Reading configuration from " config-file-path)) (log/info (str "Reading configuration from " config-file-path))
(let [file-contents (try (let [file-contents (try
(read-string (slurp config-file-path)) (read-string (slurp config-file-path))
(catch Exception x (catch Exception x
(timbre/error (log/error
(str (str
"Failed to read configuration from " "Failed to read configuration from "
config-file-path config-file-path
@ -138,12 +138,12 @@
:smeagol-site-title) :smeagol-site-title)
config-env-transforms))] config-env-transforms))]
(if (env :dev) (if (env :dev)
(timbre/debug (log/debug
"Loaded configuration\n" "Loaded configuration\n"
(with-out-str (clojure.pprint/pprint config)))) (with-out-str (clojure.pprint/pprint config))))
config) config)
(catch Exception any (catch Exception any
(timbre/error any "Could not load configuration") (log/error any "Could not load configuration")
{}))) {})))
(def config (build-config)) (def config (build-config))

View file

@ -44,6 +44,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Error to show if text to be rendered is nil. ;; Error to show if text to be rendered is nil.
;; TODO: this should go through i18n
(def no-text-error "No text: does the file exist?") (def no-text-error "No text: does the file exist?")
@ -150,28 +151,43 @@
;; I need to put the backticks back in. ;; I need to put the backticks back in.
remarked (if (odd? index) (str "```" fragment "\n```") fragment) remarked (if (odd? index) (str "```" fragment "\n```") fragment)
first-token (get-first-token fragment) first-token (get-first-token fragment)
kw (if-not (empty? first-token) (keyword first-token))
formatter (if-not formatter (if-not
(empty? first-token) (empty? first-token)
(try (try
(let [kw (keyword first-token)] (read-string (-> config :formatters kw :formatter))
(read-string (-> config :formatters kw :formatter)))
(catch Exception _ (catch Exception _
(do (do
(log/info "No formatter found for extension `" first-token "`") (log/info "No formatter found for extension `" kw "`")
;; no extension registered - there sometimes won't be, ;; no extension registered - there sometimes won't be,
;; and it doesn't matter ;; and it doesn't matter
nil))))] nil))))]
(cond (cond
(empty? fragments) (empty? fragments)
;; We've come to the end of the list of fragments. Reassemble them into
;; a single HTML text and pass it back.
(assoc result :text (assoc result :text
(local-links (local-links
(md/md-to-html-string (md/md-to-html-string
(cs/join "\n\n" (reverse processed)) (cs/join "\n\n" (reverse processed))
:heading-anchors true))) :heading-anchors true)))
formatter formatter
(apply-formatter index result fragments processed fragment first-token formatter) ;; We've found a formatter to apply to the current fragment, and recurse
;; on down the list
(let [result (apply-formatter
index
result
fragments
processed
fragment
first-token
formatter)]
(assoc result :extensions (cons kw (:extensions result))))
true true
(process-markdown-fragment index result remarked (rest fragments) processed))))) ;; Otherwise process the current fragment as markdown and recurse on
;; down the list
(process-markdown-fragment
index result remarked (rest fragments) processed)))))
(defn reintegrate-inclusions (defn reintegrate-inclusions
@ -182,6 +198,10 @@
([inclusions text] ([inclusions text]
(let [ks (keys inclusions)] (let [ks (keys inclusions)]
(if (empty? (keys inclusions)) (if (empty? (keys inclusions))
;; TODO: this is one opportunity to add scripts at the end of the
;; constructed text. I've a feeling that that would be a mistake and
;; that instead we should hand back a map comprising the text and the
;; keys of the extensions
text text
(let [kw (first ks)] (let [kw (first ks)]
(reintegrate-inclusions (reintegrate-inclusions

View file

@ -16,7 +16,7 @@
[smeagol.routes.wiki :refer [wiki-routes]] [smeagol.routes.wiki :refer [wiki-routes]]
[smeagol.middleware :refer [load-middleware]] [smeagol.middleware :refer [load-middleware]]
[smeagol.session-manager :as session-manager] [smeagol.session-manager :as session-manager]
[taoensso.timbre :as timbre] [taoensso.timbre :as log]
[taoensso.timbre.appenders.3rd-party.rotor :as rotor])) [taoensso.timbre.appenders.3rd-party.rotor :as rotor]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -55,9 +55,9 @@
"destroy will be called when your application "destroy will be called when your application
shuts down, put any clean up code here" shuts down, put any clean up code here"
[] []
(timbre/info "smeagol is shutting down...") (log/info "smeagol is shutting down...")
(cronj/shutdown! session-manager/cleanup-job) (cronj/shutdown! session-manager/cleanup-job)
(timbre/info "shutdown complete!")) (log/info "shutdown complete!"))
(defn init (defn init
@ -67,7 +67,7 @@
put any initialization code here" put any initialization code here"
[] []
(try (try
(timbre/merge-config! (log/merge-config!
{:appenders {:appenders
{:rotor (rotor/rotor-appender {:rotor (rotor/rotor-appender
{:path "smeagol.log" {:path "smeagol.log"
@ -80,10 +80,10 @@
(cronj/start! session-manager/cleanup-job) (cronj/start! session-manager/cleanup-job)
(if (env :dev) (parser/cache-off!)) (if (env :dev) (parser/cache-off!))
;;start the expired session cleanup job ;;start the expired session cleanup job
(timbre/info "\n-=[ smeagol started successfully" (log/info "\n-=[ smeagol started successfully"
(when (env :dev) "using the development profile") "]=-") (when (env :dev) "using the development profile") "]=-")
(catch Exception any (catch Exception any
(timbre/error any "Failure during startup") (log/error any "Failure during startup")
(destroy)))) (destroy))))
;; timeout sessions after 30 minutes ;; timeout sessions after 30 minutes

View file

@ -1,10 +1,10 @@
(ns ^{:doc "Explore the history of a page." (ns ^{:doc "Explore the history of a page."
:author "Simon Brooke"} :author "Simon Brooke"}
smeagol.history smeagol.history
(:require [taoensso.timbre :as timbre] (:require [clj-jgit.porcelain :as git]
[clj-jgit.porcelain :as git]
[clj-jgit.internal :as i] [clj-jgit.internal :as i]
[clj-jgit.querying :as q]) [clj-jgit.querying :as q]
[taoensso.timbre :as log])
(:import [org.eclipse.jgit.api Git] (:import [org.eclipse.jgit.api Git]
[org.eclipse.jgit.lib Repository ObjectId] [org.eclipse.jgit.lib Repository ObjectId]
[org.eclipse.jgit.revwalk RevCommit RevTree RevWalk] [org.eclipse.jgit.revwalk RevCommit RevTree RevWalk]
@ -39,7 +39,7 @@
"If this `log-entry` contains a reference to this `file-path`, return the entry; "If this `log-entry` contains a reference to this `file-path`, return the entry;
else nil." else nil."
[^String log-entry ^String file-path] [^String log-entry ^String file-path]
(timbre/info (format "searching '%s' for '%s'" log-entry file-path)) (log/info (format "searching '%s' for '%s'" log-entry file-path))
(cond (cond
(seq (filter (fn* [p1__341301#] (= (first p1__341301#) file-path)) (:changed_files log-entry))) (seq (filter (fn* [p1__341301#] (= (first p1__341301#) file-path)) (:changed_files log-entry)))
log-entry)) log-entry))
@ -54,6 +54,7 @@
(try (try
(git/load-repo git-directory-path) (git/load-repo git-directory-path)
(catch java.io.FileNotFoundException fnf (catch java.io.FileNotFoundException fnf
(log/info "Initialising Git repository at" git-directory-path)
(git/git-init git-directory-path) (git/git-init git-directory-path)
(let [repo (git/load-repo git-directory-path)] (let [repo (git/load-repo git-directory-path)]
(git/git-add-and-commit repo "Initial commit") (git/git-add-and-commit repo "Initial commit")

View file

@ -12,8 +12,7 @@
[selmer.parser :as parser] [selmer.parser :as parser]
[smeagol.configuration :refer [config]] [smeagol.configuration :refer [config]]
[smeagol.sanity :refer :all] [smeagol.sanity :refer :all]
[smeagol.util :as util] [smeagol.util :as util]))
[taoensso.timbre :as timbre]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; ;;;;

View file

@ -1,17 +1,17 @@
(ns ^{:doc "In truth, boilerplate provided by LuminusWeb." (ns ^{:doc "In truth, boilerplate provided by LuminusWeb."
:author "Simon Brooke"} :author "Simon Brooke"}
smeagol.middleware smeagol.middleware
(:require [taoensso.timbre :as timbre] (:require [environ.core :refer [env]]
[environ.core :refer [env]] [noir-exception.core :refer [wrap-internal-error]]
[selmer.middleware :refer [wrap-error-page]]
[prone.middleware :refer [wrap-exceptions]] [prone.middleware :refer [wrap-exceptions]]
[ring.middleware.anti-forgery :refer [wrap-anti-forgery]] [ring.middleware.anti-forgery :refer [wrap-anti-forgery]]
[ring.middleware.file :refer [wrap-file]] [ring.middleware.file :refer [wrap-file]]
[ring.middleware.resource :refer [wrap-resource]] [ring.middleware.resource :refer [wrap-resource]]
[ring.middleware.content-type :refer [wrap-content-type]] [ring.middleware.content-type :refer [wrap-content-type]]
[ring.middleware.not-modified :refer [wrap-not-modified]] [ring.middleware.not-modified :refer [wrap-not-modified]]
[noir-exception.core :refer [wrap-internal-error]] [selmer.middleware :refer [wrap-error-page]]
[smeagol.util :as util])) [smeagol.util :as util]
[taoensso.timbre :as log]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; ;;;;
@ -39,7 +39,7 @@
(defn log-request [handler] (defn log-request [handler]
(fn [req] (fn [req]
(timbre/debug req) (log/debug req)
(handler req))) (handler req)))
@ -49,7 +49,7 @@
(def production-middleware (def production-middleware
[#(wrap-internal-error % :log (fn [e] (timbre/error e))) [#(wrap-internal-error % :log (fn [e] (log/error e)))
#(wrap-resource % "public") #(wrap-resource % "public")
#(wrap-file % util/content-dir #(wrap-file % util/content-dir
{:index-files? false :prefer-handler? true}) {:index-files? false :prefer-handler? true})

View file

@ -10,7 +10,7 @@
[smeagol.authenticate :as auth] [smeagol.authenticate :as auth]
[smeagol.configuration :refer [config]] [smeagol.configuration :refer [config]]
[smeagol.formatting :refer [md->html]] [smeagol.formatting :refer [md->html]]
[taoensso.timbre :as timbre])) [taoensso.timbre :as log]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; ;;;;
@ -69,7 +69,7 @@
messages (try messages (try
(i18n/get-messages specifier "i18n" "en-GB") (i18n/get-messages specifier "i18n" "en-GB")
(catch Exception any (catch Exception any
(timbre/error (log/error
any any
(str (str
"Failed to parse accept-language header '" "Failed to parse accept-language header '"