Searching on getting rest-assured to output the logging to a file I followed instructions found at
http://www.google.com/url?q=http%3A%2F%2Fstackoverflow.com%2Fa%2F33388510%2F398441&sa=D&sntz=1&usg=AFQjCNFhBM53GojLIyn157GQNTXCdlfX7g. This works OK, but the format of the logs saved to the file is very different than the logs going to the console using the built-in rest-assured logging filters.
How can I get the same format logs that I see in the console into the logging file?
Example nice readable output from rest-assured to the console:
Request method: GET
Request URI: http://10.10.152.132:3030/mysite/web/widget/automation_index/1
Proxy: http://localhost:8888
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Multiparts: <none>
Headers: Accept=*/*
Cookies: JSESSIONID=ECC9D5FFFD8BFE7CF2CE537BCEB57A83;Path=/insite;HttpOnly
ROBOTSESSIONID=ECC9D5FFFD8BFE7CF2CE537BCEB57A83;Path=/;Max-Age=2160000;Expires=6/2/17 5:18 PM
Body: <none>
HTTP/1.1 422
Set-Cookie: ROBOTSESSIONID=ECC9D5FFFD8BFE7CF2CE537BCEB57A83; Max-Age=2160000; Expires=Fri, 02-Jun-2017 17:19:50 GMT; Path=/
Cache-Control: max-age=0
Expires: Mon, 08 May 2017 17:19:50 GMT
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Content-Encoding: gzip
Vary: Accept-Encoding
Date: Mon, 08 May 2017 17:19:49 GMT
{
"error": "Failed to get system from database with id 1 ."
} What shows up in the log (with my current log4j properties file):
2017-05-08 12:19:54.865 DEBUG org.apache.http.impl.conn.BasicClientConnectionManager: Get connection for route {}->http://127.0.0.1:8888->http://10.60.152.132:3030sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.impl.conn.DefaultClientConnectionOperator: Connecting to 127.0.0.1:8888sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.client.protocol.RequestAddCookies: CookieSpec selected: ignoreCookiessg
2017-05-08 12:19:54.865 DEBUG org.apache.http.client.protocol.RequestAuthCache: Auth cache not set in the contextsg
2017-05-08 12:19:54.865 DEBUG org.apache.http.client.protocol.RequestTargetAuthentication: Target auth state: UNCHALLENGEDsg
2017-05-08 12:19:54.865 DEBUG org.apache.http.client.protocol.RequestProxyAuthentication: Proxy auth state: UNCHALLENGEDsg
2017-05-08 12:19:54.865 DEBUG org.apache.http.impl.client.DefaultHttpClient: Attempt 1 to execute requestsg
2017-05-08 12:19:54.865 DEBUG org.apache.http.impl.conn.DefaultClientConnection: Sending request: GET http://10.10.152.132:3030/insite/web/widget/automation_index/1 HTTP/1.1sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.wire: >> "GET http://10.10.152.132:3030/mysite/web/widget/automation_index/1 HTTP/1.1[\r][\n]"sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.wire: >> "Cookie: JSESSIONID=ECC9D5FFFD8BFE7CF2CE537BCEB57A83; ROBOTSESSIONID=ECC9D5FFFD8BFE7CF2CE537BCEB57A83[\r][\n]"sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.wire: >> "Accept: */*[\r][\n]"sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.wire: >> "Content-Length: 0[\r][\n]"sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.wire: >> "Host: 10.60.152.132:3030[\r][\n]"sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.wire: >> "Proxy-Connection: Keep-Alive[\r][\n]"sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.wire: >> "User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_101)[\r][\n]"sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.wire: >> "Accept-Encoding: gzip,deflate[\r][\n]"sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.wire: >> "[\r][\n]"sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.headers: >> GET http://10.10.152.132:3030/mysite/web/widget/automation_index/1 HTTP/1.1sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.headers: >> Cookie: JSESSIONID=ECC9D5FFFD8BFE7CF2CE537BCEB57A83; ROBOTSESSIONID=ECC9D5FFFD8BFE7CF2CE537BCEB57A83sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.headers: >> Accept: */*sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.headers: >> Content-Length: 0sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.headers: >> Host: 10.60.152.132:3030sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.headers: >> Proxy-Connection: Keep-Alivesg
2017-05-08 12:19:54.865 DEBUG org.apache.http.headers: >> User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_101)sg
2017-05-08 12:19:54.865 DEBUG org.apache.http.headers: >> Accept-Encoding: gzip,deflatesg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "HTTP/1.1 422[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "Set-Cookie: ROBOTSESSIONID=ECC9D5FFFD8BFE7CF2CE537BCEB57A83; Max-Age=2160000; Expires=Fri, 02-Jun-2017 17:19:50 GMT; Path=/[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "Cache-Control: max-age=0[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "Expires: Mon, 08 May 2017 17:19:50 GMT[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "Content-Type: application/json;charset=UTF-8[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "Transfer-Encoding: chunked[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "Content-Encoding: gzip[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "Vary: Accept-Encoding[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "Date: Mon, 08 May 2017 17:19:49 GMT[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.impl.conn.DefaultClientConnection: Receiving response: HTTP/1.1 422 sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.headers: << HTTP/1.1 422 sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.headers: << Set-Cookie: ROBOTSESSIONID=ECC9D5FFFD8BFE7CF2CE537BCEB57A83; Max-Age=2160000; Expires=Fri, 02-Jun-2017 17:19:50 GMT; Path=/sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.headers: << Cache-Control: max-age=0sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.headers: << Expires: Mon, 08 May 2017 17:19:50 GMTsg
2017-05-08 12:19:54.896 DEBUG org.apache.http.headers: << Content-Type: application/json;charset=UTF-8sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.headers: << Transfer-Encoding: chunkedsg
2017-05-08 12:19:54.896 DEBUG org.apache.http.headers: << Content-Encoding: gzipsg
2017-05-08 12:19:54.896 DEBUG org.apache.http.headers: << Vary: Accept-Encodingsg
2017-05-08 12:19:54.896 DEBUG org.apache.http.headers: << Date: Mon, 08 May 2017 17:19:49 GMTsg
2017-05-08 12:19:54.896 DEBUG org.apache.http.impl.client.DefaultHttpClient: Connection can be kept alive indefinitelysg
2017-05-08 12:19:54.896 DEBUG io.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder: Parsing response as: application/json;charset=UTF-8sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "a[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "[0x1f]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "[0x8b]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "[0x8]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "[0x0]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "[0x0][0x0][0x0][0x0][0x0][0x0]"sg
2017-05-08 12:19:54.896 DEBUG io.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder: Parsed data to instance of: class org.apache.http.conn.EofSensorInputStreamsg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "3f[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "[0xaa]VJ-*[0xca]/R[0xb2]RrK[0xcc][0xcc]IMQ([0xc9]WHO-Q[0xf0]t[0xf2]U[0xc8]TH+[0xca][0xcf]UHI,ILJ,NU([0xcf],[0xc9]P[0xc8]LQ0T[0xd0]S[0xaa][0x5][0x0][0x0][0x0][0xff][0xff]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "a[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "[0x3][0x0][0xbd][0xb1][0xb3]a9[0x0][0x0][0x0]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "0[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.wire: << "[\r][\n]"sg
2017-05-08 12:19:54.896 DEBUG org.apache.http.impl.conn.BasicClientConnectionManager: Releasing connection org.apache.http.impl.conn.ManagedClientConnectionImpl@3cae7b8bsg
2017-05-08 12:19:54.896 DEBUG org.apache.http.impl.conn.BasicClientConnectionManager: Connection can be kept alive indefinitelysg
Here's my log4j.properties.
# Define the root logger with appender file
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
# Set the name of the file
log4j.appender.FILE.File=logs/log.txt
# Set the immediate flush to true (default)
log4j.appender.FILE.ImmediateFlush=true
# Set the threshold to debug mode
log4j.appender.FILE.Threshold=debug
# Set the append to false, overwrite
log4j.appender.FILE.Append=false
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{YYYY-MM-dd HH:mm:ss.SSS} %-5p %c: %msg%n