-
Notifications
You must be signed in to change notification settings - Fork 64
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
Showing
10 changed files
with
116 additions
and
61 deletions.
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
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
<configuration> | ||
<property name="type" value="${ZIGGURAT_LOG_FORMAT:-text}" /> | ||
|
||
<if condition = 'property("type").equals("json")'> | ||
<then> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder"> | ||
<layout class="cambium.logback.json.FlatJsonLayout"> | ||
<jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter"> | ||
<prettyPrint>false</prettyPrint> | ||
</jsonFormatter> | ||
<!-- <context>api</context> --> | ||
<timestampFormat>yyyy-MM-dd'T'HH:mm:ss.SSS'Z'</timestampFormat> | ||
<timestampFormatTimezoneId>UTC</timestampFormatTimezoneId> | ||
<appendLineSeparator>true</appendLineSeparator> | ||
</layout> | ||
</encoder> | ||
</appender> | ||
</then> | ||
</if> | ||
|
||
<if condition = 'property("type").equals("text")'> | ||
<then> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<layout class="ch.qos.logback.classic.PatternLayout"> | ||
<pattern> | ||
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg { %mdc }%n | ||
</pattern> | ||
</layout> | ||
</appender> | ||
</then> | ||
</if> | ||
|
||
<root level="info"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
</configuration> |
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
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
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
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
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,11 +1,7 @@ | ||
(ns ziggurat.util.logging | ||
(:require [clojure.tools.logging :as log]) | ||
(:import (org.apache.logging.log4j ThreadContext))) | ||
(:require [cambium.core :as clog])) | ||
|
||
(defmacro with-context | ||
[context-map & body] | ||
`(try | ||
(doseq [[k# v#] ~context-map] (ThreadContext/put (name k#) (str v#))) | ||
~@body | ||
(finally (doseq [[k# _#] ~context-map] (ThreadContext/remove (name k#)))))) | ||
`(clog/with-logging-context ~context-map ~@body)) | ||
|
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
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,20 +1,20 @@ | ||
(ns ziggurat.util.logging-test | ||
(:require [clojure.test :refer :all] | ||
[ziggurat.util.logging :as zlog]) | ||
(:import (org.apache.logging.log4j ThreadContext))) | ||
(:import (org.slf4j MDC))) | ||
|
||
(deftest with-context-test | ||
(let [capture-context #(reset! % (into {} (ThreadContext/getImmutableContext)))] | ||
(testing "sets thread local log context params within body" | ||
(let [capture-context #(reset! % (into {} (MDC/getCopyOfContextMap)))] | ||
(testing "sets mdc context params within body" | ||
(let [context-map (atom {})] | ||
(zlog/with-context {:param-1 "string-value", :param-2 123} | ||
(zlog/with-context {:param-1 "string-value" :param-2 123} | ||
(capture-context context-map)) | ||
(is (= "string-value" (get @context-map "param-1"))) | ||
(is (= "\"string-value\"" (get @context-map "param-1"))) | ||
(is (= "123" (get @context-map "param-2"))))) | ||
|
||
(testing "clears thread local log context params when exits" | ||
(testing "clears mdc context params when exits" | ||
(let [context-map (atom {})] | ||
(zlog/with-context {:param-1 "string-value", :param-2 123} | ||
(zlog/with-context {:param-1 "string-value" :param-2 123} | ||
(constantly nil)) | ||
(capture-context context-map) | ||
(is (empty? @context-map)))))) |