Overhaul crash category compilation, improve engine crash category
This commit is contained in:
parent
f1a366d431
commit
bd0879e1cc
2 changed files with 91 additions and 25 deletions
|
@ -19,7 +19,11 @@
|
||||||
|
|
||||||
package de.staropensource.engine.base.implementation.logging.crashcategory
|
package de.staropensource.engine.base.implementation.logging.crashcategory
|
||||||
|
|
||||||
|
import de.staropensource.engine.base.Engine
|
||||||
|
import de.staropensource.engine.base.implementable.Subsystem
|
||||||
import de.staropensource.engine.base.implementable.logging.CrashCategory
|
import de.staropensource.engine.base.implementable.logging.CrashCategory
|
||||||
|
import de.staropensource.engine.base.type.logging.Call
|
||||||
|
import de.staropensource.engine.base.type.logging.ChannelSettings
|
||||||
import de.staropensource.engine.base.utility.dnihbd.BuildInformation
|
import de.staropensource.engine.base.utility.dnihbd.BuildInformation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,4 +56,24 @@ class EngineCrashCategory private constructor() : BuildInformation.BuildInformat
|
||||||
override fun getName(): String {
|
override fun getName(): String {
|
||||||
return "sos!engine"
|
return "sos!engine"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun execute(
|
||||||
|
call: Call,
|
||||||
|
channelSettings: ChannelSettings?,
|
||||||
|
throwable: Throwable?,
|
||||||
|
fatal: Boolean
|
||||||
|
): LinkedHashMap<String, Any?> {
|
||||||
|
val subsystemsList: LinkedHashSet<String> = linkedSetOf()
|
||||||
|
|
||||||
|
// Populate 'subsystemsList'
|
||||||
|
for (subsystem: Subsystem in Engine.getSubsystems())
|
||||||
|
subsystemsList.add("${subsystem::class.qualifiedName ?: "<anonymous>"} [${subsystem.getName()}]")
|
||||||
|
|
||||||
|
// Return
|
||||||
|
return linkedMapOf(
|
||||||
|
Pair("State", Engine.state.name),
|
||||||
|
Pair("Subsystems", subsystemsList),
|
||||||
|
Pair("Build Information", super.execute(call, channelSettings, throwable, fatal))
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,10 @@ package de.staropensource.engine.base.logging
|
||||||
|
|
||||||
import de.staropensource.engine.base.Engine
|
import de.staropensource.engine.base.Engine
|
||||||
import de.staropensource.engine.base.EngineConfiguration
|
import de.staropensource.engine.base.EngineConfiguration
|
||||||
|
import de.staropensource.engine.base.extension.toStringType
|
||||||
|
import de.staropensource.engine.base.implementable.formatter.Formatter
|
||||||
import de.staropensource.engine.base.implementable.logging.Adapter
|
import de.staropensource.engine.base.implementable.logging.Adapter
|
||||||
import de.staropensource.engine.base.implementable.logging.CrashCategory
|
import de.staropensource.engine.base.implementable.logging.CrashCategory
|
||||||
import de.staropensource.engine.base.implementable.formatter.Formatter
|
|
||||||
import de.staropensource.engine.base.type.logging.Call
|
import de.staropensource.engine.base.type.logging.Call
|
||||||
import de.staropensource.engine.base.type.logging.ChannelSettings
|
import de.staropensource.engine.base.type.logging.ChannelSettings
|
||||||
|
|
||||||
|
@ -40,6 +41,14 @@ class CrashHandler private constructor() {
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
companion object {
|
companion object {
|
||||||
|
/**
|
||||||
|
* Dictates how much the
|
||||||
|
* indent increases per level.
|
||||||
|
*
|
||||||
|
* @since v1-alpha10
|
||||||
|
*/
|
||||||
|
const val INDENT_INCREASE: Int = 3
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles crashes.
|
* Handles crashes.
|
||||||
*
|
*
|
||||||
|
@ -94,44 +103,77 @@ class CrashHandler private constructor() {
|
||||||
/**
|
/**
|
||||||
* Compiles a [CrashCategory].
|
* Compiles a [CrashCategory].
|
||||||
*
|
*
|
||||||
* @param category [CrashCategory] to compile
|
* @param map map to compile
|
||||||
|
* @param indent indentation level
|
||||||
* @return compiled output
|
* @return compiled output
|
||||||
* @since v1-alpha10
|
* @since v1-alpha10
|
||||||
*/
|
*/
|
||||||
private fun compileCategory(map: LinkedHashMap<*, *>, indent: Int = 1): String = buildString {
|
private fun compileCategory(map: LinkedHashMap<*, *>, indent: Int = 1): String = buildString {
|
||||||
var entryString: String? = null
|
|
||||||
|
|
||||||
// Iterate over all entries
|
// Iterate over all entries
|
||||||
for (entry in map.keys) {
|
for (entry: Any in map.keys) {
|
||||||
// Check if key is a string
|
// Check if key is a string
|
||||||
if (entry !is String)
|
if (entry !is String)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
append("\n${" ".repeat(indent)}-> ${entry}")
|
append("\n${" ".repeat(indent)}-> ${entry}")
|
||||||
|
|
||||||
if (map[entry] == null) // Value is null
|
val value: String? = compileValue(map[entry], true, indent)
|
||||||
true
|
if (value != null)
|
||||||
else if (map[entry] is LinkedHashMap<*, *>) // Value is a map
|
append(value)
|
||||||
append(
|
}
|
||||||
compileCategory(
|
}
|
||||||
map[entry] as LinkedHashMap<*, *>,
|
|
||||||
indent = indent + 3 // increase the 2nd addend to change the indent size during recursion
|
/**
|
||||||
|
* Handles values and anything
|
||||||
|
* other interesting returned
|
||||||
|
* by [CrashCategory]s.
|
||||||
|
*
|
||||||
|
* @param value value to handle
|
||||||
|
* @param ofKey if to prepend `: ` to certain return values
|
||||||
|
* @param indent indentation level
|
||||||
|
* @return compiled output
|
||||||
|
* @since v1-alpha10
|
||||||
|
*/
|
||||||
|
private fun compileValue(value: Any?, ofKey: Boolean, indent: Int = 1): String? = buildString {
|
||||||
|
// Value is null
|
||||||
|
if (value == null)
|
||||||
|
true
|
||||||
|
|
||||||
|
// Value is a CharSequence or Char
|
||||||
|
else if (value is CharSequence || value is Char) {
|
||||||
|
// Put on separate line if contains newline
|
||||||
|
if (value.toString().contains("\n"))
|
||||||
|
append("\n${value}"
|
||||||
|
.replace(
|
||||||
|
"\n",
|
||||||
|
"\n ${" ".repeat(indent)}"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else {
|
else
|
||||||
entryString = map[entry].toString()
|
append("${if (ofKey) ": " else ""}${value}")
|
||||||
|
|
||||||
// Put on separate line if contains newline
|
// Value is a map
|
||||||
if (entryString.contains("\n"))
|
} else if (value is LinkedHashMap<*, *>)
|
||||||
append("\n${entryString}"
|
append(
|
||||||
.replace(
|
compileCategory(
|
||||||
"\n",
|
value,
|
||||||
"\n ${" ".repeat(indent)}"
|
indent = indent + INDENT_INCREASE
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else
|
|
||||||
append(": ${entryString}")
|
// Value is an Array
|
||||||
}
|
else if (value is Array<*>)
|
||||||
|
for (item: Any? in value)
|
||||||
|
append("\n${" ".repeat(indent.plus(INDENT_INCREASE))}-> ${compileValue(item, false, indent.plus(INDENT_INCREASE.times(2)))}")
|
||||||
|
|
||||||
|
// Value is an Iterable
|
||||||
|
else if (value is Iterable<*>)
|
||||||
|
for (item: Any? in value)
|
||||||
|
append("\n${" ".repeat(indent.plus(INDENT_INCREASE))}-> ${compileValue(item, false, indent.plus(INDENT_INCREASE.times(2)))}")
|
||||||
|
|
||||||
|
// Value is something this method doesn't recognize
|
||||||
|
else {
|
||||||
|
append("${if (ofKey) ": " else ""}${value.toStringType()}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue