Log4j: change the format of registrars configured in another library

Using clojure, I was able to successfully configure log4j very simply, using this log4j.properties file and including log4j in my class path.

# BEGIN log4j.properties

log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%d{MMdd HHmmss SSS} %5p %c [%t] %m\n

log4j.rootLogger=DEBUG, STDOUT

Then after: use'ing clojure.contrib.logging, I can print the instruction with the required formatting, as expected:

(info "About to print this")
(debug "This is debug-level")

My question is how to achieve consistent formatting for logging statements made from logs configured in other libraries. I thought I could find existing registrars using org.apache.log4j.LogManager.getCurrentLoggers () and change PatternLayouts there, but I cannot iterate over this listing in clojure, since I get the following error:

Dont know how to create ISeq from: java.util.Vector$1

I suppose this is possible somehow, and perhaps very simple. How?

Many thanks.

+3
1

enumeration-seq seq:

(enumeration-seq (org.apache.log4j.LogManager/getCurrentLoggers))

org.apache.log4j.LogManager.getCurrentLoggers() a java.util.Enumeration; seq , , enumeration-seq .

, :

(seq (.elements (java.util.Vector. [1 2 3]))
; => throws an exception

(enumeration-seq (.elements (java.util.Vector. [1 2 3])))
; => returns (1 2 3)
+2

Source: https://habr.com/ru/post/1742371/


All Articles