fixed toLog function