Smol code optimization
This commit is contained in:
parent
2f9700e28d
commit
9f538fe685
2 changed files with 13 additions and 35 deletions
|
@ -78,21 +78,14 @@ class NativeThreadingHandler : ThreadingHandler {
|
|||
.uncaughtExceptionHandler { thread, throwable -> logger.crash("Logging thread terminated unexpectedly", throwable) }
|
||||
.start {
|
||||
var time: ULong
|
||||
var waitTime: ULong
|
||||
while (active) {
|
||||
time = measureTimeMillis { flush() }.toULong()
|
||||
|
||||
if (EngineConfiguration.logThreadingPollDelay > 0u)
|
||||
if (time > EngineConfiguration.logThreadingPollDelay) {
|
||||
logger.warn("Logging thread is unable to keep up! Processing for last message batch took ${time}ms, which is longer than the configured logThreadingPollDelay of ${EngineConfiguration.logThreadingPollDelay}ms")
|
||||
waitTime = 0u
|
||||
} else
|
||||
waitTime = EngineConfiguration.logThreadingPollDelay.minus(time)
|
||||
else
|
||||
waitTime = 0u
|
||||
|
||||
if (waitTime > 0u)
|
||||
Thread.sleep(waitTime.toLong())
|
||||
Thread.sleep(EngineConfiguration.logThreadingPollDelay.minus(time).toLong())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,8 +115,8 @@ class NativeThreadingHandler : ThreadingHandler {
|
|||
this@NativeThreadingHandler.queue.clear()
|
||||
}
|
||||
|
||||
for (call: Call in queue)
|
||||
Processor.process(call)
|
||||
for (call: Call in queue)
|
||||
Processor.process(call)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,11 +149,9 @@ class Logger {
|
|||
if (level == Level.CRASH)
|
||||
CrashHandler.handle(call, levelData["throwable"] as Throwable?, levelData.getOrDefault("fatal", true) as Boolean)
|
||||
else {
|
||||
if (Processor.check(call))
|
||||
return
|
||||
|
||||
if (EngineConfiguration.logThreadingHandler?.queue(call) == null)
|
||||
Processor.process(call)
|
||||
if (!Processor.check(call))
|
||||
if (EngineConfiguration.logThreadingHandler?.queue(call) == null)
|
||||
Processor.process(call)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,9 +161,7 @@ class Logger {
|
|||
* @param message message
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun diag(message: String) {
|
||||
log(Level.DIAGNOSTIC, message, callerDepth = 1u)
|
||||
}
|
||||
fun diag(message: String) = log(Level.DIAGNOSTIC, message, callerDepth = 1u)
|
||||
|
||||
/**
|
||||
* Logs a verbose message.
|
||||
|
@ -173,9 +169,7 @@ class Logger {
|
|||
* @param message message
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun verb(message: String) {
|
||||
log(Level.VERBOSE, message, callerDepth = 1u)
|
||||
}
|
||||
fun verb(message: String) = log(Level.VERBOSE, message, callerDepth = 1u)
|
||||
|
||||
/**
|
||||
* Logs a silent warning.
|
||||
|
@ -183,9 +177,7 @@ class Logger {
|
|||
* @param message message
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun sarn(message: String) {
|
||||
log(Level.SILENT_WARNING, message, callerDepth = 1u)
|
||||
}
|
||||
fun sarn(message: String) = log(Level.SILENT_WARNING, message, callerDepth = 1u)
|
||||
|
||||
/**
|
||||
* Logs an informational message.
|
||||
|
@ -193,9 +185,7 @@ class Logger {
|
|||
* @param message message
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun info(message: String) {
|
||||
log(Level.INFORMATIONAL, message, callerDepth = 1u)
|
||||
}
|
||||
fun info(message: String) = log(Level.INFORMATIONAL, message, callerDepth = 1u)
|
||||
|
||||
/**
|
||||
* Logs a silent warning.
|
||||
|
@ -203,9 +193,7 @@ class Logger {
|
|||
* @param message message
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun warn(message: String) {
|
||||
log(Level.WARNING, message, callerDepth = 1u)
|
||||
}
|
||||
fun warn(message: String) = log(Level.WARNING, message, callerDepth = 1u)
|
||||
|
||||
/**
|
||||
* Logs a non-fatal error.
|
||||
|
@ -213,9 +201,7 @@ class Logger {
|
|||
* @param message message
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun error(message: String) {
|
||||
log(Level.ERROR, message, callerDepth = 1u)
|
||||
}
|
||||
fun error(message: String) = log(Level.ERROR, message, callerDepth = 1u)
|
||||
|
||||
/**
|
||||
* Logs a fatal error.
|
||||
|
@ -225,12 +211,11 @@ class Logger {
|
|||
* @param fatal terminates the engine and application if `true`
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
fun crash(error: String, throwable: Throwable? = null, fatal: Boolean = true) {
|
||||
fun crash(error: String, throwable: Throwable? = null, fatal: Boolean = true) =
|
||||
log(Level.CRASH, error, levelData = mapOf(
|
||||
Pair("throwable", throwable as Object?),
|
||||
Pair("fatal", fatal as Object?)
|
||||
), callerDepth = 1u)
|
||||
}
|
||||
|
||||
|
||||
// -----> Utility
|
||||
|
|
Loading…
Reference in a new issue