user1630693
user1630693

Reputation: 201

Logging in multiple files with play framework

I have java application which is running on play framework 1.2.5.

I want to do logging in such a way that every module will have its own log file and respective module logging will go in its own file.

Is that possible using play logging? or is there any other way to do it? Any help will be greatly appreciated.

Upvotes: 0

Views: 1843

Answers (1)

Wayan Wiprayoga
Wayan Wiprayoga

Reputation: 4562

Yes of course, it's possible. You can use advanced logger setting using apache log4j. By default, Play!Framework use apache log4j for logging purpose, see this documentation.

You must enabled this advanced setting on application.conf file using the entry like :

# More logging configuration - config file located at the same level on this file
application.log.path=/log4j.properties
application.log.system.out=off

Suppose you have two modules that located on com.mymodule and com.othermodule package. so if you want to make these modules logging on different file, your log4j.properties file should be like this :

# Define logging file appender for mymodule package
log4j.appender.mymodule=org.apache.log4j.FileAppender 
log4j.appender.mymodule.File=mymodule.log
log4j.appender.mymodule.layout=org.apache.log4j.PatternLayout

# Define logging file appender for othermodule package
log4j.appender.othermodule=org.apache.log4j.FileAppender
log4j.appender.othermodule.File=othermodule.log 
log4j.appender.othermodule.layout=org.apache.log4j.PatternLayout

log4j.logger.com.mymodule=INFO, package1
log4j.logger.com.othermodule=INFO, package2

For more reference, try to learn from following links:

Upvotes: 2

Related Questions