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) }
|
.uncaughtExceptionHandler { thread, throwable -> logger.crash("Logging thread terminated unexpectedly", throwable) }
|
||||||
.start {
|
.start {
|
||||||
var time: ULong
|
var time: ULong
|
||||||
var waitTime: ULong
|
|
||||||
while (active) {
|
while (active) {
|
||||||
time = measureTimeMillis { flush() }.toULong()
|
time = measureTimeMillis { flush() }.toULong()
|
||||||
|
|
||||||
if (EngineConfiguration.logThreadingPollDelay > 0u)
|
if (EngineConfiguration.logThreadingPollDelay > 0u)
|
||||||
if (time > EngineConfiguration.logThreadingPollDelay) {
|
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")
|
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
|
} else
|
||||||
waitTime = EngineConfiguration.logThreadingPollDelay.minus(time)
|
Thread.sleep(EngineConfiguration.logThreadingPollDelay.minus(time).toLong())
|
||||||
else
|
|
||||||
waitTime = 0u
|
|
||||||
|
|
||||||
if (waitTime > 0u)
|
|
||||||
Thread.sleep(waitTime.toLong())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,8 +115,8 @@ class NativeThreadingHandler : ThreadingHandler {
|
||||||
this@NativeThreadingHandler.queue.clear()
|
this@NativeThreadingHandler.queue.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (call: Call in queue)
|
for (call: Call in queue)
|
||||||
Processor.process(call)
|
Processor.process(call)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,11 +149,9 @@ class Logger {
|
||||||
if (level == Level.CRASH)
|
if (level == Level.CRASH)
|
||||||
CrashHandler.handle(call, levelData["throwable"] as Throwable?, levelData.getOrDefault("fatal", true) as Boolean)
|
CrashHandler.handle(call, levelData["throwable"] as Throwable?, levelData.getOrDefault("fatal", true) as Boolean)
|
||||||
else {
|
else {
|
||||||
if (Processor.check(call))
|
if (!Processor.check(call))
|
||||||
return
|
if (EngineConfiguration.logThreadingHandler?.queue(call) == null)
|
||||||
|
Processor.process(call)
|
||||||
if (EngineConfiguration.logThreadingHandler?.queue(call) == null)
|
|
||||||
Processor.process(call)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,9 +161,7 @@ class Logger {
|
||||||
* @param message message
|
* @param message message
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun diag(message: String) {
|
fun diag(message: String) = log(Level.DIAGNOSTIC, message, callerDepth = 1u)
|
||||||
log(Level.DIAGNOSTIC, message, callerDepth = 1u)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a verbose message.
|
* Logs a verbose message.
|
||||||
|
@ -173,9 +169,7 @@ class Logger {
|
||||||
* @param message message
|
* @param message message
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun verb(message: String) {
|
fun verb(message: String) = log(Level.VERBOSE, message, callerDepth = 1u)
|
||||||
log(Level.VERBOSE, message, callerDepth = 1u)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a silent warning.
|
* Logs a silent warning.
|
||||||
|
@ -183,9 +177,7 @@ class Logger {
|
||||||
* @param message message
|
* @param message message
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun sarn(message: String) {
|
fun sarn(message: String) = log(Level.SILENT_WARNING, message, callerDepth = 1u)
|
||||||
log(Level.SILENT_WARNING, message, callerDepth = 1u)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs an informational message.
|
* Logs an informational message.
|
||||||
|
@ -193,9 +185,7 @@ class Logger {
|
||||||
* @param message message
|
* @param message message
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun info(message: String) {
|
fun info(message: String) = log(Level.INFORMATIONAL, message, callerDepth = 1u)
|
||||||
log(Level.INFORMATIONAL, message, callerDepth = 1u)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a silent warning.
|
* Logs a silent warning.
|
||||||
|
@ -203,9 +193,7 @@ class Logger {
|
||||||
* @param message message
|
* @param message message
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun warn(message: String) {
|
fun warn(message: String) = log(Level.WARNING, message, callerDepth = 1u)
|
||||||
log(Level.WARNING, message, callerDepth = 1u)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a non-fatal error.
|
* Logs a non-fatal error.
|
||||||
|
@ -213,9 +201,7 @@ class Logger {
|
||||||
* @param message message
|
* @param message message
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
fun error(message: String) {
|
fun error(message: String) = log(Level.ERROR, message, callerDepth = 1u)
|
||||||
log(Level.ERROR, message, callerDepth = 1u)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs a fatal error.
|
* Logs a fatal error.
|
||||||
|
@ -225,12 +211,11 @@ class Logger {
|
||||||
* @param fatal terminates the engine and application if `true`
|
* @param fatal terminates the engine and application if `true`
|
||||||
* @since v1-alpha10
|
* @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(
|
log(Level.CRASH, error, levelData = mapOf(
|
||||||
Pair("throwable", throwable as Object?),
|
Pair("throwable", throwable as Object?),
|
||||||
Pair("fatal", fatal as Object?)
|
Pair("fatal", fatal as Object?)
|
||||||
), callerDepth = 1u)
|
), callerDepth = 1u)
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// -----> Utility
|
// -----> Utility
|
||||||
|
|
Loading…
Reference in a new issue