https://github.com/funcool/log4j2-clojure
A clojure specific appender implementation for Log4j2.
https://github.com/funcool/log4j2-clojure
Last synced: 6 months ago
JSON representation
A clojure specific appender implementation for Log4j2.
- Host: GitHub
- URL: https://github.com/funcool/log4j2-clojure
- Owner: funcool
- License: mpl-2.0
- Created: 2020-11-23T21:17:36.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-14T17:56:36.000Z (almost 5 years ago)
- Last Synced: 2025-06-06T16:51:49.461Z (7 months ago)
- Language: Java
- Size: 9.77 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A log4j2 appender for Clojure
This library exposes the appender implementation for log4j2 that calls
a user defined function for each log.
Requires JDK >= 11.
## Getting Started ##
Add dependencies:
```clojure
org.apache.logging.log4j/log4j-api {:mvn/version "2.13.3"}
org.apache.logging.log4j/log4j-core {:mvn/version "2.13.3"}
org.clojure/tools.logging {:mvn/version "1.1.0"}
funcool/log4j2-clojure {:mvn/version "2020.11.23-1"}
```
Configure logging (log4j2.xml):
```xml
```
This is a simple configuration that logs info (or greater levels) to
the console and to the `CljFn` appender. The `CljFn` appender will try
ti import the `some.ns/print-log` function and call it for each log
entry.
Example:
```clojure
(ns some.ns)
(defn print-log
[event]
(println (str event)))
```
The `event` is just a wrapper to the log4j2 LogEvent instance and it implementes IDeref
for obtain the original LogEvent and `.toString()` to format the log using the configured
layout (in this case the PatternLayout).
```clojure
user=> (require '[clojure.tools.logging :as log])
user=> (log/info "foobar")
[2020-11-23 22:12:39.648] [main] user - foobar
```