Skip to content

Commit

Permalink
consolidate logging
Browse files Browse the repository at this point in the history
  • Loading branch information
qnkhuat committed Nov 2, 2022
1 parent fb3f0b6 commit 44f0a4a
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 73 deletions.
44 changes: 25 additions & 19 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,35 @@

:deps
{
org.clojure/clojure {:mvn/version "1.11.0"}
org.clojure/clojure {:mvn/version "1.11.0"}
;; util
prismatic/schema {:mvn/version "1.2.0"} ; schema validator
slingshot/slingshot {:mvn/version "0.12.2"} ; better exception handling
com.cemerick/friend {:mvn/version "0.2.3"} ; auth library
cheshire/cheshire {:mvn/version "5.10.2"} ; fast JSON encoding (used by Ring JSON middleware)
potemkin/potemkin {:mvn/version "0.4.5"} ; utility macros & fns
prismatic/schema {:mvn/version "1.2.0"} ; schema validator
slingshot/slingshot {:mvn/version "0.12.2"} ; better exception handling
com.cemerick/friend {:mvn/version "0.2.3"} ; auth library
cheshire/cheshire {:mvn/version "5.10.2"} ; fast JSON encoding (used by Ring JSON middleware)
potemkin/potemkin {:mvn/version "0.4.5"} ; utility macros & fns
;; webserver+routing
compojure/compojure {:mvn/version "1.6.2"}
ring/ring-core {:mvn/version "1.9.4"}
ring/ring-jetty-adapter {:mvn/version "1.9.5"}
ring/ring-json {:mvn/version "0.5.1"}
ring-cors/ring-cors {:mvn/version "0.1.13"}
compojure/compojure {:mvn/version "1.6.2"}
ring/ring-core {:mvn/version "1.9.4"}
ring/ring-jetty-adapter {:mvn/version "1.9.5"}
ring/ring-json {:mvn/version "0.5.1"}
ring-cors/ring-cors {:mvn/version "0.1.13"}
;; log
com.taoensso/timbre {:mvn/version "5.1.2"}
org.clojure/tools.logging {:mvn/version "1.2.4"}
org.apache.logging.log4j/log4j-1.2-api {:mvn/version "2.18.0"} ; apache logging framework
org.apache.logging.log4j/log4j-api {:mvn/version "2.18.0"} ; add compatibility with log4j 1.2
org.apache.logging.log4j/log4j-core {:mvn/version "2.18.0"} ; apache logging framework
org.apache.logging.log4j/log4j-jcl {:mvn/version "2.18.0"} ; allows the commons-logging API to work with log4j 2
org.apache.logging.log4j/log4j-jul {:mvn/version "2.18.0"} ; java.util.logging (JUL) -> Log4j2 adapter
org.apache.logging.log4j/log4j-slf4j-impl {:mvn/version "2.18.0"} ; allows the slf4j API to work with log4j 2
;; database
org.clojure/java.jdbc {:mvn/version "0.7.12"}
com.h2database/h2 {:mvn/version "2.1.210"} ; H2 driver
org.postgresql/postgresql {:mvn/version "42.2.13"} ; Postgres driver
com.mchange/c3p0 {:mvn/version "0.9.5.5"}
toucan/toucan {:mvn/version "1.18.0"}
;; hickory/hickory {:mvn/version "0.7.1"} ; seems like a fater parser than enlive, but using enlive for now bc it has DOM selector
enlive/enlive {:mvn/version "1.1.6"}} ; html parser
org.clojure/java.jdbc {:mvn/version "0.7.12"}
com.h2database/h2 {:mvn/version "2.1.210"} ; H2 driver
org.postgresql/postgresql {:mvn/version "42.2.13"} ; Postgres driver
com.mchange/c3p0 {:mvn/version "0.9.5.5"}
toucan/toucan {:mvn/version "1.18.0"}
;; hickory/hickory {:mvn/version "0.7.1"} ; seems like a fater parser than enlive, but using enlive for now bc it has DOM selector
enlive/enlive {:mvn/version "1.1.6"}} ; html parser

:aliases
{; clj -M:dev
Expand Down
32 changes: 32 additions & 0 deletions resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="%date %level %logger{2} :: %message%n%throwable">
<replace regex=":basic-auth \\[.*\\]" replacement=":basic-auth [redacted]"/>
</PatternLayout>
</Console>

<!-- This file appender is provided as an example -->
<!--
<RollingFile name="FILE" fileName="${logfile.path}/ubinote.log" filePattern="${logfile.path}/ubinote.log.%i">
<Policies>
<SizeBasedTriggeringPolicy size="500 MB"/>
</Policies>
<DefaultRolloverStrategy max="2"/>
<PatternLayout pattern="%d [%t] %-5p%c - %m%n">
<replace regex=":basic-auth \\[.*\\]" replacement=":basic-auth [redacted]"/>
</PatternLayout>
</RollingFile>
-->
</Appenders>

<Loggers>
<Logger name="ubinote" level="INFO"/>
<Logger name="com.mchange" level="ERROR"/>

<Root level="WARN">
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>
18 changes: 11 additions & 7 deletions src/frontend/components/Page/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ const addHighlight = (pageId: number, selection: window.Selection, color = "red"
// need to calculate textpos before highlight, otherwise the position will be messed up
// when try to highlight on re-load
const textPos = fromRange(document.body, range);
const highlightElements = highlightRange(range, 'span', {class: colorToCSS[color]});
console.log("Elements: ", highlightElements);
console.log("range:", range);
console.log("textpos:", textPos);
console.log("bounding: ", range.getBoundingClientRect());
// from this bounding => display a dom at the middle end
//const highlightElements = highlightRange(range, 'span', {class: colorToCSS[color]});
// save it
createAnnotation(
{coordinate: textPos,
page_id: pageId})
.catch(err => console.error("Failed to add annotaiton: ", err));
return highlightElements;
//createAnnotation(
// {coordinate: textPos,
// page_id: pageId})
// .catch(err => console.error("Failed to add annotaiton: ", err));
//return highlightElements;
}

const PageView = (props: Props) => {
Expand All @@ -43,6 +46,7 @@ const PageView = (props: Props) => {
document.addEventListener("mouseup", () => {
const selection = window.getSelection();
if (!selection.isCollapsed) {
// open up a popover
addHighlight(page.id, selection);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/ubinote/cmd.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [ubinote.util.fs :as fs]
[clojure.string :as string]
[clojure.java.shell :refer [sh]]
[taoensso.timbre :as log]))
[clojure.tools.logging :as log]))

(defn which
"like `which` command"
Expand Down
2 changes: 1 addition & 1 deletion src/ubinote/migration.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[ubinote.config :as cfg]
[clojure.java.jdbc :as jdbc]
[clojure.string :as string]
[taoensso.timbre :as log]
[clojure.tools.logging :as log]
[toucan.db :as db]))

(def migrations (atom []))
Expand Down
12 changes: 11 additions & 1 deletion src/ubinote/server/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@
[compojure.route :as route]
[compojure.core :refer [context defroutes GET]]
[ring.util.response :refer [resource-response]]
[taoensso.timbre :as log]
[clojure.tools.logging :as log]
[ring.adapter.jetty :refer [run-jetty]]))

;; ensure we use a `BasicContextSelector` instead of a `ClassLoaderContextSelector` for log4j2. Ensures there is only
;; one LoggerContext instead of one per classpath root. Practical effect is that now `(LogManager/getContext true)`
;; and `(LogManager/getContext false)` will return the same (and only)
;; LoggerContext. https://logging.apache.org/log4j/2.x/manual/logsep.html
(System/setProperty "log4j2.contextSelector" "org.apache.logging.log4j.core.selector.BasicContextSelector")

;; ensure the [[clojure.tools.logging]] logger factory is the log4j2 version (slf4j is far slower and identified first)
(System/setProperty "clojure.tools.logging.factory" "clojure.tools.logging.impl/log4j2-factory")
(System/setProperty "log4j2.configurationFile" "log4j2.xml")

(defroutes routes
;; serving bundle.js this seems hacky?
(GET "/static/js/bundle.js" [_req] (resource-response "frontend/static/js/bundle.js")) ;; inside the resources folder
Expand Down
2 changes: 0 additions & 2 deletions src/ubinote/server/db.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[clojure.java.jdbc :as jdbc]
[clojure.java.io :as io]
[clojure.string :as string]
[taoensso.timbre :as log]
[toucan.models :as models]
[toucan.db :as db])
(:import java.util.Properties
Expand Down Expand Up @@ -91,6 +90,5 @@
[]
(let [db-type (cfg/config-kw :un-db-type)]
(models/set-root-namespace! 'ubinote.model)
;(db/set-default-automatically-convert-dashes-and-underscores! true)
(db/set-default-quoting-style! (db-type quoting-style))
(db/set-default-db-connection! (db-details db-type))))
2 changes: 1 addition & 1 deletion src/ubinote/server/middleware/api.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns ubinote.server.middleware.api
(:require [taoensso.timbre :as log]))
(:require [clojure.tools.logging :as log]))

(defn resp->log-level
[{:keys [status]}]
Expand Down
2 changes: 1 addition & 1 deletion src/ubinote/server/middleware/exceptions.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns ubinote.server.middleware.exceptions
(:require [taoensso.timbre :as log]))
(:require [clojure.tools.logging :as log]))

(defn- explain-one-schema-error
[[k v]]
Expand Down
2 changes: 1 addition & 1 deletion src/ubinote/server/middleware/log.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns ubinote.server.middleware.log
(:require [taoensso.timbre :as log]))
(:require [clojure.tools.logging :as log]))

(defn resp->log-level
[{:keys [status]}]
Expand Down
39 changes: 0 additions & 39 deletions src/ubinote/server/middleware/request.clj

This file was deleted.

0 comments on commit 44f0a4a

Please sign in to comment.