refactoring: extracted log function