"SmartFoxServer2X & Log4j"

Log4j Usage and Implementation in SmartFoxServer2X

While doing any massive programing we need the logs for the transactions and activities to audit and be responsible for the happened activities.

SmartfoxServer2x comes with log4j integration, there is folder named logs in SFS2X where all the SmartfoxServer2x logs will rotate.

Here the thing to know is "what to do if we want record our server(program) logs, does we need to configure another logger or need to use this".

  • No need to install or configure other logger for our application server(program).
  • We can configure the log4j that comes with SmartfoxServer2x as our needs.
  • Open the log4j.properties from the config folder. (SFS2X->config->log4j.properties).
  • Write logging instructions similar to log4j, save it and restart the server to take effect.

> Example:-

Configure the log4j of SFS2X as logs of package, "com.tutorialtous.smartfox" need to place in a folder named "MyLogs".

  1. Open the log4j.properties file existed in config folder of SmartFoxServer2X in any text editor
  2. Place the following code snippet in log4j.properties file (at the end)
  3. Detailed snippet need to place in log4j.properties file
01 #MyCustomLogs File Appender
02 log4j.appender.MFA=org.apache.log4j.RollingFileAppender
03 log4j.appender.MFA.layout=org.apache.log4j.PatternLayout
04 log4j.appender.MFA.MaxFileSize=10MB
05 log4j.appender.MFA.MaxBackupIndex=50
06 log4j.appender.MFA.File=logs/MyLogs/transactions.log
07 log4j.appender.MFA.layout.ConversionPattern=%d{dd MMM yyyy | HH:mm:ss,SSS} | %-5p | %t |  %F:%L| %m%n
08 log4j.appender.MFA.Encoding=UTF-8
09 log4j.appender.MFA.DatePattern='.'yyyy-MM-dd
10 log4j.appender.MFA.Append=true
12 log4j.category.com.tutorialtous.smartfox=DEBUG,MFA

The above configuration will creates a folder named "MyLogs"(SFS2X->logs->MyLogs->transaction.log) in logs and records the logs in transactions.log file when the entries came from the classes of package "com.tutorialtous.smartfox".

> Note :-

  • 1. If the drive doesn’t have write permissions for the user then the logger will not work, so please install the SFS2X where the user have the write permission.
  • 2. For details about log4j configurations please refer this manual link of official log4j site