Capture Continuous Android System Logs Using Termux and Logcat (No Root)

16 min read Learn step‑by‑step how to set up Termux on Android to run a background Logcat service that continuously records system logs without rooting your device. October 01, 2026 10:00 How to Capture Continuous System Logs on Android Using Termux and Logcat (No Root)

When an app misbehaves, a device freezes, or you simply want to keep a history of what Android is doing, the logcat command is the most direct window into the system. However, by default Android only shows logs while you have a terminal open, and the buffer is cleared on reboot. This tutorial shows you how to turn your Android phone into a self‑contained log‑collector that runs in the background, survives reboots, and stores logs safely on internal storage – all without rooting.

Why a Persistent Logcat Service Matters

System logs contain timestamps, process IDs, and stack traces that are invaluable for diagnosing:

  • App crashes that happen when you’re not watching the screen.
  • Intermittent connectivity drops.
  • Battery‑draining background services.
  • Security‑related events such as unexpected permission changes.

Because Android clears the log buffer on reboot and the built‑in Developer Options → Show logcat view disappears when the screen is locked, a continuous service fills the gap.

Before You Start

Prerequisites

  • Android 6.0 (Marshmallow) or newer. Older versions may lack the Termux:Boot add‑on.
  • At least 200 MB of free internal storage for log files.
  • USB debugging enabled (Settings > About phone > Tap Build number seven times, then Settings > System > Developer options > Enable USB debugging).
  • A stable Wi‑Fi or mobile data connection if you plan to pull logs to a PC later.

All steps are performed directly on the device; no PC is required, although you can use adb pull to retrieve logs later.

Step 1 – Install Termux and Required Add‑ons

  1. Open the Google Play Store (or F-Droid for a free version) and search for Termux. Install the app.
  2. After installation, launch Termux. It will display a welcome message and then present a $ prompt.
  3. Update the package repository:
    pkg update && pkg upgrade -y
  4. Install the logcat wrapper (part of the util-linux package) and busybox for extra utilities:
    pkg install util-linux busybox -y
  5. Install the Termux:Boot add‑on from the Play Store. This add‑on lets Termux run scripts automatically after every device boot.

When you first launch Termux after a reboot, it may ask for permission to access storage. Accept the prompt, then run termux-setup-storage to create the /storage/emulated/0/Android/data/com.termux/files directory.

Step 2 – Create a Dedicated Log Directory

  1. In the Termux prompt, create a folder that will hold the logs:
    mkdir -p ~/logcat_logs
  2. Give the directory a clear name, for example system_log, to avoid confusion with other files:
    mv ~/logcat_logs ~/system_log
  3. Set appropriate permissions so only Termux can write to it (this also prevents other apps from reading raw logs without your consent):
    chmod 700 ~/system_log

These steps keep your logs private and avoid cluttering the shared Downloads folder.

Step 3 – Write the Log Capture Script

The script will start logcat, pipe its output to a rotating file, and run in the background. Open the built‑in editor nano (installed by default) and create start_logcat.sh:

  1. Run:
    nano ~/start_logcat.sh
  2. Paste the following content:
    #!/data/data/com.termux/files/usr/bin/bash
    
    # Directory where logs are stored
    LOG_DIR="$HOME/system_log"
    
    # Maximum size of a single log file (e.g., 5 MB). Adjust as needed.
    MAX_SIZE=5242880
    
    # Number of rotated logs to keep
    MAX_FILES=7
    
    # Current timestamp for file naming
    TS=$(date +"%Y%m%d_%H%M%S")
    
    # Full path of the active log file
    ACTIVE_LOG="$LOG_DIR/logcat_$TS.txt"
    
    # Start logcat in the background, redirecting both stdout and stderr
    logcat -v threadtime *:V > "$ACTIVE_LOG" &
    LOG_PID=$!
    
    # Function to rotate logs when size limit is reached
    rotate_logs() {
      while kill -0 $LOG_PID 2>/dev/null; do
        CUR_SIZE=$(stat -c%s "$ACTIVE_LOG")
        if [ $CUR_SIZE -ge $MAX_SIZE ]; then
          # Close current logcat process
          kill $LOG_PID
          # Start a new log file
          TS=$(date +"%Y%m%d_%H%M%S")
          ACTIVE_LOG="$LOG_DIR/logcat_$TS.txt"
          logcat -v threadtime *:V > "$ACTIVE_LOG" &
          LOG_PID=$!
        fi
        sleep 30
      done
    }
    
    # Run the rotation monitor in the background
    rotate_logs &
    
  3. Press Ctrl + X**, then **Y** to save and exit.
  4. Make the script executable:
    chmod +x ~/start_logcat.sh

This script does three things:

  • Starts logcat with the -v threadtime format, which includes timestamps, PID, and thread ID – the most useful layout for debugging.
  • Writes output to a timestamped file inside ~/system_log.
  • Monitors the file size and rotates it when it exceeds the defined limit, keeping only the last seven files to avoid storage bloat.

Step 4 – Automate the Script with Termux:Boot

Termux:Boot runs any executable placed in ~/.termux/boot after the Android boot sequence completes. Follow these steps:

  1. Create the boot directory if it doesn’t exist:
    mkdir -p ~/.termux/boot
  2. Copy the script into that directory:
    cp ~/start_logcat.sh ~/.termux/boot/
  3. Ensure the script remains executable:
    chmod +x ~/.termux/boot/start_logcat.sh
  4. Reboot the device to test the automation.
    • After reboot, open Termux and run ps | grep logcat. You should see a logcat process running.
    • Check the log directory: ls -lh ~/system_log. You should see at least one .txt file.

If the script does not start, verify that Termux:Boot has permission to run in the background (Settings > Apps > Termux:Boot > Battery → “Unrestricted” or “Allow background activity”).

Step 5 – Retrieve and Analyse Logs

There are three convenient ways to get the logs off the device:

  1. Direct download via USB: Connect the phone to a PC, enable File Transfer, then navigate to Android/data/com.termux/files/home/system_log and copy the .txt files.
  2. ADB pull (requires a PC with adb installed):
    adb pull /data/data/com.termux/files/home/system_log ./android_logs
    This command pulls the entire log directory to a local folder named android_logs.
  3. Termux built‑in upload: Install termux-share and run:
    termux-share -a send -c text/plain -f ~/system_log/logcat_*.txt
    This opens Android’s share sheet, allowing you to email, upload to cloud storage, or send via messaging.

Once you have the files, you can open them in any text editor or import them into log‑analysis tools such as Logcat Viewer or grep for keyword searches.

Step 6 – Optional: Encrypt Logs for Sensitive Environments

If the device handles private data (e.g., corporate devices), you may want to encrypt the log files before they leave the phone. Termux provides openssl out of the box:

  1. Install OpenSSL if not already present:
    pkg install openssl -y
  2. Encrypt a single file (replace mykey with a strong passphrase):
    openssl aes-256-cbc -salt -in ~/system_log/logcat_20230101_120000.txt -out ~/system_log/logcat_20230101_120000.enc -k mykey
  3. Delete the plaintext file securely:
    shred -u ~/system_log/logcat_20230101_120000.txt
  4. When you need to read the log again, decrypt it:
    openssl aes-256-cbc -d -in ~/system_log/logcat_20230101_120000.enc -out ~/system_log/logcat_20230101_120000.txt -k mykey

For routine encryption, consider wrapping the above commands into a small script that runs after each rotation.

Troubleshooting

Logcat Returns “Permission denied”

On Android 10+ the READ_LOGS permission is restricted to system apps. However, when you enable Developer options → Enable USB debugging, the logcat command works for the current user. If you still see the error:

  • Make sure you have Developer options enabled.
  • Revoke and re‑grant USB debugging permission (Settings > Developer options > Revoke USB debugging authorizations, then reconnect to the device).
  • Some OEMs (e.g., Xiaomi, OnePlus) hide logs behind additional toggles. Look for Logcat access or Debug logging in the developer menu.

Log Files Grow Too Large Quickly

If you notice storage filling up despite the rotation logic, try these adjustments:

  • Reduce the maximum file size (e.g., MAX_SIZE=2097152 for 2 MB).
  • Lower the log level filter. Replace *:V with *:I to capture only informational messages and above.
  • Exclude noisy tags by adding -s filters, e.g., logcat -v threadtime -s ActivityManager:I SystemServer:I *.

Script Does Not Restart After Reboot

Common causes:

  • Battery optimisation – Android may kill Termux:Boot. Disable optimisation for both Termux and Termux:Boot in Settings > Apps > [App] > Battery > Unrestricted.
  • Missing execution permission – Double‑check chmod +x ~/.termux/boot/start_logcat.sh.
  • Incorrect path – The script must reside exactly in ~/.termux/boot/. A stray sub‑folder will prevent execution.

Unable to Pull Logs via ADB

On newer Android versions, the /data/data/com.termux directory is not accessible without root. Use the public storage path instead:

adb pull /sdcard/Android/data/com.termux/files/home/system_log ./android_logs

This works because Termux creates a symlink from its private home to the shared /sdcard location when you run termux-setup-storage.

Safety and Privacy Considerations

  • Logs may contain personal data such as usernames, device IDs, or even fragments of messages. Treat them as sensitive.
  • Never share raw log files publicly without redacting private information.
  • If the device is used in a corporate environment, verify with your security policy before enabling continuous logging.
  • Remember that the script runs with the same privileges as your user account. It cannot access other apps’ private data, but it can see system‑wide events.

What to Expect After Completion

Once the service is active, you will see a logcat process listed in ps. New .txt files will appear in ~/system_log roughly every time the size limit is reached (default 5 MB). The rotation mechanism ensures you always have the most recent week of logs, and older files are automatically deleted.

Extending the Setup

The basic framework can be adapted for other monitoring needs:

  • Network traffic capture – Replace logcat with tcpdump (available via pkg install tcpdump) and store PCAP files.
  • Battery statistics – Use dumpsys batterystats in a similar rotating script.
  • Crash dump aggregation – Append adb bugreport output to the same directory on demand.

Because everything runs inside Termux, you can combine multiple scripts, schedule them with cron (via the cronie package), or even push logs to a remote server using scp or rsync for centralized analysis.

With this guide you now have a reliable, non‑root method to capture, retain, and analyse Android system logs on any device. Whether you’re a developer hunting a bug, a power user monitoring battery health, or an IT admin needing audit trails, the Termux‑based log collector gives you the visibility you need without compromising device integrity.

User Comments (0)

Add Comment
We'll never share your email with anyone else.