Improve logging system (fix #278)