[
https://issues.apache.org/jira/browse/LOG4J2-1015?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14545760#comment-14545760
]
Daniel Marcotte commented on LOG4J2-1015:
-----------------------------------------
For that particular problem, I have a few markers such as :
* Payload marker
* Performance marker
* SQL marker
I want to enrich my logs and have a way to route them. I don't want to filter
them out in each specific appender since it leads to duplicated and complicated
filtering rules in each Appender. I want to redirect them at the source.
{quote}
While markers are part of the SLF4J API, only logback supports markers off the
shelf. For example, if you add the %marker conversion word to its pattern,
logback's PatternLayout will add marker data to its output. Marker data can be
used to filter messages or even trigger an outgoing email at the end of an
individual transaction.
{quote}
Here's my java sample :
{code}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
public class HelloWorld2 {
public static final Marker SQL = MarkerFactory.getMarker("SQL");
public static final Marker PAYLOAD = MarkerFactory.getMarker("PAYLOAD");
public static final Marker PERFORMANCE =
MarkerFactory.getMarker("PERFORMANCE");
public static void main(String[] args) throws InterruptedException {
final Logger logger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
logger.info(SQL, "Marker worked, should be in Sql.log");
logger.info(PAYLOAD, "Marker worked, should be in Payload.log");
logger.info(PERFORMANCE, "Marker worked, should be in Performance.log");
}
}
{code}
And here's my yaml configuraiton :
{code}
Configuration:
status: debug
Appenders:
Console:
RandomAccessFile:
- name: SQL_APPENDER
fileName: logs/sql.log
PatternLayout:
Pattern: "%d{ISO8601_BASIC} %-5level %logger{1} %X %msg%n"
- name: PAYLOAD_APPENDER
fileName: logs/payload.log
PatternLayout:
Pattern: "%d{ISO8601_BASIC} %-5level %logger{1} %X %msg%n"
- name: PERFORMANCE_APPENDER
fileName: logs/performance.log
PatternLayout:
Pattern: "%d{ISO8601_BASIC} %-5level %logger{1} %X %msg%n"
Routing:
name: ROUTING_APPENDER
Routes:
pattern: "$${marker}"
Route:
- key: PERFORMANCE
ref: PERFORMANCE_APPENDER
- key: PAYLOAD
ref: PAYLOAD_APPENDER
- key: SQL
ref: SQL_APPENDER
Loggers:
Root:
level: trace
AppenderRef:
- ref: ROUTING_APPENDER
{code}
> Add a way to route messages based on the %marker in Layout for RoutingAppender
> ------------------------------------------------------------------------------
>
> Key: LOG4J2-1015
> URL: https://issues.apache.org/jira/browse/LOG4J2-1015
> Project: Log4j 2
> Issue Type: New Feature
> Components: Appenders
> Affects Versions: 2.2
> Reporter: Daniel Marcotte
>
> Hi,
> It seems there's no way to route messages based on the Marker in the
> RoutingAppender. The "%marker" is not part of the Layout. When using SLF4J,
> since it's a core feature of the facade, this would help greatly if it was
> possible to route messages based on the Marker.
> Main StackOverFlow question (still unanswered) :
> http://stackoverflow.com/questions/30111754/log4j2-is-there-a-way-to-route-logs-based-on-marker-with-the-routingappender
> Workaround StackOverFlow question (answered) :
> http://stackoverflow.com/questions/30247323/how-to-create-custom-rewritepolicy-in-log4j2
> Thank you
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]