Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit 6dd2205

Browse files
committed
Added type hints to remove reflection when implementation-specific functions are invoked.
Fixes #10
1 parent f92114c commit 6dd2205

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/clojure/contrib/logging.clj

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Apache commons-logging, log4j, and finally java.util.logging.
2020
2121
Logging levels are specified by clojure keywords corresponding to the
22-
values used in log4j/commons-logging:
22+
values used in log4j and commons-logging:
2323
:trace, :debug, :info, :warn, :error, :fatal
2424
2525
Logging occurs with the log macro, or the level-specific convenience macros,
@@ -28,13 +28,16 @@
2828
logging is invoked within a transaction it will always use an agent.
2929
3030
The log macros will not evaluate their 'message' unless the specific logging
31-
level is in effect.
32-
33-
Alternately, you can use the spy macro when you have code that needs to be
34-
evaluated, and also want to output the code and its result to the debug log.
31+
level is in effect. Alternately, you can use the spy macro when you have code
32+
that needs to be evaluated, and also want to output the code and its result to
33+
the debug log.
3534
3635
Unless otherwise specified, the current namespace (as identified by *ns*) will
3736
be used as the log-ns (similar to how the java class name is usually used).
37+
Note: your log configuration should display the name that was passed to the
38+
logging implementation, and not perform stack-inspection, otherwise you'll see
39+
something like \"clojure.contrib.logging$fn__72$write__39__auto____81 invoke\"
40+
in your logs.
3841
3942
Use the enabled? function to write conditional code against the logging level
4043
(beyond simply whether or not to call log, which is handled automatically).
@@ -64,16 +67,16 @@
6467
(try
6568
(import (org.apache.commons.logging LogFactory Log))
6669
`(letfn [(get-log# [log-ns#]
67-
(LogFactory/getLog log-ns#))
68-
(enabled?# [log# level#]
70+
(LogFactory/getLog #^String log-ns#))
71+
(enabled?# [#^org.apache.commons.logging.Log log# level#]
6972
(condp = level#
7073
:trace (.isTraceEnabled log#)
7174
:debug (.isDebugEnabled log#)
7275
:info (.isInfoEnabled log#)
7376
:warn (.isWarnEnabled log#)
7477
:error (.isErrorEnabled log#)
7578
:fatal (.isFatalEnabled log#)))
76-
(write# [log# level# msg# e#]
79+
(write# [#^org.apache.commons.logging.Log log# level# msg# e#]
7780
(condp = level#
7881
:trace (.trace log# msg# e#)
7982
:debug (.debug log# msg# e#)
@@ -98,10 +101,10 @@
98101
:error Level/ERROR
99102
:fatal Level/FATAL}]
100103
(letfn [(get-log# [log-ns#]
101-
(Logger/getLogger log-ns#))
102-
(enabled?# [log# level#]
104+
(org.apache.log4j.Logger/getLogger #^String log-ns#))
105+
(enabled?# [#^org.apache.log4j.Logger log# level#]
103106
(.isEnabledFor log# (levels# level#)))
104-
(write# [log# level# msg# e#]
107+
(write# [#^org.apache.log4j.Logger log# level# msg# e#]
105108
(if-not e#
106109
(.log log# (levels# level#) msg#)
107110
(.log log# (levels# level#) msg# e#)))]
@@ -122,13 +125,15 @@
122125
:error Level/SEVERE
123126
:fatal Level/SEVERE}]
124127
(letfn [(get-log# [log-ns#]
125-
(Logger/getLogger log-ns#))
126-
(enabled?# [log# level#]
128+
(java.util.logging.Logger/getLogger log-ns#))
129+
(enabled?# [#^java.util.logging.Logger log# level#]
127130
(.isLoggable log# (levels# level#)))
128-
(write# [log# level# msg# e#]
131+
(write# [#^java.util.logging.Logger log# level# msg# e#]
129132
(if-not e#
130-
(.log log# (levels# level#) (str msg#))
131-
(.log log# (levels# level#) (str msg#) e#)))]
133+
(.log log# #^java.util.logging.Level (levels# level#)
134+
#^String (str msg#))
135+
(.log log# #^java.util.logging.Level (levels# level#)
136+
#^String (str msg#) #^Throwable e#)))]
132137
(struct log-system "java-logging" get-log# enabled?# write#)))
133138
(catch Exception e nil)))
134139

@@ -208,7 +213,7 @@
208213
(proxy [java.io.ByteArrayOutputStream] []
209214
(flush []
210215
(proxy-super flush)
211-
(let [s (.trim (.toString this))]
216+
(let [s (.trim (.toString #^java.io.ByteArrayOutputStream this))]
212217
(proxy-super reset)
213218
(if (> (.length s) 0)
214219
(log level s nil log-ns)))))

0 commit comments

Comments
 (0)