Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
alphordered includes, standardised on use 'log' as alias for timbre.
  • Loading branch information
simon-brooke committed Feb 12, 2020
1 parent 0d686a9 commit 2f22b73
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 42 deletions.
20 changes: 10 additions & 10 deletions src/smeagol/authenticate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[environ.core :refer [env]]
[noir.io :as io]
[smeagol.configuration :refer [config]]
[taoensso.timbre :as timbre]))
[taoensso.timbre :as log]))

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

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

(def config (build-config))
30 changes: 25 additions & 5 deletions src/smeagol/formatting.clj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; 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?")


Expand Down Expand Up @@ -150,28 +151,43 @@
;; I need to put the backticks back in.
remarked (if (odd? index) (str "```" fragment "\n```") fragment)
first-token (get-first-token fragment)
kw (if-not (empty? first-token) (keyword first-token))
formatter (if-not
(empty? first-token)
(try
(let [kw (keyword first-token)]
(read-string (-> config :formatters kw :formatter)))
(read-string (-> config :formatters kw :formatter))
(catch Exception _
(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,
;; and it doesn't matter
nil))))]
(cond
(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
(local-links
(md/md-to-html-string
(cs/join "\n\n" (reverse processed))
:heading-anchors true)))
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
(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
Expand All @@ -182,6 +198,10 @@
([inclusions text]
(let [ks (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
(let [kw (first ks)]
(reintegrate-inclusions
Expand Down
12 changes: 6 additions & 6 deletions src/smeagol/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[smeagol.routes.wiki :refer [wiki-routes]]
[smeagol.middleware :refer [load-middleware]]
[smeagol.session-manager :as session-manager]
[taoensso.timbre :as timbre]
[taoensso.timbre :as log]
[taoensso.timbre.appenders.3rd-party.rotor :as rotor]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -55,9 +55,9 @@
"destroy will be called when your application
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)
(timbre/info "shutdown complete!"))
(log/info "shutdown complete!"))


(defn init
Expand All @@ -67,7 +67,7 @@
put any initialization code here"
[]
(try
(timbre/merge-config!
(log/merge-config!
{:appenders
{:rotor (rotor/rotor-appender
{:path "smeagol.log"
Expand All @@ -80,10 +80,10 @@
(cronj/start! session-manager/cleanup-job)
(if (env :dev) (parser/cache-off!))
;;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") "]=-")
(catch Exception any
(timbre/error any "Failure during startup")
(log/error any "Failure during startup")
(destroy))))

;; timeout sessions after 30 minutes
Expand Down
9 changes: 5 additions & 4 deletions src/smeagol/history.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(ns ^{:doc "Explore the history of a page."
:author "Simon Brooke"}
smeagol.history
(:require [taoensso.timbre :as timbre]
[clj-jgit.porcelain :as git]
(:require [clj-jgit.porcelain :as git]
[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]
[org.eclipse.jgit.lib Repository ObjectId]
[org.eclipse.jgit.revwalk RevCommit RevTree RevWalk]
Expand Down Expand Up @@ -39,7 +39,7 @@
"If this `log-entry` contains a reference to this `file-path`, return the entry;
else nil."
[^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
(seq (filter (fn* [p1__341301#] (= (first p1__341301#) file-path)) (:changed_files log-entry)))
log-entry))
Expand All @@ -54,6 +54,7 @@
(try
(git/load-repo git-directory-path)
(catch java.io.FileNotFoundException fnf
(log/info "Initialising Git repository at" git-directory-path)
(git/git-init git-directory-path)
(let [repo (git/load-repo git-directory-path)]
(git/git-add-and-commit repo "Initial commit")
Expand Down
3 changes: 1 addition & 2 deletions src/smeagol/layout.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
[selmer.parser :as parser]
[smeagol.configuration :refer [config]]
[smeagol.sanity :refer :all]
[smeagol.util :as util]
[taoensso.timbre :as timbre]))
[smeagol.util :as util]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
Expand Down
14 changes: 7 additions & 7 deletions src/smeagol/middleware.clj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
(ns ^{:doc "In truth, boilerplate provided by LuminusWeb."
:author "Simon Brooke"}
smeagol.middleware
(:require [taoensso.timbre :as timbre]
[environ.core :refer [env]]
[selmer.middleware :refer [wrap-error-page]]
(:require [environ.core :refer [env]]
[noir-exception.core :refer [wrap-internal-error]]
[prone.middleware :refer [wrap-exceptions]]
[ring.middleware.anti-forgery :refer [wrap-anti-forgery]]
[ring.middleware.file :refer [wrap-file]]
[ring.middleware.resource :refer [wrap-resource]]
[ring.middleware.content-type :refer [wrap-content-type]]
[ring.middleware.not-modified :refer [wrap-not-modified]]
[noir-exception.core :refer [wrap-internal-error]]
[smeagol.util :as util]))
[selmer.middleware :refer [wrap-error-page]]
[smeagol.util :as util]
[taoensso.timbre :as log]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
Expand Down Expand Up @@ -39,7 +39,7 @@

(defn log-request [handler]
(fn [req]
(timbre/debug req)
(log/debug req)
(handler req)))


Expand All @@ -49,7 +49,7 @@


(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-file % util/content-dir
{:index-files? false :prefer-handler? true})
Expand Down
4 changes: 2 additions & 2 deletions src/smeagol/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[smeagol.authenticate :as auth]
[smeagol.configuration :refer [config]]
[smeagol.formatting :refer [md->html]]
[taoensso.timbre :as timbre]))
[taoensso.timbre :as log]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;
Expand Down Expand Up @@ -69,7 +69,7 @@
messages (try
(i18n/get-messages specifier "i18n" "en-GB")
(catch Exception any
(timbre/error
(log/error
any
(str
"Failed to parse accept-language header '"
Expand Down

0 comments on commit 2f22b73

Please sign in to comment.