Skip to content

Commit

Permalink
Logging 2147483647
Browse files Browse the repository at this point in the history
  • Loading branch information
Weathercold committed Jan 5, 2022
1 parent 815b10c commit 1aac752
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Extra Logging
[![Commit Testing](https://github.com/Weathercold/ExtraLogging/actions/workflows/commitTest.yml/badge.svg?branch=master)](https://github.com/Weathercold/ExtraLogging/actions/workflows/commitTest.yml) [![Total Downloads](https://img.shields.io/github/downloads/Weathercold/ExtraLogging/total?color=success&labelColor=gray&label=Downloads&logo=docusign&logoColor=white)](https://github.com/Weathercold/ExtraLogging/releases)\
Mindustry mod that adds more logging features.\
Mindustry mod that adds more logging features and improvements.\
I initially made this mod to better understand the order in which the events are triggered, now I decided to add more features and turn this into a mod. Also this is my first *published* mod.

## Features
- Enables the in-game console.
- Adds customisable log level<sup>[1]</sup>.
- **Adds timestamp for console messages**<sup>[1]</sup>.
- Removes `[colorname]`s for Java console.
- Optionally listens to important events and prints them to the console.
- **Optionally reenables/disables colored Java console**<sup>[2]</sup>.
- Optionally prints important event triggers to the console.
- Various other quality of life improvements.

## Details on event trigger order
Expand All @@ -33,4 +33,5 @@ The order in which the logs are displayed in the in-game console is weird, this

---

[1]: Only after the mod is created though
[1]: Only after the mod is created though\
[2]: For Windows and Android, you need a modern terminal that supports ANSI color codes. ~~This proves Linux is superior~~
4 changes: 2 additions & 2 deletions assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
extra-logging.displayName = Extra Logging

setting.extra-loglevel.name = Global Log Level
setting.extra-coloredjavaconsole.name = Add colors to Java console
setting.extra-coloredjavaconsole.name = Add colors to Java console [stat](Requires modern console)
setting.extra-enablemetalogging.name = Enable Meta Logging
setting.extra-metaloglevel.name = Meta Log Level
setting.extra-enableeventlogging.name = Enable Event Logging
setting.extra-enableeventlogging.name = Enable Event Logging [stat](Requires restart)
setting.extra-eventloglevel.name = Event Log Level
2 changes: 1 addition & 1 deletion mod.hjson
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
name: extra-logging
displayName: Extra Logging
description: "Adds more debugging features and improvements.\n\nFeatures include:\n - Enables the in-game console.\n - Adds customisable log level.\n - Adds timestamps for console messages.\n - Listens to events and prints them to the console.\n\nSee README.md for more information."
description: "Adds more debugging features and improvements.\n\nFeatures:\n - Enables the in-game console and sets log level to debug.\n - Adds timestamps for console messages.\n - Reenables colored Java console for Windows and Android.\n - Various other QoL improvements.\n\nSee README.md for more information."
author: "Weathercold"

version: 1.3.0
Expand Down
2 changes: 0 additions & 2 deletions src/logging/ExtraLogging.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public ExtraLogging(){

if (!enableEventLogging) return;
listeningEvents.each(c -> Events.on(c, e -> {
if (!enableEventLogging) return;

String fields = "";
for (Field field : c.getDeclaredFields()){
try {fields += " " + field.getName() + "=" + field.get(e);}
Expand Down
8 changes: 8 additions & 0 deletions src/logging/util/ColorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* @author Weathercold
*/
public class ColorUtils{

//region Fields

public static String
flush = "\033[H\033[2J",
reset = "\u001B[0m",
Expand Down Expand Up @@ -130,6 +133,9 @@ public class ColorUtils{
codes = codeMap.keys().toSeq(),
names = nameMap.keys().toSeq();

//endregion
//region Methods

public static String formatColors(String text, boolean useColors, Object... args){
text = Strings.format(text, args);
return useColors ? convertNames(convertCodes(text)) : removeColors(removeNames(removeCodes(text)));
Expand Down Expand Up @@ -169,4 +175,6 @@ public static String removeNames(String text){
for (String name : names) text = text.replace("[" + name + "]", "");
return text;
}

//endregion
}
7 changes: 4 additions & 3 deletions src/logging/util/ExtraLogHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @author Weathercold
*/
public class ExtraLogHandler implements LogHandler{
public String stmpl = "@ &lk[@]&fr @";
public String stmpl = "@ &lk[@] @@&fr";
public String[] stags = {"&lc&fb[D]&fr", "&lb&fb[I]&fr", "&ly&fb[W]&fr", "&lr&fb[E]&fr", " "};
public String tmpl = "@ [grey][@] [@]@";
/** Why isn't terminal font monospaced */
Expand All @@ -33,11 +33,12 @@ public ExtraLogHandler(){

@Override
public void log(LogLevel level, String text){
String rtext = formatColors(stmpl, coloredJavaConsole, stags[level.ordinal()], timef.format(LocalTime.now()), removeNames(text));
String time = timef.format(LocalTime.now());
String rtext = formatColors(stmpl, coloredJavaConsole, stags[level.ordinal()], time, text.startsWith("[EL]") ? "&ly" : "&fr", text);
System.out.println(rtext);

if(!headless){
String ftext = formatCons(tmpl, tags[level.ordinal()], timef.format(LocalTime.now()), text.startsWith("[EL]") ? "accent" : "white", text);
String ftext = formatCons(tmpl, tags[level.ordinal()], time, text.startsWith("[EL]") ? "accent" : "white", text);
if (ui == null || ui.scriptfrag == null) logBuffer.add(ftext);
else ui.scriptfrag.addMessage(ftext);
}
Expand Down

0 comments on commit 1aac752

Please sign in to comment.