log: fix test code variable issue and refactor code

Change-Id: I69bd800a341a06c2458713c3caa96c879be7ee9e