Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add java option -Dauthlibinjector.logFile to customize the path of log file #206

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ gradle
开启此选项后, 日志仅会输出到控制台.

需要注意的是, authlib-injector 的日志是不会输出到 Minecraft 服务端/客户端的日志文件中的.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要编辑无关行。

每次启动时, 日志文件都会被清空. 如果有多个进程使用同一个日志文件, 则只有最早启动的会成功打开日志文件.

-Dauthlibinjector.logFile
指定日志文件输出位置.
可以填写绝对路径,也可以填写相对路径。
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

标点请用英文半角。此外,请修改对应的英文readme。

在 -Dauthlibinjector.noLogFile 选项开启后,本选项将会失效。

-Dauthlibinjector.mojangNamespace={default|enabled|disabled}
设置是否启用 Mojang 命名空间 (@mojang 后缀).
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/moe/yushi/authlibinjector/util/Logging.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import static java.nio.file.StandardOpenOption.WRITE;
import static moe.yushi.authlibinjector.util.Logging.Level.INFO;
import static moe.yushi.authlibinjector.util.Logging.Level.WARNING;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.*;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要使用通配符导入

import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.file.Path;
Expand All @@ -45,8 +42,15 @@ private static FileChannel openLogFile() {
log(INFO, "Logging to file is disabled");
return null;
}

Path logfilePath = Paths.get("authlib-injector.log").toAbsolutePath();

String logFileProperty = System.getProperty("authlibinjector.logFile");
Path logfilePath;
if (logFileProperty == null) {
logfilePath = Paths.get("authlib-injector.log").toAbsolutePath();
} else {
logfilePath = new File(logFileProperty).toPath().toAbsolutePath();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要使用 new File(...).toPath(),直接使用 Paths.get(...) 即可

}

try {
FileChannel channel = FileChannel.open(logfilePath, CREATE, WRITE);
if (channel.tryLock() == null) {
Expand Down