add DUBUG MODE for log handler and some refactor