[Log Utils] Make Non-Static/Modify backend.
@Jonathing がすでに取り組んでいます。
2025年5月15日 から。
評価
この issue はまだ評価されていません。
説明
Currently I am using a custom Logger that allows for using the Log4J backend.
Specifically its the use of the StringFormatterMessageFactory which allows for String.format style log commands:
info("[%3d/%3d] Running test", current, max)
[INFO] [ 1/100] Running Test
As well as exception as last argument support:
info("Failed to download %s", fileName, ex)
[INFO] Failed to download version.json
java.io.IOException: File Not Found
at whatever
I also made it implement Closeable so I can do things like:
try (var l = log.push()) {
log.info("This is indented");
}
log.info("This is not");
At the end of the day it just drills down to log(Level, String) and log(Level, String, Object[]) so it doesn't need to use L4J levels, but allowing things to be instance based would allow the consumer to choose. I specifically care because I like L4J's logging to a file. Tho that can be easily duplicated without L4J.
package net.minecraftforge.ir.util;
import java.io.Closeable;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.StringFormatterMessageFactory;
public class Log implements Closeable {
private static Class<?> getCallerClass() {
StackTraceElement ste = Thread.currentThread().getStackTrace()[3];
try {
return Class.forName(ste.getClassName());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
private final Logger logger;
private int tabLevel = 0;
public Log() {
this(LogManager.getLogger(getCallerClass(), StringFormatterMessageFactory.INSTANCE));
}
public Log(Logger logger) {
this.logger = logger;
}
@Override
public void close() {
tabLevel--;
}
public Log push() {
tabLevel++;
return this;
}
public Log pop() {
tabLevel--;
return this;
}
private String getIndent() {
return " ".repeat(tabLevel);
}
private void log(Level level, String message) {
logger.log(level, getIndent() + message);
}
private void log(Level level, String message, Object[] args) {
logger.log(level, getIndent() + message, args);
}
public void info(String message) {
log(Level.INFO, message);
}
public void info(String message, Object... args) {
log(Level.INFO, message, args);
}
public void warn(String message) {
log(Level.WARN, message);
}
public void warn(String message, Object... args) {
log(Level.WARN, message, args);
}
public void error(String message) {
log(Level.ERROR, message);
}
public void error(String message, Object... args) {
log(Level.ERROR, message, args);
}
public void debug(String message) {
log(Level.DEBUG, message);
}
public void debug(String message, Object... args) {
log(Level.DEBUG, message, args);
}
}
- 主要言語
- Java
- スター
- 0
- フォーク
- 5
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
MinecraftForge/Utils のほかの issue
-
MinecraftForge/Utils#8 · 担当者 1 名 ·
-
MinecraftForge/Utils#3 · 担当者 1 名 ·
-
MinecraftForge/Utils#2 · 担当者 2 名 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
MinecraftForge/Utils#1 · コメント 4 件 ·
-
MinecraftForge/Utils#13 · コメント 2 件 · 担当者 1 名 ·
MinecraftForge/Utils の issue をすべて見る
似ている issue
-
certification
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
[BUG] ECR GetAuthorizationToken returns a proxyEndpoint for the default region, not the request's オープンbug ecr
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
Needs: Triage Type: Feature request
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
AntennaPod/AntennaPod#8794 ·
-
agentic-workflows
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
github/copilot-sdk#2760 ·