https://github.com/jhannes/logevents
An easy-to-extend implementation of SLF4J with batteries included and sensible defaults
https://github.com/jhannes/logevents
java library logging slf4j
Last synced: 11 months ago
JSON representation
An easy-to-extend implementation of SLF4J with batteries included and sensible defaults
- Host: GitHub
- URL: https://github.com/jhannes/logevents
- Owner: jhannes
- License: other
- Created: 2018-07-09T22:08:29.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2025-06-12T11:37:55.000Z (about 1 year ago)
- Last Synced: 2025-06-12T12:38:22.593Z (about 1 year ago)
- Topics: java, library, logging, slf4j
- Language: Java
- Homepage:
- Size: 11.8 MB
- Stars: 44
- Watchers: 3
- Forks: 8
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-java - LogEvents
README
# Logevents - a simple SLF4J implementation
[](https://opensource.org/licenses/Apache-2.0)
[](https://maven-badges.herokuapp.com/maven-central/org.logevents/logevents)
[](https://jhannes.github.io/logevents/apidocs/)
[](https://github.com/jhannes/logevents/actions/workflows/delivery.yml)
[](https://coveralls.io/github/jhannes/logevents?branch=main)
[](https://snyk.io/test/github/jhannes/logevents?targetFile=pom.xml)
Setting up and configuring logging should be *easy*, whether you want to do it with configuration files or in code. Log
Events is a small (265kb, *no dependencies*) logging framework built on top of SLF4J - the logging lingua franka for
Java.
For detailed instructions, see [the manual](MANUAL.md).
## Quick start
### Add dependencies (for Maven)
```xml
org.slf4j
slf4j-api
2.0.7
org.logevents
logevents
0.5.0
runtime
```
### Simple configuration
```properties
root=WARN file,console
logger.org.example=INFO
logger.org.example.myapp=DEBUG,TRACE@marker=HTTP_REQUEST&mdc:user=admin
logevents.status=CONFIG
```
By default, the [`file`](https://jhannes.github.io/logevents/apidocs/org/logevents/observers/FileLogEventObserver.html) observer will log to a file named `logs/your-app-name-%date.log` and [`console`](https://jhannes.github.io/logevents/apidocs/org/logevents/observers/ConsoleLogEventObserver.html) logs ANSI-colored logs to the console.
The default level for loggers with this configuration will be `WARN`, by `org.example` will log at `INFO` and `org.example.myapp` will log at `DEBUG`, or trace for HTTP_REQUEST when the `user` is `admin`. See [LogEventFilter](https://jhannes.github.io/logevents/apidocs/org/logevents/impl/LogEventFilter.html) for details. Use level `NONE` to turn off logging.
Logevents will output [configuration information](https://jhannes.github.io/logevents/apidocs/org/logevents/status/package-summary.html) to system err.
### Configuration in a [Twelve-Factor](https://12factor.net/) setting
Here is an example setup in a cloud environment. Logevents can be configured with environment variables and use stdout as the main channel for logging, outputting JSON logs for more powerful downstream parsing
```bash
# Output logevents configuration debug to stderr
LOGEVENTS_STATUS=CONFIG
# Skip sun.reflect packages in stack traces
LOGEVENTS_PACKAGEFILTER=sun.reflect
# By default only output to console at DEBUG
LOGEVENTS_ROOT=DEBUG console
# Console format should be JSON for easier log parsing
LOGEVENTS_OBSERVER_CONSOLE_FORMATTER=ConsoleJsonLogEventFormatter
# Install logging to Microsoft Teams for all ERROR messages
LOGEVENTS_ROOT_OBSERVER_TEAMS=ERROR
LOGEVENTS_OBSERVER_TEAMS=MicrosoftTeamsLogEventObserver
LOGEVENTS_OBSERVER_TEAMS_URL=https://example.webhook.office.com/webhookb2/...
# Turn down logging for selected packages
LOGEVENTS_LOGGER_ORG_ECLIPSE_JETTY=WARN
# Turn up logging to TRACE for com.example message for selected users are
LOGEVENTS_LOGGER_COM_EXAMPLE=DEBUG,TRACE@mdc:user=superuser|admin|tester
```
## Features:
* [Console logging](https://jhannes.github.io/logevents/apidocs/org/logevents/observers/ConsoleLogEventObserver.html)
with good default colors (also on Windows). Use `observer.console.format=ConsoleJsonLogEventFormatter` to output
single-line JSON logs, suitable for log parsing
* [File logging](https://jhannes.github.io/logevents/apidocs/org/logevents/observers/FileLogEventObserver.html) with
reasonable defaults
* [JUnit support](https://jhannes.github.io/logevents/apidocs/org/logevents/optional/junit/ExpectedLogEventsRule.html) to
easy assert on what is logged
* [Email logging](https://jhannes.github.io/logevents/apidocs/org/logevents/observers/SmtpLogEventObserver.html),
including throttling to reduce spamming when get lots of log messages
* [Slack](https://jhannes.github.io/logevents/apidocs/org/logevents/observers/SlackLogEventObserver.html) to send log
messages to you favorite chat channel
* [Microsoft Teams](https://jhannes.github.io/logevents/apidocs/org/logevents/observers/MicrosoftTeamsLogEventObserver.html)
* [Logging to database](https://jhannes.github.io/logevents/apidocs/org/logevents/observers/DatabaseLogEventObserver.html)
* [Display logs on a web dashboard](https://jhannes.github.io/logevents/apidocs/org/logevents/observers/WebLogEventObserver.html)
* [Elasticsearch](https://jhannes.github.io/logevents/apidocs/org/logevents/observers/ElasticsearchLogEventObserver.html)
. Logging directly to Elastic search Index API avoids edge cases when writing and parsing log files
* [Humio](https://jhannes.github.io/logevents/apidocs/org/logevents/observers/HumioLogEventObserver.html)
. Logging directly to Humio via their [Elastic search Bulk API](https://library.humio.com/stable/docs/ingesting-data/log-shippers/other-log-shippers/#elasticsearch-bulk-api).
* [Azure Application Insights](https://jhannes.github.io/logevents/apidocs/org/logevents/optional/azure/ApplicationInsightsLogEventObserver.html) (
requires optional com.microsoft.azure:applicationinsights-core dependency)
* [JMX integration](https://jhannes.github.io/logevents/apidocs/org/logevents/jmx/LogEventsMBeanFactory.html) to view
the configuration and tweak log levels
* [Filter loggers](https://jhannes.github.io/logevents/apidocs/org/logevents/core/LogEventFilter.html) on
markers and MDC values (e.g. `logger.org.example.app=INFO,DEBUG@mdc:user=superuser|admin`)
* [Filter observers](https://jhannes.github.io/logevents/apidocs/org/logevents/core/AbstractFilteredLogEventObserver.html)
on markers and MDC values