Skip to content

Commit bb8df80

Browse files
committed
feat(bukkit): Fix debug logging
1 parent 2083fbd commit bb8df80

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

inspector-bukkit/src/main/kotlin/plugin/TrackedPlugin.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import org.bukkit.generator.ChunkGenerator
88
import org.bukkit.plugin.java.JavaPlugin
99
import ru.endlesscode.inspector.bukkit.report.BukkitEnvironment
1010
import ru.endlesscode.inspector.bukkit.report.BukkitUnwrapReporter
11+
import ru.endlesscode.inspector.bukkit.util.debug
12+
import ru.endlesscode.inspector.bukkit.util.fixDebugLogs
1113
import ru.endlesscode.inspector.report.ReportEnvironment
1214
import ru.endlesscode.inspector.report.ReportedException
1315
import ru.endlesscode.inspector.report.Reporter
@@ -66,15 +68,15 @@ public abstract class TrackedPlugin @JvmOverloads constructor(
6668
reporter.enabled = environment.isInspectorEnabled
6769
reporter.addHandler(
6870
beforeReport = { message, data ->
69-
logger.log(Level.FINE, "$TAG $message", data.exception)
71+
logger.debug("$TAG $message", data.exception)
7072
},
7173
onSuccess = { message, _ ->
7274
logger.warning("$TAG $message")
7375
logger.warning("$TAG Error was reported to author!")
7476
},
7577
onError = {
7678
logger.warning("$TAG Error on report: ${it.localizedMessage}")
77-
logger.log(Level.FINE, TAG, it)
79+
logger.debug(TAG, it)
7880
}
7981
)
8082
}
@@ -84,15 +86,16 @@ public abstract class TrackedPlugin @JvmOverloads constructor(
8486
val fileHandler = FileHandler("$logsDir/latest.log", true).apply {
8587
level = Level.ALL
8688
formatter = object : Formatter() {
87-
val timeFormatter = SimpleDateFormat("dd/MM/yy HH:mm:ss")
89+
val timeFormatter = SimpleDateFormat("MM/dd HH:mm:ss")
8890

8991
override fun format(record: LogRecord): String {
90-
val message = "[${timeFormatter.format(Date(record.millis))} ${record.level}]: ${record.message}\n"
92+
val message = "[${timeFormatter.format(Date(record.millis))}][${record.level}]: ${record.message}\n"
9193
return record.thrown?.stackTraceText?.let { "$message$it" } ?: message
9294
}
9395
}
9496
}
9597
logger.addHandler(fileHandler)
98+
logger.fixDebugLogs()
9699
}
97100

98101
protected abstract fun createReporter(): Reporter
@@ -131,7 +134,7 @@ public abstract class TrackedPlugin @JvmOverloads constructor(
131134
sender: CommandSender,
132135
command: Command,
133136
label: String,
134-
args: Array<out String>
137+
args: Array<out String>,
135138
): Boolean {
136139
return track("Exception occurred on command '$label' with arguments: ${args.contentToString()}") {
137140
lifecycle.onCommand(sender, command, label, args)
@@ -142,7 +145,7 @@ public abstract class TrackedPlugin @JvmOverloads constructor(
142145
sender: CommandSender,
143146
command: Command,
144147
alias: String,
145-
args: Array<out String>
148+
args: Array<out String>,
146149
): MutableList<String>? {
147150
return track {
148151
lifecycle.onTabComplete(sender, command, alias, args)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ru.endlesscode.inspector.bukkit.util
2+
3+
import java.util.logging.Level
4+
import java.util.logging.Logger
5+
6+
private const val DEBUG_TAG = "[DEBUG]"
7+
8+
internal fun Logger.debug(message: String, throwable: Throwable) {
9+
log(Level.INFO, "$DEBUG_TAG$message", throwable)
10+
}
11+
12+
internal fun Logger.fixDebugLogs() {
13+
// Use INFO level and replace it with FINE after isLoggable check.
14+
setFilter { record ->
15+
if (record.message?.startsWith(DEBUG_TAG) == true) record.level = Level.FINE
16+
true
17+
}
18+
}

0 commit comments

Comments
 (0)