add new log functions

Base foundation for a future solid log system. This also change
debug() macro to use these new functions.