Rework logging
* add lots of comments and documentation
* add new logging type debug