1import logging
2import sys
3
4logger = logging.getLogger()
5logger.setLevel(logging.INFO)
6formatter = logging.Formatter('%(asctime)s | %(levelname)s | %(message)s',
7 '%m-%d-%Y %H:%M:%S')
8
9stdout_handler = logging.StreamHandler(sys.stdout)
10stdout_handler.setLevel(logging.DEBUG)
11stdout_handler.setFormatter(formatter)
12
13file_handler = logging.FileHandler('logs.log')
14file_handler.setLevel(logging.DEBUG)
15file_handler.setFormatter(formatter)
16
17logger.addHandler(file_handler)
18logger.addHandler(stdout_handler)
19
1import logging
2
3logging.basicConfig(level=logging.WARNING)
4logger = logging.getLogger(__name__)
5logger.setLevel(logging.DEBUG)
6
7logger.debug("some debugging...")
8logger.error("some error...")
1How do you use Log4J in your framework?
2Basically it is printing/logging the important
3events of the application/test run.
4in my project I did logging using the log4j library.
5I added the library dependency into pom.xml.
6For logging we create an object from
7Logger Interface and LogManager class using
8getLogger method and passing the class name in it;
9
10private static Logger log = LogManager.getLogger(LogDemo.class.getName());
11static Logger log = Logger.getLogger(log4jExample.class.getName());
12
13We create it by passing the
14name of the current class.
15Then we can use this object
16to do our logging.
17log.info
18log.debug
19log.fatal
20log.error
21
22The Logger object is responsible for capturing
23logging information and they are stored
24in a namespace hierarchy.
1Logging
2In many cases it can be useful to print the
3response and/or request details in order to
4help you create the correct expectations and
5send the correct requests. To do help you do thi
6s you can use one of the predefined filters
7supplied with REST Assured or you can use one of the shortcuts.
8
9Request Logging
10
11given().log().all(). .. //
12Log all request specification details
13including parameters, headers and body
14given().log().params(). .. // Log only the parameters of the request
15given().log().body(). .. // Log only the request body
16given().log().headers(). .. // Log only the request headers
17given().log().cookies(). .. // Log only the request cookies
18given().log().method(). .. // Log only the request method
19given().log().path(). .. // Log only the request path
1formatter = logging.Formatter('[%(asctime)s] p%(process)s {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s','%m-%d %H:%M:%S')
2