Skip to content

Commit

Permalink
Logger prefix (#50)
Browse files Browse the repository at this point in the history
* feat: logger prefix

* chore: update github actions

* chore: downgrade actions/checkout
  • Loading branch information
Ingrim4 authored Sep 28, 2020
1 parent 92b2b77 commit d90a52f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8
- uses: actions/cache@v1
- name: BuildTools cache
uses: actions/cache@v2
with:
path: ~/.m2/repository/org/spigotmc/spigot
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
key: ${{ runner.os }}-maven-${{ hashFiles('./.github/workflows/buildtools.sh') }}
restore-keys: |
${{ runner.os }}-maven-
- name: BuildTools
Expand All @@ -31,7 +32,7 @@ jobs:
mkdir dist
mv orebfuscator-plugin/target/orebfuscator-*.jar ./dist
- name: Upload artifacts
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v2
with:
name: Plugin
path: dist/
7 changes: 4 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ jobs:
uses: actions/setup-java@v1
with:
java-version: 1.8
- uses: actions/cache@v1
- name: BuildTools cache
uses: actions/cache@v2
with:
path: ~/.m2/repository/org/spigotmc/spigot
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
key: ${{ runner.os }}-maven-${{ hashFiles('./.github/workflows/buildtools.sh') }}
restore-keys: |
${{ runner.os }}-maven-
- name: BuildTools
Expand All @@ -31,7 +32,7 @@ jobs:
mvn clean package -pl orebfuscator-plugin -B --also-make -Dorebfuscator.version=$RELEASE_VERSION
mkdir dist
mv orebfuscator-plugin/target/orebfuscator-*.jar ./dist
- uses: ncipollo/release-action@v1
- uses: ncipollo/release-action@v2
with:
artifacts: "dist/*"
name: Release ${{ env.RELEASE_VERSION }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void initialize(Config config) {
throw new IllegalStateException("NMS protocol version was already initialized!");
}

OFCLogger.log("Searching NMS protocol for server version \"" + MinecraftVersion.getNmsVersion() + "\"!");
OFCLogger.info("Searching NMS protocol for server version \"" + MinecraftVersion.getNmsVersion() + "\"!");

switch (MinecraftVersion.getNmsVersion()) {
case "v1_16_R2":
Expand Down Expand Up @@ -69,7 +69,7 @@ public static void initialize(Config config) {
}

if (NmsInstance.instance != null) {
OFCLogger.log("NMS protocol for server version \"" + MinecraftVersion.getNmsVersion() + "\" found!");
OFCLogger.info("NMS protocol for server version \"" + MinecraftVersion.getNmsVersion() + "\" found!");
} else {
throw new RuntimeException("Server version \"" + MinecraftVersion.getNmsVersion() + "\" is currently not supported!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void onEnable() {
try {
// Check if protocolLib is enabled
if (this.getServer().getPluginManager().getPlugin("ProtocolLib") == null) {
OFCLogger.log("[OFC] ProtocolLib is not found! Plugin cannot be enabled.");
OFCLogger.info("[OFC] ProtocolLib is not found! Plugin cannot be enabled.");
return;
}

Expand All @@ -60,9 +60,10 @@ public void onEnable() {

// Load packet listener
this.packetListener = new PacketListener(this);

} catch(Exception e) {
OFCLogger.log(e);
OFCLogger.log(Level.SEVERE, "An error occurred by enabling plugin");
OFCLogger.log(Level.SEVERE, "An error occurred while enabling plugin");
OFCLogger.err(e);

this.getServer().getPluginManager().registerEvent(PluginEnableEvent.class, this, EventPriority.NORMAL, this::onEnableFailed, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void run() {
}
});
} catch (Exception e) {
OFCLogger.log(e);
OFCLogger.err(e);
} finally {
this.proximityHider.unlockPlayer(player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,38 @@

public class OFCLogger {

public static final Logger LOGGER = Logger.getLogger("Minecraft.OFC");
private static final String LOG_PREFIX = "[OFC] ";
public static final Logger LOGGER = Logger.getLogger("bukkit.orebfuscator");
private static final String LOG_PREFIX = "[Orebfuscator] ";

public static void warn(String message) {
OFCLogger.LOGGER.warning(message);
log(Level.WARNING, message);
}

/**
* Log an information
*/
public static void log(String message) {
OFCLogger.LOGGER.info(LOG_PREFIX + message);
public static void info(String message) {
log(Level.INFO, message);
}

/**
* Log with a specified level
*/
public static void log(Level level, String message) {
OFCLogger.LOGGER.log(level, message);
OFCLogger.LOGGER.log(level, LOG_PREFIX + message);
}

/**
* Log with a specified level and throwable
* Log an error
*/
public static void log(Level level, String message, Throwable throwable) {
OFCLogger.LOGGER.log(level, message, throwable);
public static void err(Throwable e) {
log(Level.SEVERE, e.getMessage(), e);
}

/**
* Log an error
* Log with a specified level and throwable
*/
public static void log(Throwable e) {
OFCLogger.LOGGER.severe(LOG_PREFIX + e.toString());
e.printStackTrace();
public static void log(Level level, String message, Throwable throwable) {
OFCLogger.LOGGER.log(level, LOG_PREFIX + message, throwable);
}
}

0 comments on commit d90a52f

Please sign in to comment.