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

Support for LogLevel in EffLog #6659

Merged
merged 36 commits into from
Jul 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0217ab5
Improved EffLog
EquipableMC May 8, 2024
a8572a1
Update EffLog.java
EquipableMC May 8, 2024
66ad0c1
Update EffLog.java
EquipableMC May 8, 2024
ad9c652
Update EffLog.java
EquipableMC May 8, 2024
6d5d7ba
Update EffLog.java
EquipableMC May 8, 2024
2a57b56
Merge branch 'dev/feature' into dev/feature
EquipableMC May 8, 2024
570d764
Update EffLog.java
EquipableMC May 8, 2024
413d717
Update EffLog.java
EquipableMC May 8, 2024
d12f89b
Update EffLog.java
EquipableMC May 8, 2024
ef9ab68
Update EffLog.java
EquipableMC May 8, 2024
c09984f
Merge branch 'SkriptLang:dev/feature' into dev/feature
EquipableMC May 10, 2024
806cbcc
Update EffLog.java
EquipableMC May 10, 2024
fc37d4f
Update EffLog.java
EquipableMC May 12, 2024
080515c
Merge branch 'dev/feature' into dev/feature
sovdeeth May 13, 2024
078265c
Update EffLog.java
EquipableMC May 13, 2024
244fa08
Update EffLog.java
EquipableMC May 13, 2024
3500a4b
Update EffLog.java
EquipableMC May 13, 2024
797573e
Update EffLog.java
EquipableMC May 13, 2024
b24be61
Update EffLog.java
EquipableMC May 16, 2024
e0faf82
Update EffLog.java
EquipableMC May 19, 2024
a2b117f
Update EffLog.java
EquipableMC May 27, 2024
694024b
Update EffLog.java
EquipableMC Jun 1, 2024
55e92ba
Update EffLog.java
EquipableMC Jun 1, 2024
5081bae
Update EffLog.java
EquipableMC Jun 5, 2024
b4675df
Merge branch 'dev/feature' into dev/feature
Moderocky Jun 11, 2024
b8b5b7d
Update EffLog.java
EquipableMC Jun 11, 2024
88ef745
Merge branch 'dev/feature' into dev/feature
Moderocky Jun 28, 2024
baefbfb
Merge branch 'dev/feature' into dev/feature
EquipableMC Jun 28, 2024
4009d45
Update EffLog.java
EquipableMC Jun 28, 2024
22ab0ec
Merge branch 'dev/feature' of https://github.com/EquipableMC/Skript i…
EquipableMC Jun 28, 2024
0cb99cc
Update EffLog.java
EquipableMC Jun 28, 2024
d8f4c4b
Update EffLog.java
EquipableMC Jun 28, 2024
6406a05
Merge branch 'dev/feature' into dev/feature
sovdeeth Jun 28, 2024
251419c
Update EffLog.java
EquipableMC Jul 1, 2024
cebf1c3
Update EffLog.java
EquipableMC Jul 1, 2024
bb279ee
Merge branch 'dev/feature' into dev/feature
sovdeeth Jul 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions src/main/java/ch/njol/skript/effects/EffLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
@Since("2.0")
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
public class EffLog extends Effect {
static {
Skript.registerEffect(EffLog.class, "log %strings% [(to|in) [file[s]] %-strings%]");
Skript.registerEffect(EffLog.class, "log %strings% [to|in [file[s]] %-strings%] [with severity of] [1:warning|2:severe]");
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
}

private final static File logsFolder = new File(Skript.getInstance().getDataFolder(), "logs");
Expand All @@ -77,12 +77,17 @@ public void close() {
private Expression<String> messages;
@Nullable
private Expression<String> files;


private static final int WARNING = 1, SEVERE = 2;
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved

private int mark;
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved

@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
messages = (Expression<String>) exprs[0];
files = (Expression<String>) exprs[1];
mark = parser.mark;
return true;
}

Expand All @@ -91,23 +96,31 @@ public boolean init(final Expression<?>[] exprs, final int matchedPattern, final
protected void execute(final Event e) {
for (final String message : messages.getArray(e)) {
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
if (files != null) {
for (String s : files.getArray(e)) {
s = s.toLowerCase(Locale.ENGLISH);
if (!s.endsWith(".log"))
s += ".log";
if (s.equals("server.log")) {
for (String logFile : files.getArray(e)) {
logFile = logFile.toLowerCase(Locale.ENGLISH);
if (!logFile.endsWith(".log"))
logFile += ".log";
if (logFile.equals("server.log")) {
if (mark == 1) {
SkriptLogger.LOGGER.log(Level.WARNING, message);
continue;
}
else if (mark == 2) {
SkriptLogger.LOGGER.log(Level.SEVERE, message);
continue;
}
SkriptLogger.LOGGER.log(Level.INFO, message);
continue;
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
}
PrintWriter w = writers.get(s);
PrintWriter w = writers.get(logFile);
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
if (w == null) {
final File f = new File(logsFolder, s); // REMIND what if s contains '..'?
final File f = new File(logsFolder, logFile); // REMIND what if logFile contains '..'?
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
try {
f.getParentFile().mkdirs();
w = new PrintWriter(new BufferedWriter(new FileWriter(f, true)));
writers.put(s, w);
writers.put(logFile, w);
} catch (final IOException ex) {
Skript.error("Cannot write to log file '" + s + "' (" + f.getPath() + "): " + ExceptionUtils.toString(ex));
Skript.error("Cannot write to log file '" + logFile + "' (" + f.getPath() + "): " + ExceptionUtils.toString(ex));
return;
}
}
Expand All @@ -122,6 +135,13 @@ protected void execute(final Event e) {
if (script != null)
scriptName = script.getConfig().getFileName();
}

if (mark == 1) {
Skript.warning("[" + scriptName + "] " + message);
}
if (mark == 2) {
Skript.error("[" + scriptName + "] " + message);
}
Skript.info("[" + scriptName + "] " + message);
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down