implement log saving function