Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging Suggestion #1424

Open
Sam-Kruglov opened this issue Apr 28, 2020 · 4 comments
Open

Logging Suggestion #1424

Sam-Kruglov opened this issue Apr 28, 2020 · 4 comments
Assignees
Labels
Priority 4: Would Lowest priority. Would-be-nice to include issues when time allows it. Type: Enhancement Use to signal an issue enhances an already existing feature of the project.

Comments

@Sam-Kruglov
Copy link

Sam-Kruglov commented Apr 28, 2020

I propose that out-of-the-box, all messages are logged like this:

  • Command payloads at DEBUG
  • User-friendly events at INFO
  • Event payloads at DEBUG
  • Query payloads at TRACE
  • Query
  • return values at TRACE

I think that would be in-line with "convention over configuration".

I think a well placed LoggingInterceptor, potentially adjusted to chance logging levels, covers this point already.

(c) @smcvb AxonFramework/extension-tracing#15

Here is how I'm doing it here:

@Bean
fun eventLogger(tracer: Tracer): MessageDispatchInterceptor<EventMessage<*>> {
    return MessageDispatchInterceptor {
        BiFunction { _, event ->
            try {
                val description = (event.payload as Describable).description()
                log.info("[${tracer.id()}]: $description")
                if (log.isDebugEnabled) {
                    log.debug("[${tracer.id()}]: ${event.payload}")
                }
            } catch (e: ClassCastException) {
                log.error("[${tracer.id()}]: ${event.name()} " +
                        "does not implement ${Describable::class.simpleName}")
                log.info("[${tracer.id()}]: ${event.payload}")
            }
            event
        }
    }
}

@Bean
fun commandLogger(tracer: Tracer): MessageDispatchInterceptor<CommandMessage<*>> {
    return MessageDispatchInterceptor {
        BiFunction { _, command ->
            if (log.isDebugEnabled) {
                log.debug("[${tracer.id()}]: ${command.payload}")
            }
            command
        }
    }
}

@Bean
fun queryLogger(tracer: Tracer): MessageDispatchInterceptor<QueryMessage<*, *>> {
    return MessageDispatchInterceptor {
        BiFunction { _, query ->
            if (log.isTraceEnabled) {
                val payload = query.payload.toString()
                log.trace("[${tracer.id()}]: $payload")
            }
            query
        }
    }
}

@Bean
fun queryLoggerReturnValue(tracer: Tracer): MessageHandlerInterceptor<QueryMessage<*, *>> {
    return MessageHandlerInterceptor { unitOfWork, chain ->
        if (!log.isTraceEnabled) {
            return@MessageHandlerInterceptor chain.proceed()
        }
        val span = tracer.activeSpan()!!
        val traceId = span.context().toTraceId()
        val logAction: (Any?) -> Unit = {
            //fixme sometimes we can't see payload in the ui, maybe span is finished earlier then the future?
            span.setTag("axon.return.message.payload", it.toString())
            log.trace("[$traceId]: ${unitOfWork.message.payloadType.simpleName} returned: $it")
        }
        val returnValue: Any? = chain.proceed()
        if (returnValue == null) {
            logAction(null)
            return@MessageHandlerInterceptor returnValue
        }
        if (returnValue is CompletableFuture<*>) {
            returnValue.thenAccept(logAction)
        } else {
            logAction(returnValue)
        }
        return@MessageHandlerInterceptor returnValue
    }
}
@smcvb smcvb added the Status: Under Discussion Use to signal that the issue in question is being discussed. label Apr 29, 2020
@smcvb
Copy link
Member

smcvb commented Aug 10, 2020

What's your feel with enhancing the LoggingInterceptor to specify these levels per type of message, making it configurable through a builder to provide more flexibility, and to configure this interceptor by default, @Sam-Kruglov?

@smcvb smcvb self-assigned this Aug 10, 2020
@smcvb smcvb added Priority 4: Would Lowest priority. Would-be-nice to include issues when time allows it. Status: Information Required Use to signal this issue is waiting for information to be provided in the issue's description. Type: Enhancement Use to signal an issue enhances an already existing feature of the project. labels Aug 10, 2020
@Sam-Kruglov
Copy link
Author

Sorry for the late response.
I see, so you want to have a single big MessageHandlerInterceptor with a bunch of instanceOf to see what type of message it is and to be able to configure the logging levels of each thing I mentioned here. I see no problem with that, we would only need to make sure to check logger.is[Debug/Trace/Info]Enabled somehow to avoid calling toString() and other expensive methods for no reason.

@smcvb smcvb added this to the Release 4.7.0 milestone Oct 3, 2022
@smcvb smcvb added Status: In Progress Use to signal this issue is actively worked on. and removed Status: Information Required Use to signal this issue is waiting for information to be provided in the issue's description. Status: Under Discussion Use to signal that the issue in question is being discussed. labels Jan 6, 2023
@smcvb smcvb modified the milestones: Release 4.7.0, Release 4.8.0 Jan 16, 2023
@smcvb
Copy link
Member

smcvb commented Jan 16, 2023

Moving issue to release 4.8.0 in favor of time we need to spent on releasing 4.7.0

@smcvb smcvb removed the Status: In Progress Use to signal this issue is actively worked on. label Jun 12, 2023
@smcvb
Copy link
Member

smcvb commented Jun 12, 2023

We do not envision having sufficient time to work on this before our intended release of 4.8.0.
Added, we aim to direct our attention to the following major release.
Due to this, it is unclear at this stage when the issue will be resolved.

@smcvb smcvb removed this from the Release 4.8.0 milestone Jun 12, 2023
@smcvb smcvb changed the title Suggestion for logging Logging Suggestion Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority 4: Would Lowest priority. Would-be-nice to include issues when time allows it. Type: Enhancement Use to signal an issue enhances an already existing feature of the project.
Projects
None yet
Development

No branches or pull requests

2 participants