Custom Logger | Bondar Academy
Course: Playwright API Testing with TypeScript
Module: Building a Framework
Instructor: Artem Bondar
Lesson Summary
In this lesson, we created a custom logger for API tests to enhance debugging capabilities. The need for this logger arose from the limitations of the default test reports, which often lack detailed information about failed tests. Key Issues with Default Reporting Test reports only show that a test has failed without explaining why . Common status codes like 422 are displayed without context. Playwright does not log request and response details, making it hard to diagnose issues. Creating the Custom Logger We implemented a logger in a new file called logger.ts within the utils folder. The logger includes: API Logger Class : Contains a private field recentLogs to store log entries. logRequest Method : Collects details about the request, including: method (GET, POST, etc.) URL headers body (optional) logResponse Method : Captures response details, specifically statusCode and responseBody . getRecentLogs Method : Retrieves and formats the logs for easy reading. Benefits of the Custom Logger The custom logger allows us to: Aggregate request and response details for better understanding of test failures. Isolate log instances for each test, ensuring that logs from parallel tests do not interfere with each other. In summary, we developed a logger with three methods to enhance our debugging process, making it easier to analyze API test failures.