Tim Perry
Tim Perry

Reputation: 3096

Shared tinylog configuration with separate files for each application

Can tinylog use the same configuration file for multiple applications (war's), but write the log based on the display-name in the web.xml?

Right now, all our web applications use log4j and share a configuration file. The log files are written with the following variable in the file name:

<RollingFile fileName="${web:servletContextName:-unknownContext}-${env:COMPUTERNAME:-unknownComputer}.%d{yyyy-MM-dd}.log" >
</RollingFile>

This means when our application has a display name of svc1234_FancyService and runs on SERVER001 then the log is named:

svc1234_FancyServce-SERVER001.2022-01-04.log

Can this behaviour be replicated with tinylog 2.4+?

Upvotes: 1

Views: 157

Answers (1)

Martin
Martin

Reputation: 716

Same Configuration File

You can place the tinylog configuration file anywhere on your file system and set the path via the system property tinylog.configuration. tinylog will automatically use the log file that is set in this system property. The system property tinylog.configuration can be set in your web.xml files or globally via your application or web server configuration. For example, the global configuration file for JBoss EAP and Wildfly is standalone.xml.

Log File Path

tinylog supports environment variables and date patterns by default. For the servlet context name, you will need a custom system property.

Example:

writer      = rolling file
writer.file = #{servlet.context.name:unknownContext}-${COMPUTERNAME:unknownComputer}.{date:yyyy-MM-dd}.log

Then, you can set the system property servlet.context.name in the web.xml files for example.

Upvotes: 1

Related Questions