Java Agent logs how to get %file %line %method

%3CLINGO-SUB%20id%3D%22lingo-sub-2944896%22%20slang%3D%22en-US%22%3EJava%20Agent%20logs%20how%20to%20get%20%25file%20%25line%20%25method%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2944896%22%20slang%3D%22en-US%22%3E%3CP%3EJava%20SpringBoot%20application%20V%3A%202.5.4%3C%2FP%3E%3CP%3EapplicationsInsightsAgent%20V%3A3.2.0%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20log%20pattern%20that%20I%20am%20using%20for%20the%20application%20looks%20something%20like%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EmdcPattern%3D%25replace(accountId%3A%25X%7BaccountId%7D%20webUserId%3A%25X%7BwebUserId%7D%20payload%3A%25X%7Bpayload%7D)%7B'(%5E%7C%20)%3F%5Ba-zA-Z%5D%2B%3A(%20%7C%24)'%2C%20''%7D%0AlogPatternConsole%3D%25d%7Byyyy-MM-dd%20HH%3Amm%3Ass%7D%20%5B%25thread%5D%20%25-5level%20%24%7BPID%7D%20---%5B%24%7BmdcPattern%7D%5D%20%5B%25logger%7B0%7D%20%25file%3A%25line-%26gt%3B%25method%5D%20%3A%20%25msg%20%25n%0Alogging.pattern.console%3D%24%7BlogPatternConsole%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewhich%20produces%20console%20outputs%20like%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E2021-11-09%2016%3A44%3A47%20%5Bhttps-jsse-nio-8080-exec-4%5D%20DEBUG%2050483%20---%5B%5D%20%5BApiController%20ApiController.java%3A1697-%26gt%3Bgreetings%5D%20%3A%20%5B***%5D%20%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20logging%20in%20the%20azure%20logging%20workspace%20picks%20up%20under%20%22properties%22%20values%20such%20as%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ELoggerName%3A%20com.mia.wa.controller.ApiController%0ALoggingLevel%3A%20DEBUG%0ASourceType%3A%20Logger%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eand%20when%20upgrading%20from%20V%3A%203.1.1%20to%203.2.0%20it%20also%20picked%20up%20ThreadName%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20problem%20is%20that%20the%20values%20specified%20in%20the%20log%20pattern%20which%20are%20dynamic%20and%20show%20per%20log%20output%20on%20the%20console%2C%20the%20file%20name%2C%20the%20line%20number%20and%20the%20name%20of%20the%20method%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CSPAN%3E%25file%3A%25line-%26gt%3B%25method%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3Eis%20not%20capture%20in%20the%20Azure%20Logs%20AppTrace%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3BIs%20there%20anyway%20to%20have%20those%20values%20sent%20back%20to%20the%20Azure%20Logs%20and%20show%20as%20properties%20(the%20same%20way%20that%20the%20ThreadName%20now%20shows%20or%20even%20the%20MDC%20values%20)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Java SpringBoot application V: 2.5.4

applicationsInsightsAgent V:3.2.0

 

The log pattern that I am using for the application looks something like:

mdcPattern=%replace(accountId:%X{accountId} webUserId:%X{webUserId} payload:%X{payload}){'(^| )?[a-zA-Z]+:( |$)', ''}
logPatternConsole=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level ${PID} ---[${mdcPattern}] [%logger{0} %file:%line->%method] : %msg %n
logging.pattern.console=${logPatternConsole}

 

which produces console outputs like

2021-11-09 16:44:47 [https-jsse-nio-8080-exec-4] DEBUG 50483 ---[] [ApiController ApiController.java:1697->greetings] : [***] 

 

The logging in the azure logging workspace picks up under "properties" values such as

LoggerName: com.mia.wa.controller.ApiController
LoggingLevel: DEBUG
SourceType: Logger

 

and when upgrading from V: 3.1.1 to 3.2.0 it also picked up ThreadName

 

 

The problem is that the values specified in the log pattern which are dynamic and show per log output on the console, the file name, the line number and the name of the method 

%file:%line->%method

is not capture in the Azure Logs AppTrace

 

 Is there anyway to have those values sent back to the Azure Logs and show as properties (the same way that the ThreadName now shows or even the MDC values )

 

Thanks 

 

 

 

 

 

0 Replies