Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/skjolber/logback-logstash-syntax-highlighting-decorators

Syntax highlighting JSON decorator for logstash-logback-encoder
https://github.com/skjolber/logback-logstash-syntax-highlighting-decorators

ansi colors jackson json kibana logback logstash syntax-highlighting

Last synced: 14 days ago
JSON representation

Syntax highlighting JSON decorator for logstash-logback-encoder

Awesome Lists containing this project

README

        

![Build Status](https://github.com/skjolber/logback-logstash-syntax-highlighting-decorators/actions/workflows/maven.yml/badge.svg)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.skjolber.logback-logstash-syntax-highlighting-decorators/logback-logstash-syntax-highlighting-decorators.svg)](https://mvnrepository.com/artifact/com.github.skjolber.logback-logstash-syntax-highlighting-decorators/logback-logstash-syntax-highlighting-decorators)

# This project is currently maintained at [Entur](https://github.com/entur/logback-logstash-syntax-highlighting-decorators).

# logback-logstash-syntax-highlighting-decorators
ANSI syntax highlighting for [logstash-logback-encoder] JSON output.

Features:
* Syntax highlighting (and pretty printing)
* Special field handling
* Level: trace, debug, info, warn and error
* Message

The primary use-case for this tool is coloring JSON console-output during __local development / unit testing__.

In production rather configure an encoder without a `Decorator` and apply proper visualization tools like [Kibana].
Use [conditional processing] to differentiate between different environments in [Logback] configuration.

## Example output

![Example](docs/logLevel.png?raw=true "Example")

## License
[Apache 2.0]

# Obtain
The project is based on [Maven] and is available at central Maven repository.

Maven coordinates

Add the property
```xml
1.0.6
```

then add

```xml

com.github.skjolber.logback-logstash-syntax-highlighting-decorators
logback-logstash-syntax-highlighting-decorators
${logback-logstash-syntax-highlighting-decorators.version}

```

or

Gradle coordinates

For

```groovy
ext {
logbackLogstashSyntaxHighlightingDecoratorsVersion = '1.0.6'
}
```

add

```groovy
implementation ("com.github.skjolber.logback-logstash-syntax-highlighting-decorators:logback-logstash-syntax-highlighting-decorators:${logbackLogstashSyntaxHighlightingDecoratorsVersion}")
```

# Usage
Add a [JsonGeneratorDecorator]:

```xml




```

The default decorator is aware of the log-level and highlights `WARN` and `ERROR` with yellow and red background colors.

## Custom colors
Define your own colors using `ConfigurableSyntaxHighlighter`:

```xml


blue
black highIntensity
red
yellowBackground
cyan
black
green
green
green
green
green

```

and space-separated foreground, background and style keys. For special handling of fields `message` and `level`, use the `LogLevelSyntaxHighlighterFactory`:

```xml



green
yellow
red

highIntensity blue

```

#### Pretty-printing
Pretty-printing (with newline + indent) is enabled by default. To disable it, a `prettyPrint`-element under `SyntaxHighlightingDecorator` like so:

```xml

false

```

### Foreground color
| Key | Text color |
| ----- | ----------- |
| default | Default text |
| black | Black text |
| red | Red text |
| green | Green text |
| yellow | Yellow text |
| blue | Blue text |
| magenta | Magneta text |
| cyan | Cyan text |
| white | White text |

### Background color
| Key | Background color |
| ----- | ----------- |
| defaultBackground | Default |
| blackBackground | Black |
| redBackground | Red |
| greenBackground | Green |
| yellowBackground | Yellow |
| blueBackground | Blue |
| magentaBackground | Magneta |
| cyanBackground | Cyan |
| whiteBackground | White |

### Style
| Key | Style |
| ----- | ----------- |
| highIntensity | High intensity (bold) |
| lowIntensity | Low instensity |
| italic | Italic
| underline | Underline
| blink| Blink |

## Details
The `SyntaxHighlightingDecorator` supports a list of `` elements. The colors are applied in chronological order. Highlighters not wanting to contribute to the current JSON event are expected to return an ANSI reset (including escaping).

## Tips and tricks
Exclude fields with low information value during testing. For example:

```xml



[ignore]
[ignore]

```

# History
- 1.0.6: Do not set default colors.
- 1.0.5: Add option for single-line output
- 1.0.1-1.0.4: Update Jackson dependency due to security issue and dependency updates
- 1.0.0: Initial version

[Apache 2.0]: http://www.apache.org/licenses/LICENSE-2.0.html
[issue-tracker]: https://github.com/skjolber/logback-logstash-syntax-highlighting-decorators/issues
[Maven]: http://maven.apache.org/
[1.0.2]: https://github.com/skjolber/logback-logstash-syntax-highlighting-decorators/releases/tag/logback-logstash-syntax-highlighting-decorators-1.0.1
[jackson-syntax-highlight]: https://github.com/skjolber/jackson-syntax-highlight
[Jackson]: https://github.com/FasterXML/jackson
[ANSI]: https://en.wikipedia.org/wiki/ANSI_escape_code
[JSON]: https://no.wikipedia.org/wiki/JSON
[JsonGeneratorDecorator]: https://github.com/logstash/logstash-logback-encoder/blob/master/src/main/java/net/logstash/logback/decorate/JsonGeneratorDecorator.java
[logstash-logback-encoder]: https://github.com/logstash/logstash-logback-encoder
[Kibana]: https://www.elastic.co/products/kibana
[conditional processing]: https://logback.qos.ch/manual/configuration.html#conditional
[Logback]: https://github.com/qos-ch/logback