Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async appender support #25

Open
neuromantik33 opened this issue Jan 10, 2020 · 0 comments
Open

Async appender support #25

neuromantik33 opened this issue Jan 10, 2020 · 0 comments

Comments

@neuromantik33
Copy link

Hello,

I wanted to implement logback's async appender with unilog but not supported out of the box I found it tricky and had to copy a bunch of code. Can you perhaps support this feature in the future?

(def ^LoggerContext context (LoggerFactory/getILoggerFactory))
(defmethod u/build-appender :async
  [{:keys [name
           delegates
           queue-size
           discarding-threshold
           include-caller-data
           max-flush-time
           never-block]
    :or   {name                 "async"
           queue-size           256
           discarding-threshold -1
           include-caller-data  false
           max-flush-time       1000
           never-block          false}
    :as   config}]
  (let [aa (doto (AsyncAppender.)
             (.setName name)
             (.setContext context)
             (.setQueueSize queue-size)
             (.setDiscardingThreshold discarding-threshold)
             (.setIncludeCallerData include-caller-data)
             (.setMaxFlushTime max-flush-time)
             (.setNeverBlock never-block))]
       (doseq [{:keys [^OutputStreamAppender appender
                    ^Encoder encoder]}
            (->> delegates (map u/build-appender) (map u/build-encoder))]
      (when encoder
        (.setContext encoder context)
        (.start encoder)
        (.setEncoder appender encoder))
      (u/start-appender! appender context)
      (.addAppender aa appender))
    (-> config
        (assoc :appender aa)
        (dissoc :delegates))))

And the schema looks like this

{:appender  :async
 :delegates [{:appender :console
              :encoder  :pattern
              :pattern  "%p [%d] - %c - %m%n"}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant