1

is there a way to log a property from MDC as Integer? I have this pattern in my logback.xml,

<pattern>
    {
    "level": "%level",
    "maz": {
    "tenant": "%mdc{tenant}",
    "login": "%mdc{login}",
    "process": "backend"
    },
    "http": {
    "host": "%mdc{host}",
    "provider": "%mdc{provider}",
    "method": "%mdc{method}",
    "request": "%mdc{request}",
    "query": "%mdc{query}",
    "size_o": "%mdc{size}",
    "status": "%mdc{status}",
    "duration_ms": "%mdc{duration}"
    },
    "message": "%message"
    }
</pattern>

and I want to print the duration as Integer not string, if not, is there a way to read a java variable in logback.xml? or is there any suggestion to log this variable as integer?

1 Answers1

1

mdc can use defualt value with symbol :- .default value support expression like %mdc{duration:-${defaultCostTime}}

<property name="defaultCostTime" value="1"/>

<pattern>
    {
    "level": "%level",
    "maz": {
    "tenant": "%mdc{tenant}",
    "login": "%mdc{login}",
    "process": "backend"
    },
    "http": {
    "host": "%mdc{host}",
    "provider": "%mdc{provider}",
    "method": "%mdc{method}",
    "request": "%mdc{request}",
    "query": "%mdc{query}",
    "size_o": "%mdc{size}",
    "status": "%mdc{status}",
    "duration_ms": %mdc{duration:-${defaultCostTime}}
    },
    "message": "%message"
    }
</pattern>
BlackC
  • 331
  • 3
  • 8