1

Want to print API request in log with the help of RequestLogger. We have log4j properties file ,log4j dependency entry is there in pom and also POM is referring the log4j properties file too.

We have log4j properties under resources and also added dependency in POM file . And tried to dd RequestLogger requestLogger = new RequestLogger(NullPrintStream.NULL_PRINT_STREAM); TestBaseProvider.instance().get().getContext().setProperty("rest.client.requestlogger", requestLogger);

the above lines in OnStart listener method. But nothing works fine, Can anyone please guide how we can print api requests in log.

ashwini r
  • 21
  • 2

1 Answers1

1

Looking at the source code of RequestLogger, it can operate in two ways: by sending messages to Jakarta Commons Logging or to a PrintStream, depending on the constructor you use:

  • by calling new RequestLogger(NullPrintStream.NULL_PRINT_STREAM) you send everything to a PrintStream, which:

    Writes all data to the famous /dev/null. This print stream has no destination (file/socket etc.) and all bytes written to it are ignored and lost.

  • by calling new RequestLogger(), you send everything to JCL, which is a logging API with a configurable backend. If you use Log4j2 and have log4j-jcl on the classpath, JCL will choose Log4j2. If you use the (EOL-ed) Log4j 1.2 and have no other JCL binding on the classpath, JCL will choose this one.

Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43