Given a file of logs, write a Python script that parses it, converts each log entry into a dictionary, and returns the relevant information.
Asked in the loop coding stage. Think aloud while coding; interviewers then added edge cases and asked for code changes.
Implement parse_logs(log_text). The input is one string containing newline-separated records. Each valid record has the format timestamp|level|service|message. Return a list of dictionaries with keys timestamp, level, service, and message. Ignore blank or malformed lines. Preserve additional | characters inside the message.
def parse_logs(log_text):