import tensorflow as tf
import re

# Create a summary writer
logdir = "logs/"
writer = tf.summary.create_file_writer(logdir)

# Read the journalctl logs
with open("ollama.log", "r") as f:
    for line in f:
        # Example: Parse the log line (you may need to adjust this regex)
        match = re.search(r'(\d+-\d+-\d+ \d+:\d+:\d+).*?(\w+): (.*)', line)
        if match:
            timestamp = match.group(1)
            log_level = match.group(2)
            message = match.group(3)

            # Write to TensorBoard
            with writer.as_default():
                tf.summary.text("log_message", f"{timestamp} [{log_level}] {message}", step=0)

# Close the writer
writer.close()
