Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/handsome-steve/colorfulloggerlib

This library is designed to simplify a specific aspect of Minecraft Modding workflows by making it easy to add ANSI color to your Logger calls.
https://github.com/handsome-steve/colorfulloggerlib

minecraft-fabric minecraft-fabric-mod modding-tools

Last synced: 4 days ago
JSON representation

This library is designed to simplify a specific aspect of Minecraft Modding workflows by making it easy to add ANSI color to your Logger calls.

Awesome Lists containing this project

README

        


Handsome Steve's Colorful Logger

[ko-fi]:https://ko-fi.com/handsomesteve
[modrinth]:https://modrinth.com/mod/colorfulloggerlib



[][ko-fi]
[][modrinth]







#### Ever wanted to add some color to your LOGGER during the development of your minecraft mods in a simple, yet functional manner?

Well look no further, Handsome Steve has you covered! This simple library allows you to do just that by utilizing a wide range of pre-defined ANSI codes.

**EDIT: Please prioritize the [Handsome Steve Maven](https://maven.handsomesteve.net/) as this also serves the Jar's Sources file.** Alternatively, the installation code below has been updated to reflect [Modrinth Maven](https://support.modrinth.com/en/articles/8801191-modrinth-maven) in case the maven is ever offline, apologies in for any inconveniences.



## FAQ
**Q: Is this a mod?**

Techinally, no. This is a library, so it's only really used when developing a mod, however, it may be required as a dependency when the dependent mod is being installed on a client/server depending on what platform the dependent mod is targeting and how the mod developer is utilising the library.



**Q: Can I use this library as a dependency in my project?**

Absolutely, go nuts!



**Q: Does this library require a specific Fabric Version?**

Nope, it's now standalone, so as long as your modding platform uses `org.slf4j.Logger`, it will work regardless of the version.


## Current Version
Please note that the current version only has the `Logger.info()` method colorized, the rest will be added in future updates, such as `Logger.error()` etc.


## Installation
Add the required Maven Repositories to your `build.gradle` in the *repositories* section:
```groovy
repositories {
// Initial Maven Repository
// Priority
exclusiveContent {
forRepository {
maven {
name = "Handsome Steve's Maven"
url = "https://maven.handsomesteve.net/releases"
}
}
filter {
includeGroup "net.handsomesteve"
}
}

// Modrinth Fallback Maven
// Optional, but strongly recommended
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
filter {
includeGroup "maven.modrinth"
}
}
}
```

Add an implementation to your `build.gradle` in the dependencies section:
```groovy
dependencies {
//Handsome Steve's Colorful Logger // This automatically downloads the sources file as well.
implementation include("net.handsomesteve:colorfulloggerlib:${project.hs_colorful_logger}")

// Modrinth Fallback (De-comment if preferred maven is down).
//implementation include ("maven.modrinth:colorfulloggerlib:${project.hs_colorful_logger}")
// SOURCES FILE NEEDS MANUAL DOWNLOAD, SEE BOTTOM OF PAGE (if using fallback maven).
}
```
> [**SEE:** Fabric - Dependency Configuration](https://fabricmc.net/wiki/documentation:fabric_loom#options)

> [**SEE:** Modrinth - Dependency configuration](https://support.modrinth.com/en/articles/8801191-modrinth-maven#h_2484bbd424)


Add the version variable to your `gradle.properties` and replace `{version}` by the desired available library version of your choice:
```groovy
hs_colorful_logger={version}
```

## Implementation
Create a `public static final` instance of the `ColorfulLogger` class. This instance will allow you to utilize the internal reference of `org.slf4j.Logger` from the `ColorfulLogger` class throughout your project.

```java
import net.handsomesteve.api.ColorfulLogger;
import net.handsomesteve.api.ansi.AnsiColorBackground;
import net.handsomesteve.api.ansi.AnsiColorText;

public class FabricMod implements ModInitializer {
public static final String MOD_ID = "your-mod-id";
public static final ColorfulLogger LOGGER = ColorfulLogger.getInstance("your-mod-id", false);

@Override
public void onInitialize() {
LOGGER.info(">>> This is a plain message without any colouring");
LOGGER.info(">>> I want some green text", AnsiColorText.ANSI_BRIGHT_GREEN);
LOGGER.info(">>> I want some red text with a black background", AnsiColorText.ANSI_BRIGHT_RED, AnsiColorBackground.ANSI_BLACK_BACK);
}
}
```

If required, the `Logger` can be interfaced with by calling it as follows:

```java
LOGGER.getLogger(); // Returns the Logger to be interfaced with.
```

This will, however, not implement the ANSI color coding to your output if accessed this way.

> **NOTE:** A `ColorfulLogger` variable can be declared anywhere in the project. It is recommended, however, ***to only ever declare this once as it is a singleton***.
>


> To import the declared variable as a *static import* when referencing the variable:
> ```java
> import static com.packagename.FabricMod.LOGGER;
> ```

> **ALTERNATIVELY:** `ColorfulLogger` can be instantiated anywhere in the project as follows if required after the singleton is declared:
> ```java
> public class References {
> private static final ColorfulLogger LOGGER = ColorfulLogger.getInstance();
>
> public static ColorfulLogger getLogger() {
> return LOGGER;
> }
> }
> ```
> Then accessed:
> ```java
> import static com.package.References.getLogger;
>
> public class MyClass {
> References.getLogger();
> }
> ```


## Sources
### [Only if using Modrinth Maven as a dependency]
*

There is a sources file available in the versions download.

*

This is a well define sources file where all variables, methods and constructors are well-defined as well as the class itself.
You should download and add this file in the folder path:

```
.gradle/loom-cache/remapped_mods/net_fabricmc_yarn{version}/maven/colorfulloggerlib/{hs_colorful_logger_version}/
```
> **Note:** Replace curly-braced text with current versions etc.