1

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+?

Tim Perry
  • 3,066
  • 1
  • 24
  • 40

1 Answers1

1

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.

Martin
  • 598
  • 1
  • 4
  • 27
  • I'll have to reread the documentation. If the system property option isn't there, I'll try to put in a pull request to add it. Perhaps it is there and I assumed it only applied to properties set on the JVM with a -D flag. – Tim Perry Jan 05 '22 at 01:35
  • Which application or web server are you using? Do you want to set the system properties in the global server configuration or in the web.xml for each WAR? – Martin Jan 05 '22 at 09:08
  • We are using Tomcat and generally set the log configuration location with a -D flag on the server, but would put the log file name in web.xml as a property. – Tim Perry Jan 05 '22 at 19:35