Formatting log files according to tree structure