-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
awb99
committed
Apr 15, 2024
1 parent
2cfed1e
commit d65ee2f
Showing
10 changed files
with
283 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Use Node.js 12.x | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12.x | ||
- name: Prepare java | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 1.14 | ||
- name: Install clojure tools | ||
uses: DeLaGuardo/setup-clojure@12.1 | ||
with: | ||
# Install just one or all simultaneously | ||
cli: 1.11.1.1413 # Clojure CLI based on tools.deps | ||
clj-kondo: 2022.05.31 # Clj-kondo | ||
cljfmt: 0.10.2 # cljfmt | ||
- name: Release | ||
if: success() | ||
# if: github.event_name == 'push' | ||
env: | ||
CLOJARS_USERNAME: ${{ secrets.ReleaseUsername }} | ||
CLOJARS_PASSWORD: ${{ secrets.ReleasePassword }} | ||
CODECOV_TOKEN: ${{ secrets.CodecovToken }} | ||
run: | | ||
git config --global user.email "ci@pinkgorilla.org" | ||
git config --global user.name "CI/CD" | ||
clojure -T:build jar | ||
clojure -T:build deploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.cpcache | ||
.lsp | ||
.clj-kondo | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
# timbre | ||
# timbre [](https://github.com/pink-gorilla/timbre/actions?workflow=CI)[](https://clojars.org/org.pinkgorilla/timbre) | ||
|
||
|
||
## timbre log config | ||
|
||
See example in `demo/logging.clj` | ||
|
||
``` | ||
clj -X:demo-log-default | ||
clj -X:demo-log-custom | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
(ns build | ||
(:require | ||
[clojure.tools.build.api :as b] | ||
[deps-deploy.deps-deploy :as dd])) | ||
|
||
(def lib 'org.pinkgorilla/timbre) | ||
(def version (format "0.0.%s" (b/git-count-revs nil))) | ||
(def class-dir "target/classes") | ||
(def basis (b/create-basis {:project "deps.edn"})) | ||
(def jar-file (format "target/%s-%s.jar" (name lib) version)) | ||
|
||
(defn clean [_] | ||
(b/delete {:path "target"})) | ||
|
||
(def pom-template | ||
[[:licenses | ||
[:license | ||
[:name "Eclipse Public License"] | ||
[:url "https://www.eclipse.org/legal/epl-v10.html"]]] | ||
[:developers | ||
[:developer | ||
[:name "pink-gorilla"]]] | ||
[:scm | ||
[:url "https://github.com/pink-gorilla/timbre"] | ||
[:connection "scm:git:git://github.com/pink-gorilla/timbre.git"] | ||
[:developerConnection "scm:git:ssh://git@github.com/pink-gorilla/timbre.git"]]]) | ||
|
||
(def opts {:class-dir class-dir | ||
:lib lib | ||
:version version | ||
:basis basis | ||
:pom-data pom-template | ||
:src-dirs ["src"]}) | ||
|
||
(defn jar [_] | ||
(b/write-pom opts) | ||
(b/copy-dir {:src-dirs ["src" "resources"] | ||
:target-dir class-dir}) | ||
(b/jar {:class-dir class-dir | ||
:jar-file jar-file})) | ||
|
||
(defn deploy "Deploy the JAR to Clojars." [_] | ||
(println "Deploying to Clojars.") | ||
(dd/deploy {:installer :remote | ||
;:sign-releases? true | ||
:pom-file (b/pom-path (select-keys opts [:lib :class-dir])) | ||
;:artifact "target/tech.ml.dataset.jar" | ||
:artifact (b/resolve-path jar-file)})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{:paths ["src" | ||
"resources" ; extension , resources used in devtools ui | ||
] | ||
:deps {org.clojure/clojure {:mvn/version "1.11.1"} | ||
; logging | ||
com.taoensso/timbre {:mvn/version "6.2.2"} ; clj/cljs logging | ||
; config to log slf4j output to console: | ||
com.fzakaria/slf4j-timbre {:mvn/version "0.4.0"} ; https://mvnrepository.com/artifact/org.slf4j/slf4j-simple | ||
} | ||
|
||
:aliases | ||
{; github ci | ||
:build {:deps {io.github.clojure/tools.build {:mvn/version "0.9.6"} | ||
slipset/deps-deploy {:mvn/version "0.2.1"} | ||
babashka/fs {:mvn/version "0.0.5"}} | ||
:ns-default build} | ||
|
||
;; demo | ||
|
||
:demo-log-default | ||
{:extra-paths ["src-demo"] | ||
:exec-args {:custom-config false} | ||
:exec-fn logging/demo} | ||
|
||
:demo-log-custom | ||
{:extra-paths ["src-demo"] | ||
:exec-args {:custom-config true} | ||
:exec-fn logging/demo} | ||
|
||
; | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{:name "timbre" | ||
:lazy false | ||
:cljs-namespace [modular.log] | ||
:cljs-ns-bindings {'timbre-config! {'header-main modular.log/timbre-config!}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(ns logging | ||
(:require | ||
[taoensso.timbre :refer [info debug warn error with-context]] | ||
[modular.log :refer [timbre-config!]])) | ||
|
||
(defn timbre-custom-config [] | ||
(println "setting custom logging config!") | ||
(timbre-config! | ||
{:min-level [[#{"org.eclipse.jetty.*"} :warn] | ||
[#{"modular.oauth2.token.refresh"} :warn] | ||
[#{"*"} :info]] | ||
:appenders {:default {:type :console-color} | ||
:file {:type :file | ||
:fname "target/file.log"} | ||
:rolling {:type :file-rolling | ||
:path "target/rolling.log" | ||
:pattern :monthly} | ||
:workflow {:type :file-rolling-context | ||
:context :scheduled-data-import | ||
:path "target/workflow.log" | ||
:pattern :monthly}}})) | ||
|
||
(defn demo [{:keys [custom-config]}] | ||
(if custom-config | ||
(timbre-custom-config) | ||
(println "using default timbre config!")) | ||
|
||
(debug "debug!") | ||
(info "info!") | ||
(warn "warn!") | ||
(error "error!") | ||
|
||
(with-context :scheduled-data-import | ||
(debug "debug!") | ||
(info "info!") | ||
(warn "warn!") | ||
(error "error!")) | ||
|
||
; | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(ns modular.log | ||
(:require | ||
[taoensso.timbre :as timbre] | ||
[modular.log.appenders :refer [appender-list default-appenders]])) | ||
|
||
(defn- create-appender [{:keys [type] :as opts}] | ||
(let [opts (dissoc opts :type) | ||
appender (get appender-list type)] | ||
(if appender | ||
(appender opts) | ||
(do (println "appender not found: " type) | ||
nil)))) | ||
|
||
(defn- create-appenders [appenders] | ||
{:appenders | ||
(->> (map (fn [[name opts]] | ||
(let [a (create-appender opts)] | ||
(if a | ||
[name a] | ||
nil))) appenders) | ||
(remove nil?) | ||
(into {}))}) | ||
|
||
(defn timbre-config! [{:keys [min-level appenders] | ||
:or {min-level :info | ||
appenders default-appenders} | ||
:as config}] | ||
; use println, because at timbre configuration it is not sure where logging | ||
; output would be written to. | ||
(println "timbre config min-level: " min-level "appenders: " appenders) | ||
;(println "appender setup: " (create-appenders appenders)) | ||
(timbre/set-config! | ||
(merge timbre/default-config | ||
(create-appenders appenders) | ||
{;:output-fn default-output-fn | ||
; :middleware [(fn [data] | ||
; (println "context: " (:context data)) | ||
; ;(println "middleware: " data) | ||
; ;(assoc data :vargs ["qux"]) | ||
; data | ||
; )] | ||
:min-level min-level}))) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(ns modular.log.appenders | ||
(:require | ||
[taoensso.timbre :as timbre] | ||
[taoensso.timbre.appenders.core :refer [println-appender spit-appender]] | ||
[taoensso.timbre.appenders.community.rolling :refer [rolling-appender]])) | ||
|
||
(defn color-appender [& [opts]] | ||
(let [colors {:info :green, | ||
:warn :yellow | ||
:error :red | ||
:fatal :purple | ||
:report :blue}] | ||
{:enabled? true | ||
:async? false | ||
:min-level nil | ||
:rate-limit nil | ||
:output-fn :inherit | ||
:fn (fn [{:keys [error? level output-fn] :as data}] | ||
(binding [*out* (if error? *err* *out*)] | ||
(if-let [color (colors level)] | ||
(println (timbre/color-str color (output-fn data))) | ||
(println (output-fn data)))))})) | ||
|
||
(defn rolling-appender-context [& [opts]] | ||
(let [context-target (:context opts) | ||
ra (rolling-appender opts) | ||
ra-fn (:fn ra)] | ||
{:enabled? true | ||
:async? false | ||
:min-level nil | ||
:rate-limit nil | ||
:output-fn :inherit | ||
:fn (fn [{:keys [context] :as data}] | ||
(when (= context context-target) | ||
;(println "context driven data: " data) | ||
(ra-fn data)))})) | ||
|
||
(def appender-list | ||
{:console println-appender | ||
:console-color color-appender | ||
:file spit-appender | ||
:file-rolling rolling-appender | ||
:file-rolling-context rolling-appender-context}) | ||
|
||
(def default-appenders | ||
{:default {:type :console-color}}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(ns modular.log.appenders | ||
(:require | ||
[taoensso.timbre :as timbre] | ||
[taoensso.timbre.appenders.core :refer [println-appender console-appender]])) | ||
|
||
(def appender-list | ||
{:console println-appender | ||
:console-color console-appender}) | ||
|
||
(def default-appenders | ||
{:default {:type :console-color}}) |