[Log Utils] Make Non-Static/Modify backend.
@Jonathing đang làm issue này rồi.
Từ ngày 15/5/2025.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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);
}
}
- Ngôn ngữ chính
- Java
- Star
- 0
- Fork
- 5
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của MinecraftForge/Utils
-
[Download Utils] Method to grab the header.Có thể làm lại được @Jonathing đã nhận 514 ngày trước và không có pull request nào đang mở. Đang mở
MinecraftForge/Utils#8 · 1 người được giao ·
-
[Download Utils] Path supportCó thể làm lại được @LexManos đã nhận 352 ngày trước và không có pull request nào đang mở. Đang mở
MinecraftForge/Utils#3 · 1 người được giao ·
-
[Hash Utils] CRC32 supportCó thể làm lại được @PaintNinja đã nhận 352 ngày trước và không có pull request nào đang mở. Đang mở
MinecraftForge/Utils#2 · 2 người được giao ·
-
Logger Utils DiscussionĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
MinecraftForge/Utils#1 · 4 bình luận ·
-
[Download Utils] No download timeout causes downloads to hang if a server doesn't respondCó thể làm lại được @Jonathing đã nhận 352 ngày trước và không có pull request nào đang mở. Đang mở
MinecraftForge/Utils#13 · 2 bình luận · 1 người được giao ·
Tất cả issue của MinecraftForge/Utils
Issue tương tự
-
Flight SQL JDBC parses boolean properties case-sensitively, silently disabling TLS for useEncryption=TRUECó thể đã có người làm @Arawoof06 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
apache/arrow-java#1357 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
apache/rocketmq-dashboard#6610 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
MetricsHub/metricshub-community#1396 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
L: java:gradle L: java:maven L: ruby:bundler T: bug 🐞
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
dependabot/dependabot-core#16547 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Citationcount column sorts alphabetically instead of numericallyCó thể đã có người làm @kpunia306 đã nhận hôm nay. Đang mởstatus: needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
JabRef/jabref#17459 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày