To capture the GenRocket Runtime activity, GenRocket Runtime provides the ability to log the details by configuring the logger properties file.


There are 2 ways by which you can configure logging. One way is that you can pass the Log configuration file to each of the genrocket commands that you execute and another is to configure at the global level for all the GenRocket Runtime commands.


In order to configure the generation of the Log file at the Global Level, the following steps are required to be performed.


  1. Navigate to the .genrocket directory on your local system/server where GenRocket Runtime is installed. By default, the .genrocket directory is located in the User's HOME. But the path to the .genrocket folder is configurable therefore look for Environment variable or System Property if they are set to find out path to .genrocket folder.
  2. Once you are in the .genrocket folder, look for the genrocket.properties file. The genrocket.properties file gets created automatically by GenRocket runtime, therefore you do not need to create that manually. Open the genrocket.properties file in edit mode. 
  3. Add a property LOG_FILE_PATH in the genrocket.properties file. This property represents the path to where the log configuration is saved.
    • e.g. LOG_FILE_PATH=<FILE_PATH>/log4j.properties


In case you need to override or pass the Log configuration for each command, you can use GenRocket's -glog option


genrocket -r <Scenario.grs> -glog <pathToLog4JPropertiesFile>


e.g. genrocket -r TestScenario.grs -glog /home/jane/log4j.properties


GenRocket Runtime is using Java's log4j utility. Please check here: https://howtodoinjava.com/log4j2/log4j2-properties-example/


Examples


For GenRocket runtime version 3.5.30 and above:


Sample log4j2.properties file to create a new log file on each run and filename with current Timestamp:


appenders = console, rolling

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %m%n

appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{ABSOLUTE} %5p %c - %m%n
appender.rolling.fileName = /home/jd/Desktop/App-${date:yyyy-MM-dd-HH-mm-ss}.log
appender.rolling.filePattern = /home/jd/Desktop/App-%d{yyyy-MM-dd}.log
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy


loggers = rolling

logger.rolling.name = org.apache.logging.log4j.core.appender.RollingFileAppender
logger.rolling.level = debug

rootLogger.level = debug
rootLogger.appenderRefs = stdout, rolling

rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRef.rolling.ref = RollingFile


Sample log4j2.properties file for DailyRollingFileAppender:


appenders = console, rolling

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %m%n

appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{ABSOLUTE} %5p %c - %m%n
appender.rolling.fileName = /home/jd/Desktop/App.log
appender.rolling.filePattern = /home/jd/Desktop/App-%d{yyyy-MM-dd}.log
appender.rolling.append = true
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy


loggers = rolling

logger.rolling.name = org.apache.logging.log4j.core.appender.RollingFileAppender
logger.rolling.level = debug

rootLogger.level = debug
rootLogger.appenderRefs = stdout, rolling

rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRef.rolling.ref = RollingFile


For GenRocket runtime version 3.5.29 and below:


Sample log4j.properties file to create a new log file on each run and filename with current Timestamp.:


# Define the console appender
log4j.rootLogger=DEBUG, RollingAppender, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.conversionPattern=%m%n 

# Define the file appender
log4j.appender.RollingAppender=com.genRocket.NewLogForEachRunFileAppender
log4j.appender.RollingAppender.File=/home/jane/Desktop/logs/App.log
log4j.appender.RollingAppender.DatePattern=yyyy-MM-dd-HH-mm-ss
log4j.appender.RollingAppender.append=false

# Define the layout for the file appender
log4j.appender.RollingAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingAppender.layout.ConversionPattern=%d{ABSOLUTE} %5p %c - %m%n


Sample log4j.properties file for DailyRollingFileAppender:


# Define the console appender

log4j.rootLogger=DEBUG, RollingAppender, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.conversionPattern=%m%n

# Define the file appender using DailyRollingFileAppender
log4j.appender.RollingAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingAppender.File=/home/jane/Desktop/logs/App.log
log4j.appender.RollingAppender.DatePattern=yyyy-MM-dd-HH-mm-ss

# Define the layout for file appender
log4j.appender.RollingAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingAppender.layout.ConversionPattern=%d{ABSOLUTE} %5p %c - %m%n