Skip to content

Commit

Permalink
Merge pull request #11 from GoodforGod/dev
Browse files Browse the repository at this point in the history
[0.15.0]
  • Loading branch information
GoodforGod authored Apr 19, 2022
2 parents 065422a + 24d9020 commit 4206988
Show file tree
Hide file tree
Showing 12 changed files with 1,130 additions and 61 deletions.
80 changes: 76 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,27 @@ This logger is great for applications that use synchronous output or run in sing
Features:
- Performance optimizations.
- GraalVM friendly.
- JSON format support.
- Environment variables logging.
- [slf4j-simple-logger](https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html) compatible configuration.

And more...

## Dependency :rocket:

Java 11+ compatible.

[**Gradle**](https://mvnrepository.com/artifact/io.goodforgod/slf4j-simple-logger)
```groovy
implementation "io.goodforgod:slf4j-simple-logger:0.14.1"
implementation "io.goodforgod:slf4j-simple-logger:0.15.0"
```

[**Maven**](https://mvnrepository.com/artifact/io.goodforgod/slf4j-simple-logger)
```xml
<dependency>
<groupId>io.goodforgod</groupId>
<artifactId>slf4j-simple-logger</artifactId>
<version>0.14.1</version>
<version>0.15.0</version>
</dependency>
```

Expand All @@ -39,8 +42,11 @@ Based on SLF4J 1.7.36
## Content

- [Logging example](#logging-example)
- [Text format](#text-format)
- [Json format](#json-format)
- [Features](#features)
- [Performance Optimizations](#performance-optimizations)
- [Output format](#output-format)
- [DateTime output](#datetime-output)
- [Logger name abbreviation](#logger-name-abbreviation)
- [Environment logging](#environment-logging)
Expand All @@ -53,12 +59,14 @@ Based on SLF4J 1.7.36

## Logging example

Below is example of logged message:
### Text format

Below is example of logged message in text format:
```java
logger.debug("Message is printed for this logger");
```

And the detailed result:
Result logged message:
```text
Date Time Implementation Log Level Environment variables Thread Logger Name Log Message
| | | | | | |
Expand All @@ -68,6 +76,48 @@ ___________|__________ ______|_______ __|__ ___________________|__________
2022-02-23T15:43:40.331 [0.9.0-SNAPSHOT] [DEBUG] [SESSION=Console, PROCESSOR_LEVEL=6] [main] io.goodforgod.Application - Message is printed for this logger
```

### Json format

Below is example of logged message in json format:
```java
Exception e = new RuntimeException();
logger.debug("Message is printed for this logger", e);
```

Result logged message:
```json
{
"timestamp": "2022-02-23T15:43:40.331",
"implementation": "0.9.0-SNAPSHOT",
"level": "DEBUG",
"thread": "main",
"logger": "io.goodforgod.Application",
"environment": [
{
"name": "SESSION",
"value": "Console"
},
{
"name": "PROCESSOR_LEVEL",
"value": "6"
}
],
"message": "Message is printed for this logger",
"exception": "Ops",
"stacktrace": [
{
"clazz": "io.goodforgod.slf4j.simplelogger.JsonLoggerLayoutTests",
"message": "Ops",
"method": "throwableOutput:279"
},
{
"clazz": "jdk.internal.reflect.NativeMethodAccessorImpl",
"method": "invoke0:-2"
}
]
}
```

## Features

### Performance optimizations
Expand All @@ -76,6 +126,24 @@ This implementation is based on default *slf4j-simple-logger*, but there are ple

Some cases are 200% faster others are 800% faster, you can read more about here in my [JVM benchmark](https://github.com/GoodforGod/java-logger-benchmark).

### Output format

There is option to output logged messages in different formats, currently supported formats:
- TEXT
- JSON

You can check example of each format [here](#logging-example).

Configuration for format is below for TEXT (default value).
```properties
org.slf4j.simpleLogger.format=TEXT
```

And same for JSON:
```properties
org.slf4j.simpleLogger.format=JSON
```

### DateTime output

There are three options to output date & time:
Expand Down Expand Up @@ -170,6 +238,8 @@ Only these properties can be changed in runtime:
```properties
# Default logging level for all loggers. Must be one of ("TRACE", "DEBUG", "INFO", "WARN", or "ERROR"). (default INFO)
org.slf4j.simpleLogger.defaultLogLevel=INFO
# Set logging message output format. Must be one of ("TEXT", "JSON"). (default TEXT)
org.slf4j.simpleLogger.format=TEXT
# Set to true to show current datetime in output. (default true)
org.slf4j.simpleLogger.showDateTime=true
# Set datetime output type. Must be one of ("TIME", "DATE_TIME", "UNIX_TIME", "MILLIS_FROM_START"). (default DATE_TIME)
Expand Down Expand Up @@ -248,6 +318,8 @@ Example of full *simplelogger.properties* file:
```properties
# Default logging level for all loggers. Must be one of ("TRACE", "DEBUG", "INFO", "WARN", or "ERROR"). (default INFO)
org.slf4j.simpleLogger.defaultLogLevel=INFO
# Set logging message output format. Must be one of ("TEXT", "JSON"). (default TEXT)
org.slf4j.simpleLogger.format=TEXT
# Set to true to show current datetime in output. (default true)
org.slf4j.simpleLogger.showDateTime=true
# Set datetime output type. Must be one of ("TIME", "DATE_TIME", "UNIX_TIME", "MILLIS_FROM_START"). (default DATE_TIME)
Expand Down
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.8.2"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.8.2"
testImplementation "org.junit.jupiter:junit-jupiter-params:5.8.2"
testImplementation "org.skyscreamer:jsonassert:1.5.0"
}

test {
Expand All @@ -39,6 +40,10 @@ test {
html.enabled(false)
junitXml.enabled(false)
}

environment([
"A_KEY_LOG_LEVEL": "off",
])
}

spotless {
Expand Down Expand Up @@ -66,7 +71,7 @@ publishing {
pom {
name = "SLF4J Simple Logger"
url = "https://github.com/GoodforGod/$artifactId"
description = "SLF4J based, simple, GraalVM friendly, efficient logger that is great for Serverless applications, single-thread or CLI applications."
description = "SLF4J based, simple, efficient logger that is great for Serverless applications, single-thread or CLI applications."

license {
name = "Apache License 2.0"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
groupId=io.goodforgod
artifactId=slf4j-simple-logger
artifactVersion=0.14.1
artifactVersion=0.15.0


##### GRADLE #####
Expand Down
Loading

0 comments on commit 4206988

Please sign in to comment.