Fixed that MessageLogCollector must get created for each JobContext to be able to correlate each message to its context

This commit is contained in:
dankito 2024-08-20 12:43:18 +02:00
parent 524153cb31
commit 0361a0e6b8
3 changed files with 9 additions and 8 deletions

View File

@ -2,7 +2,6 @@ package net.dankito.banking.fints.config
import net.dankito.banking.fints.FinTsJobExecutor
import net.dankito.banking.fints.RequestExecutor
import net.dankito.banking.fints.log.MessageLogCollector
import net.dankito.banking.fints.messages.MessageBuilder
import net.dankito.banking.fints.model.mapper.ModelMapper
import net.dankito.banking.fints.util.FinTsServerAddressFinder
@ -21,6 +20,5 @@ class FinTsClientConfiguration(
modelMapper: ModelMapper = ModelMapper(messageBuilder),
tanMethodSelector: TanMethodSelector = TanMethodSelector(),
var jobExecutor: FinTsJobExecutor = FinTsJobExecutor(requestExecutor, messageBuilder, modelMapper, tanMethodSelector),
var finTsServerAddressFinder: FinTsServerAddressFinder = FinTsServerAddressFinder(),
var messageLogCollector: MessageLogCollector = MessageLogCollector()
var finTsServerAddressFinder: FinTsServerAddressFinder = FinTsServerAddressFinder()
)

View File

@ -23,7 +23,8 @@ open class JobContext(
/**
* Only set if the current context is for a specific account (like get account's transactions).
*/
open val account: AccountData? = null
open val account: AccountData? = null,
protected open val messageLogCollector: MessageLogCollector = MessageLogCollector()
) : MessageBaseData(bank, config.options.product), IMessageLogAppender {
companion object {
@ -38,7 +39,7 @@ open class JobContext(
open val responseParser: ResponseParser = ResponseParser(logAppender = this)
open val messageLogWithoutSensitiveData: List<MessageLogEntry>
get() = config.messageLogCollector.messageLogWithoutSensitiveData
get() = messageLogCollector.messageLogWithoutSensitiveData
open var dialog: DialogContext = DialogContext() // create null value so that variable is not null
@ -72,11 +73,11 @@ open class JobContext(
open fun addMessageLog(type: MessageLogEntryType, message: String) {
config.messageLogCollector.addMessageLog(type, message, createMessageContext())
messageLogCollector.addMessageLog(type, message, createMessageContext())
}
override fun logError(loggingClass: KClass<*>, message: String, e: Exception?) {
config.messageLogCollector.logError(loggingClass, message, createMessageContext(), e)
messageLogCollector.logError(loggingClass, message, createMessageContext(), e)
}
protected open fun createMessageContext(): MessageContext {

View File

@ -7,8 +7,10 @@ import net.dankito.banking.fints.log.MessageContext
open class MessageLogEntry(
open val type: MessageLogEntryType,
open val message: String,
open val context: MessageContext,
open val messageTrace: String,
open val message: String,
open val error: Throwable? = null,
open val time: Instant = Clock.System.now()
) {