HyLogger is a console logging library designed for human programmers to read. Its APIs are simple and clean, and its color-coding features make logging more readable. It focuses on coloring features like color-coding.
TODO: Add support for universal System.err override
<!-- https://mvnrepository.com/artifact/org.hydev/HyLogger -->
<dependency>
<groupId>org.hydev</groupId>
<artifactId>HyLogger</artifactId>
<version>2.1.0.378</version>
</dependency>
// https://mvnrepository.com/artifact/org.hydev/HyLogger
compile group: 'org.hydev', name: 'HyLogger', version: '2.1.0.378'
It'll be available after clicking the reload button in IDEA!
Java:
HyLogger logger = new HyLogger("Scenario Name");
Kotlin:
val logger = HyLogger("Scenario Name")
Basic logging (they are basically the same for Kotlin and Java):
logger.log("Oak logs are the best.");
logger.debug("This is not logged if HyLoggerConfig.debug is off.");
logger.error("This could never happen in theory, right?");
logger.warning("Nerf this!");
Formatting with String.format()
:
logger.logf("Player %s just ate %.2f stardrops.", username, amount);
logger.errorf("Time has just been distorted by %.5f picoseconds.", timeDiff);
Formatting like SLF4J (This is completely useless in Kotlin):
logger.log("{}! {} Everywhere!", "Brackets", "Brackets");
logger.debug("User {} just posted {} on {}", user, json, board);
In Kotlin you can do this:
logger.debug("User $user tried to inject a SQL sequence: ${json.value}")
A. Use Minecraft Color-code:
Java:
logger.log(HyLoggerUtilsKt.parseFormats("&cHeck &eyeah!"));
Kotlin:
logger.log("&cHeck &eyeah!".parseFormats())
Java: (Import static AnsiColor.* first)
logger.log("{}I'm blue {}da ba dee da ba daa", BLUE, CYAN);
Kotlin: (Import AnsiColor.* first)
logger.log("${BLUE}I'm blue ${CYAN}da ba dee da ba daa")
Unlike the regular logging features, these fancy logging features need proper support by the terminal program you're using. The terminal programs with perfect compatibility for each platform are following: (If you found a new compatible program, please post an issue)
- All Platform: Terminus Alpha
- MacOS: iTerm
- Windows: Git Bash / MinTTY
- Linux: XFCE4 Terminal Emulator / Gnome-Terminal
Here is a list of incompatible programs:
- Windows: CMD / Powershell / Babun 1.2.0 / PowerCmd 2.2 / Xshell 5
- All Platform: Hyper
Here is a list of partially compatible programs: (Might not display TrueColor properly or have some bugs)
- Windows: Xshell 5 / Cmder 1.3.6 / CmdEmu 180626
How to add support for Eclipse terminal:
- Just use IntelliJ! It's 100% better.
- Or install
ANSI Escape in Console
plugin in Eclipse Marketplace.
Java:
logger.log("{}Awwwww", HyLoggerUtilsKt.foreground(new Color(252, 168, 187)));
Kotlin:
logger.log("${new Color(252, 168, 187).foreground()}Awwwww");
LinearGradient defines a gradient pattern on a single line. (Eg. Red to Blue)
There are several presets in the GradientPresets
class,
and you can create your own too.
Please see LoggerTest.kt for examples!
Eg.
logger.fancy.gradient("Orange to Pink Gradient", Color(255, 140, 0), Color(255, 0, 128))
// Resets the timer
logger.timing.reset();
// Print the elapsed time in ms and reset
logger.timing.time().reset();