• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Spring Boot session logging

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm after some best practice / advice.

I have a Spring Boot servlet web service which is called with some HTTP header information.  I need to output this header information in any trace files which are produced by the application.  Tracing is done my log4j2, and I'm after advice as to how to ensure that this header information is available to all classes within the application so it can be included in the logs.

I thought about placing the information into session, and then make this httpSession object available thoughout the application but this seems like overkill.  Are there any other recommended ways to do this?

Cheers
 
Sheriff
Posts: 21774
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you only need to include it in your logs, you should probably put it in your thread context (MDC in Log4J 1, SLF4J and Logback), then change your log pattern layout to include these values.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!