https://github.com/sshtools/slf4j-tty
An SLF4J provider focused on pretty console logging output.
https://github.com/sshtools/slf4j-tty
ansi coloured java logging slf4j tty
Last synced: 3 months ago
JSON representation
An SLF4J provider focused on pretty console logging output.
- Host: GitHub
- URL: https://github.com/sshtools/slf4j-tty
- Owner: sshtools
- License: mit
- Created: 2024-05-07T10:24:09.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-01T11:12:40.000Z (8 months ago)
- Last Synced: 2025-01-23T00:13:30.762Z (4 months ago)
- Topics: ansi, coloured, java, logging, slf4j, tty
- Language: Java
- Homepage:
- Size: 414 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SLF4J TTY
[](https://maven-badges.herokuapp.com/maven-central/com.sshtools/slf4j-tty)
[](https://javadoc.io/doc/com.sshtools/slf4j-tty)
A colourful logger provider for SLF4J for making your console log output pretty.
*Note this is not intended for logging to a file, although there are options to do so. This provider is focused on console log output'*
Requires any modern terminal that has ANSI color and emoticon support.

## Who Is This For?
* You have a console application that uses SL4F4J and you want pretty output
* You have a console application that pipes logged output to another application and you want to capture simple log output in a consistent manner.## Features
* Flexible configuration based on INI files.
* Live configuration changes.
* Style a log event according to log priority level.
* Style and decorate any field with color, styles and emoticons.
* Highlight parameters in parameterized log events.
* Output resizes automatically with terminal
* JSON output option
## UsageSLF4J-TTY is in Maven central, so simply add the dependency to your project.
```xml
com.sshtools
slf4j-tty
0.0.3```
_See badge above for version available on Maven Central. Snapshot versions are in the [Sonatype OSS Snapshot Repository](https://oss.sonatype.org/content/repositories/snapshots/)._
## DesignSLF4J-TTY kind of steps outside of SLF4Js intended design a bit. Usually, any particular provider would actually be an adapter to a separate (existing) logging framework, for example Log4J.
However, given SLF4J has become the de-facto standard, and all the projects I intend to use SLF4J-TTY with use it, I saw little point right now in implementing an entirely new logging framework.
So instead, SLF4J-TTY is more basically more like `slf4j-simple`, which is the simple provider that implements the SLF4J API directly. The code in fact was based on this provider.
## TODO
This is the very first alpha release. There are a few bugs, and incompete areas.
* No way to load defaults from classpath resource.
* Live configuration reloading not implemented.## Configuration
Configuration is achieved using INI format files. The library comes with a pre-defined default, which you can override any and all properties using a resource in your project.
Further configuration may be achieved by the user by creating either a system-wide or user specific file in the usual location for configuration the operating system in use.
### Defaults
The defaults used are as follows.
```ini
;
; Log
;[log]
enabled = TRUE
default-level = INFO
output = SYS_ERR
log-file =
[output]
style-as-level = TRUE
gap = 1
ellipsis = âĻ
width = 0
fallback-width = 132
parameter-style = @{bold ${parameter}}
layout = level, short-name, message, thread-name, date-time
[fields]
[fields.date-time]
alignment = RIGHT
type = DATE_TIME
format = SHORT
width = 23
style = @{faint ${date-time}}
[fields.level]
alignment = LEFT
width = 9
style = [${level}]
[fields.thread-id]
alignment = LEFT
width = 10
style = ${thread-id}
[fields.thread-name]
alignment = LEFT
width = 15
style = [${thread-name}]
[fields.message]
alignment = LEFT
width = 0
style =${message}
[fields.markers]
alignment = LEFT
width = 0
style = ${markers}
[fields.name]
alignment = LEFT
width = 0
style = ${name}
[fields.short-name]
alignment = LEFT
width = 15
style = @{bold ${short-name}}
[levels]
name = Levels
description = Configuration for each of the levels
[levels.TRACE]
text = đ TRACE
style = @{faint ${text}}
[levels.DEBUG]
text = đ DEBUG
style = @{italic,fg:cyan ${text}}
[levels.INFO]
text = âšī¸ INFO
style = @{fg:blue ${text}}
[levels.WARN]
text = â ī¸ WARN
style = @{fg:yellow ${text}}
[levels.ERROR]
text = â ERROR
style = @{bold,fg:red ${text}}
```### Styles Expressions
SLF4J-TTY uses Jline3's [StyleExpression](https://www.javadoc.io/doc/org.jline/jline/3.23.0/org/jline/style/StyleExpression.html) for it's `style` configuration items. With these, you can style the text for the item using any common support ANSI terminal sequence.
#### Selection Of Styles
* fg
* bg
* blink
* bold
* conceal
* crossed-out
* crossedout
* faint
* hidden
* inverse
* inverse-neg
* inverseneg
* italic
* underline