refactored log function