Adding support for logger name in JaxRsDpsLogger and ILogger for fine grained configuration of log messages
Context and Scope
Below are the sample logs in storage service
2020-06-29 19:34:19.783 INFO 5644 --- [nio-8082-exec-3] o.o.o.c.common.logging.DefaultLogWriter : storage.app: Start Web-API DELETE /records/opendes:id:1593439432354 Headers: {data-partition-id:opendes,content-type:application/json} {correlation-id=68a989a1-f1a2-4bbc-9f1c-5c734a790311, data-partition-id=opendes}
2020-06-29 19:34:22.342 INFO 5644 --- [nio-8082-exec-3] o.o.o.c.common.logging.DefaultLogWriter : {auditLog={resources=[opendes:id:1593439432354], action=DELETE, actionId=ST003, message=Record purged, user=e6ac6dfe-8198-4f9c-b2e8-b974c0f9ef5b, status=SUCCESS}} {correlation-id=68a989a1-f1a2-4bbc-9f1c-5c734a790311, data-partition-id=opendes}
2020-06-29 19:34:22.344 INFO 5644 --- [nio-8082-exec-3] o.o.o.c.common.logging.DefaultLogWriter : storage.app: Storage publishes message 68a989a1-f1a2-4bbc-9f1c-5c734a790311 {correlation-id=68a989a1-f1a2-4bbc-9f1c-5c734a790311, data-partition-id=opendes}
2020-06-29 19:34:22.670 INFO 5644 --- [nio-8082-exec-3] o.o.o.c.common.logging.DefaultLogWriter : storage.app: End Web-API DELETE /records/opendes:id:1593439432354 Headers: {correlation-id:68a989a1-f1a2-4bbc-9f1c-5c734a790311} timeTaken:2887 {correlation-id=68a989a1-f1a2-4bbc-9f1c-5c734a790311, data-partition-id=opendes}
If we notice above the loggerName for all the logs is o.o.o.c.common.logging.DefaultLogWriter
. This is fully qualified name of the class in which logger instance is created by giving the class name as input.
Logging libraries like java.utils.logging, log4j2 etc., provides a way to configure log level based on logger name. As these logger names most of the times are full qualified names, this allows different configuration at package level or class level. Refer sample log4j2.xml below
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c{1} - %m%n"/>
</layout>
</appender>
<logger name="com.example.mypackage" additivity="false">
<level value="info"/>
<appender-ref ref="console"/>
</logger>
<root>
<priority value="warn"/>
<appender-ref ref="console"/>
</root>
</log4j:configuration>
From the above configuration, for package com.example.mypacage
we are logging any thing info and above where as for root we are logging warn and above.
Having loggerName will give fine grained control of log messages at different level like package or classes and different environments like dev, stage, prod.
Decision
To support loggerName overloaded methods will be added to JaxRsDpsLogger.java and ILogger.java. ILogger.java new methods will have default implementation which will call into existing methods leaving the loggerName. This is to keep backward compatiability.
Cloud providers who what to use this additional feature will implement their own class for ILogger to support new loggerName.
Rationale
This proposal will not affect the existing implementations and cloud providers can pick up these changes at their own pace if needed