Add log trimming function