GUIDE

How to log serial output to a file, with timestamps

You need the console output of a device in a file: to share it, to search it, or to catch a fault that only shows up after hours. Here is how to do it with the usual tools, and what to watch out for when the capture has to run for days.

Updated September 2026

PuTTY (Windows)

  • Open PuTTY and select Connection type “Serial”, then enter the COM port and speed.
  • Go to Session → Logging and choose “Printable output” (or “All session output” to keep control characters).
  • Set the log file name. Placeholders such as &Y&M&D-&T give each session its own file, for example capture-&Y&M&D-&T.log.
  • Choose whether to overwrite or append if the file exists, then open the session.

PuTTY writes the raw output. It does not add a timestamp to each line, so you only know when a line arrived if the device prints its own time. If you need per-line timestamps, use Tera Term, minicom or one of the scripts below.

Tera Term (Windows)

  • Connect to the serial port (Setup → Serial port to set the speed).
  • Open File → Log… and choose a file name. Date placeholders like %Y%m%d_%H%M%S are supported in the name.
  • Tick “Timestamp” to add the time to every line, and “Append” if you want to continue an existing file.

Tera Term is the easiest option on Windows if you need timestamps without writing a script.

minicom (Linux, macOS)

minicom -D /dev/ttyUSB0 -b 115200 -C capture.log

The -C option writes everything to capture.log. Inside minicom, Ctrl-A L starts or stops the capture file, and Ctrl-A N toggles a timestamp at the start of each line (recent versions).

Linux command line

For unattended captures, a plain shell pipeline is often more robust than a terminal program:

# Set the port to 115200 baud, raw mode
stty -F /dev/ttyUSB0 115200 raw -echo

# Add a timestamp to every line (ts is in the "moreutils" package)
cat /dev/ttyUSB0 | ts '%Y-%m-%dT%H:%M:%.S' >> capture.log

Run it inside screen or tmux, or as a systemd service, so it keeps going when you log out. Rotate the file with logrotate if the capture is long.

Python script (any OS)

A few lines of pyserial give you full control over the format, for example ISO 8601 timestamps with the UTC offset:

import datetime
import serial  # pip install pyserial

PORT = '/dev/ttyUSB0'  # Windows: 'COM3'
with serial.Serial(PORT, 115200, timeout=1) as port, open('capture.log', 'a', buffering=1) as log:
    while True:
        line = port.readline()
        if line:
            stamp = datetime.datetime.now().astimezone().isoformat(timespec='microseconds')
            log.write(f"{stamp} {line.decode('utf-8', 'backslashreplace').rstrip()}\n")

Binary or non-UTF-8 bytes are kept as \x escapes instead of breaking the log.

Raspberry Pi as a logger

A Raspberry Pi running the command-line or Python version is a common do-it-yourself logger that you can leave behind. It works, but check these points first:

  • Power loss can corrupt the SD card. Use a read-only root file system or at least a good SD card and journaling.
  • Without a network or an RTC module, the clock is wrong after a reboot, and so are your timestamps.
  • RS-232 and RS-485 need a level converter or transceiver. The Pi’s UART is 3.3 V TTL only.
  • There is no galvanic isolation. On machines with ground offsets, that can mean corrupted data or damaged hardware.

When the capture has to run for days

Logging from a laptop is fine at the bench. It becomes unreliable when you leave it running at a customer site or overnight in a test lab:

  • The laptop goes to sleep or reboots for an update, and the log stops.
  • USB power management suspends the serial adapter, and the port disappears.
  • Timestamps are missing because logging was started without them.
  • Ground offsets between the laptop and the machine cause garbage or worse.
  • Nobody wants to leave a company laptop in a customer’s cabinet for three weeks.

If you still go that way: disable sleep (on Windows, powercfg /change standby-timeout-ac 0), disable USB selective suspend in the power options, turn on per-line timestamps, split the log into daily files, and use an isolated USB-serial adapter when the target is not on the same ground.

A standalone logger instead

This is the situation we are building the Remora SFL-2 for: a small serial logger you connect to one or two ports and leave on site. It records UART, RS-232 or RS-485 output on two isolated, receive-only inputs, with timestamps on every line, to 8 GB of internal storage. No laptop, no app, no cloud. When you come back, you plug in USB-C and copy plain text files.

The SFL-2 is in development. Pre-orders are planned for January 2027.