fix StringIO errors in unit test

alarm tests are throwing StringIO failures as it's being closed to soon.
change the way we capture logging.

Change-Id: Ifd956b8fe144219d029f8afb369ec25d13177078
Closes-Bug: #1329692
(cherry picked from commit c0702b298a8614a713ca392d0fcdb9bdaae9faac)
Merge "fix StringIO errors in unit test" into stable/icehouse