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
35 changes: 24 additions & 11 deletions src/main/java/ch/njol/skript/effects/EffLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@
@Description({"Writes text into a .log file. Skript will write these files to /plugins/Skript/logs.",
"NB: Using 'server.log' as the log file will write to the default server log. Omitting the log file altogether will log the message as '[Skript] [<script>.sk] <message>' in the server log."})
@Examples({"on place of TNT:",
" log \"%player% placed TNT in %world% at %location of block%\"",
" log \"%player% placed TNT in %world% at %location of block%\" to file \"tnt/placement.log\"",
" log \"%player% placed TNT in %world% at %location of block%\" to file \"tnt/placement.log\"\"with a severity of warning\""})
"log \"%player% placed TNT in %world% at %location of block%\"",
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
"log \"A TNT was just placed at %location of block%!\" to file \"tnt/placement.log\"",
"log \"A player named %player% just placed a TNT in %world%!\" to file \"tnt/placement.log\"\"with a severity of warning\""})


@Since("2.0, INSERT VERSION (Adds severity to logs)")
@Since("2.0, INSERT VERSION (severities)")
public class EffLog extends Effect {
static {
Skript.registerEffect(EffLog.class, "log %strings% [(to|in) [file[s]] %-strings%] [with [the|a] severity [of] (1:warning|2:severe)]");
}

private static File logsFolder = new File(Skript.getInstance().getDataFolder(), "logs");
private static final File logsFolder = new File(Skript.getInstance().getDataFolder(), "logs");

static HashMap<String, PrintWriter> writers = new HashMap<>();
final static HashMap<String, PrintWriter> writers = new HashMap<>();
static {
Skript.closeOnDisable(new Closeable() {
@Override
Expand All @@ -80,6 +80,8 @@ public void close() {
private Expression<String> files;

private Level logLevel = Level.INFO;
private static final int WARNING_LOG = 900;
private static final int SEVERE_LOG = 1000;

@SuppressWarnings({"unchecked", "null"})
@Override
Expand Down Expand Up @@ -118,7 +120,18 @@ protected void execute(Event event) {
return;
}
}
logWriter.println("[" + SkriptConfig.formatDate(System.currentTimeMillis()) + "] " + message);
String levelType;
switch (logLevel.intValue()) {
case WARNING_LOG:
levelType = "WARNING";
break;
case SEVERE_LOG:
levelType = "SEVERE";
break;
default:
levelType = "INFO";
}
logWriter.println("[" + levelType + "]" + "[" + SkriptConfig.formatDate(System.currentTimeMillis()) + "] " + message);
EquipableMC marked this conversation as resolved.
Show resolved Hide resolved
logWriter.flush();
}
} else {
Expand All @@ -130,10 +143,10 @@ protected void execute(Event event) {
scriptName = script.getConfig().getFileName();
}
switch (logLevel.intValue()) {
case 900: // warning
case WARNING_LOG:
Skript.warning("[" + scriptName + "] " + messages);
break;
case 1000: // severe
case SEVERE_LOG:
Skript.error("[" + scriptName + "] " + messages);
break;
default:
Expand All @@ -147,10 +160,10 @@ protected void execute(Event event) {
public String toString(@Nullable Event e, boolean debug) {
String levelType;
switch (logLevel.intValue()) {
case 900:
case WARNING_LOG:
levelType = "warning ";
break;
case 1000:
case SEVERE_LOG:
levelType = "severe ";
break;
default:
Expand Down