refactoring log function