Fix logging script (head before tail)