Some refactoring on logging