Fix bugs in log function