Skip to main content

I’m trying to create a custom log format in the Service Framework - specifically, include a GUID in each log line.

I *think* I can do that using a formatter (java.util.logging.Formatter), but can't figure out how that would work. Are there any examples around I could steal?

Thanks!

Hi Marc,

Sorry for not getting back sooner, are you referring to just adding a unique id for each log message, or do you need GUIDs coming from a database to appear in the logging?

If its the former, I think you can configure additional formatting via the log4j2.xml, specifically looking at UService.log: 

<RollingFile name="UService_Appender" fileName="./logs/UService.log" filePattern="./logs/UService.log.%i.log">
            <PatternLayout pattern="%d{ISO8601} %-5p %t %C %x - %m%n"/>

In this example on SO :

https://stackoverflow.com/questions/43999342/how-to-add-uuid-to-log4j-for-logging-into-file

they are using  UUID:%u{RANDOM}

If you add that to the PatternLayout , you should get unique id's for every log message in the UService.log.

		<RollingFile name="UService_Appender" fileName="./logs/UService.log" filePattern="./logs/UService.log.%i.log">
<PatternLayout pattern="UUID:%u{RANDOM} %d{ISO8601} %-5p %t %C %x - %m%n"/>

 


Exactly what I was looking for, Dara, thanks! Somehow an hour of searching never got me to this answer...


ahha glad it helps Marc !!! 😄 


Reply