-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add README for nrich-logging-spring-boot-starter-module
- Loading branch information
1 parent
638b882
commit 67a8382
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# nrich-logging-spring-boot-starter | ||
|
||
[](https://maven-badges.herokuapp.com/maven-central/net.croz.nrich/nrich-logging-spring-boot-starter) | ||
|
||
## Overview | ||
|
||
Spring Boot starter for nrich-logging module. The purpose of nrich-logging is to provide a unified and configurable logging format. It is used by nrich-webmvc module to log exceptions, it also allows | ||
logging level and logging verbosity (details about exception) to be easily configured through `message.properties`. | ||
Starter module provides a `@Configuration` class with default configuration of nrich-logging module (while allowing for overriding with conditional annotations) and does automatic registration | ||
through `spring.factories`. | ||
|
||
## Usage | ||
|
||
### Adding the Dependency | ||
|
||
The artifact is published on [Maven Central Repository][Maven Central]. To include the dependency use the following configurations. | ||
|
||
With Maven: | ||
|
||
```xml | ||
|
||
<dependency> | ||
<groupId>net.croz.nrich</groupId> | ||
<artifactId>nrich-logging-spring-boot-starter</artifactId> | ||
<version>${nrich.version}</version> | ||
</dependency> | ||
|
||
``` | ||
|
||
With Gradle: | ||
|
||
```groovy | ||
implementation "net.croz.nrich:nrich-logging-spring-boot-starter:${nrich.version}" | ||
``` | ||
|
||
Note if using nrich-bom dependency versions should be omitted. | ||
|
||
### Using the library | ||
|
||
After adding the dependency a bean of type `LoggingService` is available for dependency injection. The purpose of the `LoggingService` it to be used by `NotificationErrorHandlingRestControllerAdvice` | ||
to log uncaught exception but users can also use it to manually log caught exceptions. An example usage is given bellow (more detailed examples are found in nrich-logging README.MD): | ||
|
||
```java | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class ExampleService { | ||
|
||
private final LoggingService loggingService; | ||
|
||
public void executeAction() { | ||
try { | ||
// some operation that can throw an exception | ||
} | ||
catch (Exception exception) { | ||
loggingService.logInternalException(exception, null); | ||
} | ||
} | ||
} | ||
|
||
|
||
``` |