Skip to content

Commit

Permalink
feat: set log level from ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ozangulle committed Feb 5, 2025
1 parent ffacd49 commit 7670334
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
10 changes: 9 additions & 1 deletion resources/templates/admin-preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h3 class="uppercase text-lg my-10">Preferences</h3>

<form action="/admin/preferences" method="POST">
<div class="grid gap-6 mb-6 md:grid-cols-2">
<div class="grid gap-4 mb-6 md:grid-cols-2">
<input type="hidden" name="redirect-url" value="/admin/preferences"</input>
<div>
<label class="block mb-2 text-sm font-medium text-gray-900" for="language-detection-threshold">Language Detection Threshold</label>
Expand All @@ -15,6 +15,14 @@ <h3 class="uppercase text-lg my-10">Preferences</h3>
<label class="block mb-2 text-sm font-medium text-gray-900" for="categorization-threshold">Categorization Threshold</label>
<input class="mr-4 text-gray-700 focus:text-gray-700 focus:border-gray-200 focus:ring-gray-200" name="categorization-threshold" value="{{categorization-threshold}}">
</div>
<div>
<label class="block mb-2 text-sm font-medium text-gray-900" for="categorization-threshold">Log Level</label>
<select class="block mr-4 bg-gray-50 border border-gray-200 text-gray-700 focus:bg-gray-700 focus:ring-gray-200 focus:border-gray-200 focus:text-white text-sm rounded-lg block w-full p-2.5 w-full" name="log-level">
{% for option in log-level-options %}
<option value="{{option.key}}" {% if option.key = log-level %} selected="true" {% endif %}>{{option.name}}</option>
{% endfor %}
</select>
</div>
</div>
<button class="px-4 py-2 text-white bg-gray-700 hover:bg-gray-900 font-medium rounded-lg text-sm" type="send">Save</button>
</form>
Expand Down
4 changes: 2 additions & 2 deletions src/plauna/entry.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
[plauna.core.events :as events])
(:gen-class))

(tstreams/streams->telemere!)
(t/set-min-level! :info)
(t/set-min-level! :slf4j "org.eclipse.jetty.server.*" :error)
(tstreams/streams->telemere!)

(set! *warn-on-reflection* true)

Expand All @@ -39,6 +38,7 @@
(defn -main
[& args]
(let [parsed-config (reduce (fn [acc val] (conj acc (parse-cli-arg val))) {} args)]
(t/set-min-level! (or (database/fetch-preference (name :log-level)) :info))
(files/set-custom-config-location! (:config-file parsed-config))
(files/check-and-create-database-file)
(doseq [address (:addresses (:email (files/config)))] (database/add-to-my-addresses address))
Expand Down
15 changes: 3 additions & 12 deletions src/plauna/markup.clj
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,6 @@
:tooltip {:field :count :type "quantitative"}}}]
(render-file "statistics.html" {:statistics [{:type :bar-chart :header "Yearly Emails" :id "emails" :json-data (json/write-str vega-data)}]})))

(defn email-training-page [emails categories languages page-info]
(let [page-size (:size page-info)
last-page {:last-page (if (= 0 page-size) 1 (quot (:total page-info) page-size))}
modified-emails (map #(update-in % [:header :date] timestamp->date) emails)]
(render-file "training-review.html" {:emails modified-emails :languages languages :categories categories :page (conj page-info last-page)})))

(defn email-new-training-page [emails categories languages page-info]
(let [last-page {:last-page (quot (:total page-info) (:size page-info))}
modified-emails (map #(update-in % [:header :date] timestamp->date) emails)]
(render-file "training-review.html" {:emails modified-emails :languages languages :categories categories :page (conj page-info last-page)})))

(defn categories-page [categories] (render-file "admin-categories.html" {:categories categories}))

(defn languages-admin-page [language-preferences]
Expand All @@ -148,4 +137,6 @@

(defn watcher [client folders] (render-file "watcher.html" {:id (-> client first :id) :host (:host (first client)) :user (:user (first client)) :folders folders}))

(defn preferences-page [data] (render-file "admin-preferences.html" data))
(defn preferences-page [data] (let [log-levels {:log-level-options [{:key :error :name "Error"} {:key :info :name "Info"} {:key :debug :name "Debug"}]}]
(println (conj data log-levels))
(render-file "admin-preferences.html" (conj data log-levels))))
7 changes: 5 additions & 2 deletions src/plauna/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,15 @@

(comp/GET "/admin/preferences" {}
(let [language-datection-threshold (analysis/language-detection-threshold)
categorization-threshold (analysis/categorization-threshold)]
(success-html-with-body (markup/preferences-page {:language-detection-threshold language-datection-threshold :categorization-threshold categorization-threshold}))))
categorization-threshold (analysis/categorization-threshold)
log-level (or (db/fetch-preference (name :log-level)) :info)]
(success-html-with-body (markup/preferences-page {:language-detection-threshold language-datection-threshold :categorization-threshold categorization-threshold :log-level log-level}))))

(comp/POST "/admin/preferences" request

(doseq [param (dissoc (:params request) :redirect-url)]
(db/update-preference (first param) (second param)))
(t/set-min-level! (db/fetch-preference (name :log-level)))
(redirect-request request))

(comp/POST "/admin/languages" {params :params}
Expand Down
2 changes: 1 addition & 1 deletion test/plauna/database_test.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns plauna.database_test
(ns plauna.database-test
(:require [clojure.test :refer :all]
[clojure.core.async :as async]
[plauna.database :as db]
Expand Down
3 changes: 1 addition & 2 deletions test/plauna/files_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
(:require [clojure.test :refer :all]
[clojure.java.io :as io]
[plauna.files :as files]
[plauna.messaging :refer [main-chan restart-main-chan]]
[clojure.core.async :refer [go <!! chan close!]]))
[clojure.core.async :refer [<!! chan close!]]))

(defn resource->is [resource-path]
(io/input-stream (io/resource resource-path)))
Expand Down
3 changes: 1 addition & 2 deletions test/plauna/parser_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
[plauna.files :as files]
[plauna.util.async :as async-utils]
[plauna.parser :as parser]
[clojure.core.async :refer [pub sub chan >!!] :as async]
[plauna.analysis :as analysis]))
[clojure.core.async :refer [pub sub chan >!!] :as async]))

(defn resource->is [resource-path]
(io/input-stream (io/resource resource-path)))
Expand Down

0 comments on commit 7670334

Please sign in to comment.