add session ID to logging if present, refactored log()