0

I have a logback.xml with the below contents

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="10000">          
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="com.myFilter.filters.CustomJsonLayout">
            <jsonFormatter class="ch.qos.logback.contrib.jackson.JacksonJsonFormatter">
                <prettyPrint>false</prettyPrint>
            </jsonFormatter>
            <appendLineSeparator>true</appendLineSeparator>
        </layout>
    </appender>


    <logger name="com.third.party" level="INFO" additivity="false">
        <appender-ref ref="CONSOLE"/>
    </logger>
    <logger name="com.cassandra" level="INFO" additivity="false">
        <appender-ref ref="CONSOLE"/>
    </logger>
    <logger name="com.sql" level="INFO" additivity="false">
        <appender-ref ref="CONSOLE"=/>
    </logger>
    <logger name="SESSION_ATTRIBUTE_LOG" level="INFO" additivity="false">
        <appender-ref ref="CONSOLE"/>
    </logger>
    <logger name="OPS_LOG" additivity="false" level="INFO">
        <appender-ref ref="CONSOLE"/>
    </logger>

<jmxConfigurator contextName="MyConfig"/>
</configuration>

Here the CustomJsonLayout class is created for our specific purpose of logging, and its working fine.

The issue is all the logs are logging to the console and I am not able to differentiate, which log is logging it like whether its thridparty or sql or myapp. Is there any way to overcome this issue ?

my log output looks like

{
  "timestamp": "1554710406746",
  "level": "INFO",
  "thread": "http-nio-8082-exec-12",
  "domain": "docker.for.mac.localhost",
  "user_agent": "Styx/1.0-1032",
  "akamai_bot": "",
  "request_method": "GET",
  "url": "/version.txt",
  "remote_host": "127.0.0.1",
  "edgescape": "",
  "logger": "com.filter.guid.GuidFilter",
  "message": "New GUID=ab3f9b75-27b8-4f13-b8e7-e1320c0d0c85 generated for requestUri=/version.txt",
  "context": "default"
}
robin
  • 1,893
  • 1
  • 18
  • 38
  • Hope this will be helpful: https://stackoverflow.com/a/10734257/2987755 – dkb Apr 09 '19 at 06:32
  • Can you give example of what your output message looks like – Cray Apr 09 '19 at 06:38
  • @dkb I have already seen that, its of no use, for me what I want is to log in the logout put a name of which log, like logName: Thridpart or sql like that – robin Apr 09 '19 at 06:55
  • @Cray not sure how output message will help, but added it. – robin Apr 09 '19 at 06:55
  • So as I understand the `"logger": "com.filter.guid.GuidFilter"` field is not enough and you need `"name": "com.third.party"` field in addition to it? – Cray Apr 09 '19 at 07:03
  • @Cray yes or any custom value which I can pass in appender-ref – robin Apr 09 '19 at 07:06
  • I don't think you can pass those on to the layout. You would have to create different appenders for each logger. – Cray Apr 09 '19 at 07:14

0 Answers0