I have a Python script, which sends requests to our API using Requests module, then recieve the ansver, parse it and says that's everything is ok or not. The result displays with 'print'. Here is simple example:
for i in response:
if i in response_keys:
print('[Request_name] '+i+' is ok')
else:
print('[Request_name] Extra key ' +i+' in resronse)
Now I need to log these prints ti file. When I use Logging module like this:
#Example without sending a request, just logging configuration and check
import logging
logging.basicConfig(filename='Autotests_log.log', level=logging.INFO, format='%(asctime)s %(message)s' )
for i in response:
if i in response_keys:
logging.info('[Request_name] '+i+' is ok')
else:
logging.info('[Request_name] '+i+' is not ok')
I see this in the log file:
2016-04-20 14:24:44,823 Starting new HTTP connection (1): 192.168.1.44
2016-04-20 14:24:44,873 [Request_name] success is ok
2016-04-20 14:24:44,874 [Request_name] statusCode is ok
2016-04-20 14:24:44,874 [Request_name] data is ok
2016-04-20 14:24:44,876 Starting new HTTP connection (1): 192.168.1.44
2016-04-20 14:24:44,924 Starting new HTTP connection (1): 192.168.1.44
2016-04-20 14:24:44,974 Starting new HTTP connection (1): 192.168.1.44
2016-04-20 14:24:45,017 Starting new HTTP connection (1): 192.168.1.44
What should I do to see just this in log:
2016-04-20 14:24:44,873 [Request_name] success is ok
2016-04-20 14:24:44,874 [Request_name] statusCode is ok
2016-04-20 14:24:44,874 [Request_name] data is ok