Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 1.1 KB

File metadata and controls

32 lines (24 loc) · 1.1 KB

How to easily capture logs using SimpleLogger

Contents

Why use logs?

Logs can be a good way to capture both flow of a program and state as the program progresses. Adding logs to a program is also extremely safe which allows you to get regression tests in place.

Capturing logs in test

By default logging goes to System.out. When capturing for testing, you will want them to instead go to a local StringBuffer. Here's how to do it using the SimpleLogger:

StringBuffer log = SimpleLogger.logToString();
new Sample().methodThatLogs();
Approvals.verify(log);

snippet source | anchor

See also