[ https://issues.apache.org/jira/browse/LOG4J2-1010?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15346041#comment-15346041 ]
Mikael Ståldal commented on LOG4J2-1010: ---------------------------------------- I am actually using [Local|https://twitter.github.io/util/docs/#com.twitter.util.Local], which is the low level mechanism (similar to Java's ThreadLocal) used by Finagle to implement Contexts. I currently have a custom Scala API wrapper which does this in a clumsy way. But this only works for Finagle. With other asynchronous frameworks (such as Play Framework) you would have to do it differently. A pluggable way to inject context properties to the LogEvent is exactly what I want. My intention with adding arguments to logging calls was not that the application would used it directly, it was that some API wrapper (such as the Scala API) can use it for injection. But if we can come up with some other way of doing the injection, then that's fine. However, I am not satisfied with the two other proposals that came up earlier in this discussion. Custom messages is not good since I want to leverage existing Layouts which already uses context properties. Configuration properties is not good since I don't what to have to specify all possible context property keys in my configuration file. My idea of injection mechanism is to add a parameter to {{ExtendedLogger.logMessage}}: {code} /** * Always logs a message at the specified level. It is the responsibility of the caller to ensure the specified * level is enabled. * * @param fqcn The fully qualified class name of the logger entry point, used to determine the caller class and * method when location information needs to be logged. * @param level The logging Level to check. * @param marker A Marker or null. * @param message The Message. * @param t the exception to log, including its stack trace. * @param contextMap contextMap to include in the log event, or null. */ void logMessage(String fqcn, Level level, Marker marker, Message message, Throwable t, Map<String, String> contextMap); {code} I am open for other ideas. > Possibility to set ThreadContext values in calls to Logger method > ----------------------------------------------------------------- > > Key: LOG4J2-1010 > URL: https://issues.apache.org/jira/browse/LOG4J2-1010 > Project: Log4j 2 > Issue Type: Improvement > Components: API > Affects Versions: 2.2 > Reporter: Mikael Ståldal > Attachments: properties.patch > > > It would be useful to have some logging methods in the Logger interface to > set ThreadContext values for a single log message only. > In an asynchronous environment, using ThreadContext as currently defined is > not so useful since JVM threads might not be coupled to the logical flow of > the application. -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-dev-h...@logging.apache.org