362

I installed Android Studio yesterday, and I tried to use the LogCat to see the logs. But there is nothing to show in the logcat. I used the terminal to run ./adb logcat and it works.

Is there someone who can explain to me how to use logcat in Android Studio?

Zoe
  • 27,060
  • 21
  • 118
  • 148
user2506173
  • 3,959
  • 3
  • 16
  • 9
  • 6
    just restart android studio. – Amit Vaghela Apr 14 '16 at 09:00
  • "./adb" means what? I don't know where that directory is. – Nerdy Bunz May 15 '18 at 06:38
  • Go to AVD Manager and cold boot the emulator. It worked for me! Changing the emulator name might also work! – beginner Jun 07 '21 at 10:24
  • It's Feb 2022 and running Android Studio Android Studio Bumblebee | 2021.1.1. All I did was to restart Android Studio. @AmitVaghela answer is helped me – Donzaala Feb 21 '22 at 09:39
  • I tried almost all the suggestions in these answers, but none of them worked for me. In the end, I had to resort to using a different logcat-viewer plugin for Android Studio: https://josesamuel.com/logviewer [it has some bugs of its own, eg. process filtering fails for me, but at least the logs and text-filtering work!] – Venryx Jul 04 '23 at 20:28

69 Answers69

464

Restarting logcat helps me always.

enter image description here

Amio.io
  • 20,677
  • 15
  • 82
  • 117
  • 4
    I think after restarting logcat you need to run your app again – JoelFan Dec 02 '14 at 15:21
  • 13
    Nice and simple. Started working straight away after doing this. I couldn't see the restart button. Sometimes it is hidden if your screen is small. There are 2 arrows like this ">>" and then you can see the restart button like in the above image. – uplearned.com Jan 07 '15 at 01:41
  • For me nothing of that works. logcat stopped working since one of the last updates. "adb logcat" works fine. restarting PC, restarting android studio, restarting phone .. nothing helps to get a line of logcat there – John Jan 22 '15 at 19:47
  • 3
    The filtering in Logcat doesn't work in the newer versions of Android Studio. But in Android Device Monitor it still works, so I use that. – K.C. Feb 02 '15 at 10:36
  • 8
    Thank you so much! Can't belive I've been restarting Android Studio for nothing all these years :D – Marija Milosevic Aug 28 '15 at 18:13
  • Very useful answer. In my case logcat works fine but often doesn't display error logs (!). I restart logcat and last error logs magically appear. – j.c Mar 09 '16 at 18:09
  • and sometime restarting Android Studio help us... anyway **restart** is a master key in the computer world :) – Ayub Mar 30 '17 at 17:38
  • 2
    This happened for me when I had a filter enabled and forget about it :( – Elliott Beach Jun 29 '17 at 15:54
  • 1
    Year 2020: I had to restart logcat, restart app and restart Android. – Pablo Alfonso Mar 06 '20 at 15:23
  • Or possibly You disabled logging via phone's Developer Options. – Zakir Shikhli Sep 08 '20 at 12:24
  • It is strange, could not even see that icon. Only restarting Android studio helped me, – Karan Sharma Sep 15 '20 at 05:21
  • If Restarting logcat does not work then here is a workaround. Unplug your device and plug again. (close and reopen works if you are using emulator) – Dev Vanana Jan 13 '21 at 13:11
  • close and open AS simple solution but works everytime – Yohanim Mar 24 '21 at 08:35
  • On top of this, I had to clear the old logs with 'No Filter' selected, then Android Studio started accepting new logs. – Gligor Atanasovski Sep 11 '21 at 11:20
  • @Yohanim does not work everytime. – Michał Dobi Dobrzański Jan 20 '23 at 08:49
173

I get into this state often. Logcat is blank. Debugging works, I can hit breakpoints. No filters are set. Log level is on Verbose. I fix it by repeatedly looping through the following:

  • Restart logcat (see Zatziky's answer above)
  • Change the log level to Debug (or anything else) and back to Verbose.
  • unplugging and plugging back in the device
  • running adb kill-server && adb start-server
  • Close Android Studio and launch ddms on the command line.
  • Restart Android Studio

And finally restarting the computer if all else fails.

The problem is intermittent, I think Android Studio is just buggy.

Robert Karl
  • 7,598
  • 6
  • 38
  • 61
  • 3
    I did all of this multiple times and it's still broken, I have no idea why. Command line works fine, but it seems disconnected from Android Studio. I hope this gets fixed, I'm just going to reinstall my SDK and Android Studio to see what happens because I can't work fast like this. – G_V Nov 18 '14 at 16:02
  • 2
    I'm sorry to hear that... what version of Android Studio are you running? Can you post if you find what fixes the issue? – Robert Karl Nov 19 '14 at 05:59
  • 2
    Android Studio 0.8.14. Reinstalling it did nothing, going to try the SDK and config files now. – G_V Nov 19 '14 at 09:53
  • 2
    I'm using Android Studio 1.0.2 and it's still not fixed. EDIT: see @zatziky response. That "reset" button fixes it – Someone Somewhere Jan 13 '15 at 00:10
  • It's completely disfunctional since many weeks for me, no way to get it working no matter what I do. – John Jan 22 '15 at 19:57
  • I feel so bad about this android studio! we are just trying to train the learning curve of this buggy studio!!! It feels like the first years of android over eclipse which everything was so manual and bugfull – VSB Jan 29 '15 at 18:34
  • Nice list, thx. Maybe you coudl add the point "Check for stupid filters" which caused my LogCat to be quiet. I guess I put the filter in accidentally. – user2345998 Mar 31 '15 at 11:56
  • 12
    Man i feel stupid.. nothing worked, NOTHING.. until i cleared the search box in Logcat window.. I was looking for something the whole time. – Sindri Þór Sep 23 '15 at 00:57
  • i just had mine go away. and i had something in the search box. so you coment saved me! thank you. – Ray Tayek Feb 13 '16 at 05:48
  • Restarting the computer helped me. AS 2.2 Preview 3 – lingareddyk Jun 29 '16 at 09:32
  • 1
    For me I started with `adb kill-server && adb start-server` without trying the first steps first and fixed it immediately. – Rock Lee Oct 12 '16 at 18:57
  • Same here, my search box had the work 'implicit' in it and I didn't type it there. – midiwriter Apr 19 '20 at 22:55
  • 1
    7 years passed but no fix from Android studio, can anyone please wake them :( – Shahzain ali Aug 29 '21 at 23:07
  • What is ddms and what command should I write? – MML Aug 27 '22 at 14:08
  • Honestly, how is this still an issue in 2022, almost 2023 – MikkelT Dec 15 '22 at 06:48
  • Tis now 2023 and issue persists fwiw. – Reid Mac Jan 12 '23 at 19:28
86

I had the same problem but I solved by the following steps, Try this once.

1) In the android studio.

2) Open android Monitor window(bottom of android studio)

3) You can see the drop down in the right corner(spinner)

4) select -- Show only Selected application.

enter image description here

Surendar D
  • 5,554
  • 4
  • 36
  • 38
68

You need to press Alt+6 twice to restart the logcat window. That way it'll show the log outputs.

The problem mainly happens in debug mode.

Krishna Raj Salim
  • 7,331
  • 5
  • 34
  • 66
0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184
46

Best way to fix some unnecessary changes is to invalidate caches

Go to FILE -> click "INVALIDATE CACHES/RESTART" then a dialog box will pop-up, Select "INVALIDATE CACHES/RESTART" button.

Android studio will automatically restart and rebuild the index.

Roshan
  • 1,380
  • 13
  • 23
36

These helped me :

1.Enable ADB integration enter image description here 2. Go to Android Device Monitor Check if your device is online and Create a required filter enter image description here enter image description here enter image description here enter image description here

Dev Gurung
  • 1,290
  • 14
  • 16
33

Run this command in terminal. It will start working again.

adb kill-server && adb start-server
Sajid Zeb
  • 1,806
  • 18
  • 32
16

Restarting Android Studio helped me.

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
Manish Butola
  • 557
  • 6
  • 15
15

In android Studio application you need to click Debug application option (Shift+f9) to run in debug mode and to enable LogCat.

Ashutosh Nigam
  • 868
  • 8
  • 27
14

Not a technical answer but you might want to check the search box for the logcat. If there is any character inputted, your logcat will be empty as it will be searching for that certain character or word, and then if its not present, your logcat log will be totally empty.

whit3hawks
  • 429
  • 7
  • 14
12

Make sure you have Logger buffer sizes propper value in your emulator developer menu option.

enter image description here

9

For me, the issue was that I had two emulators with the same name (I created it, deleted it, and then created it again with the same name). There were two emulator entries in the logcat dropdown and it was connected to the wrong one. All I had to do was switch to the other one. I prevented the problem permanently by renaming the emulator.

enter image description here

Mark Lu
  • 1,348
  • 1
  • 15
  • 19
8

**

  • Read this if you are still stuck with logcat being empty

**

I've just solved this after MONTHS of annoyment and trouble.
Nothing helped, the device monitor worked fine during debugging but the standard logcat view was always empty.

The reason was annoyingly simple:
The logcat view was there but it had been moved to 0 width by an update!

You are in "ALT 6" Tab, you see two tabs in there "ADB logs" and "Devices | logcat"
Devices | logcat really means that it consists of Devices AND logcat, split by a vertical border.
The vertical border can be moved and during an update it seems to have moved to 100% right.

This results in the logcat to be collected but not displayed, move your mouse pointer to the right of the tool window and just DRAG logcat back into view.

This solution won't help everyone but I found many people with working ADB connection and still no logcat output, those might be hit by the same problem.

John
  • 7,507
  • 3
  • 52
  • 52
8

Try to close the project and re-open it .It worked for me. Logs will be reappear.

fazil
  • 1,155
  • 11
  • 24
  • This worked for me...Google (or IntelliJ) should check why this happens :S because this didn't happen to me on AS2 only on AS3 – Asfo Jul 03 '18 at 23:57
7

enter image description here

In my case, I removed "image" from the little dropdown on the right. It showed up just fine after that. That's because it will be searching the log for the keyword in that searchbox, so if it doesn't find any matches, it returns blank

Pamela Sillah
  • 193
  • 4
  • 17
7

It's weird to still encounter this problem even on a recent version of Android Studio. I read through the long list of solutions but they did not work for me. The accepted answer worked on an earlier version of Android Studio ( I guess it was v2.3)

I did the following to get Logcat working again:

  1. Logcat > Show only selected application > No filters

enter image description here

  1. Logcat > No filters > Show only selected application

enter image description here

I expected resetting logcat should ideally give me the same effect but it didn't. Manually toggling filter was the only thing that worked.

This is on Android Studio 3.0.1 (stable) (I can't update it before finishing the current project) The issue occurred when I started Android studio in the morning to continue the work I left at night. I hope the devs will look into this. It was painstaking to try over 15 solutions from stackoverflow and still see no result. It's even irritating to reveal another solution for future victims of this issue.

sziraqui
  • 5,763
  • 3
  • 28
  • 37
7

When everything else didn't work, here's what I did. Since adb logcat worked nicely, I decided to rely on it. Running adb logcat -v color in the Android Studio's embedded terminal produced outputs similar to the normal logcat, and allowed code links to work too:

Running adb logcat -v color in the embedded console

But this came with a few issues:

  • You can't specify a package to watch. Using the --pid=<your PID> option, you can watch the output of a single process. But since every time you restart your app the PID changes, you have re-run this command with every restart.
  • The colors are annoying (in my opinion).
  • The output fields are not aligned with previous messages, the whole thing is not well formatted which makes following the logcat much harder than it should be (the same happens with the embedded logcat, though).

So I decided to make my own tool to automatically watch my package PID(s) and prettify the logcat output:

import java.awt.AWTException;
import java.io.*;
import java.util.ArrayList;
import java.awt.Robot;
import java.awt.event.KeyEvent;

public class Logcat {

    private static final String ADB_FILE_PATH = "adb";

    // Customizations,
    private static final Color     V_COLOR = Color.RESET;
    private static final Color     D_COLOR = Color.RESET;
    private static final Color     I_COLOR = Color.RESET;
    private static final Color     W_COLOR = Color.BLUE;
    private static final Color     E_COLOR = Color.RED_BRIGHT;
    private static final Color  HINT_COLOR = Color.MAGENTA_BOLD_BRIGHT;
    private static final Color OTHER_COLOR = Color.GREEN_BOLD_BRIGHT;

    private static final int       DATE_LENGTH =   5;
    private static final int       TIME_LENGTH =  12;
    private static final int PROCESS_ID_LENGTH =   5;
    private static final int  THREAD_ID_LENGTH =   5;
    private static final int  LOG_LEVEL_LENGTH =   1;
    private static final int        TAG_LENGTH =  20;
    private static final int    MESSAGE_LENGTH = 110;

    private static final String SEPARATOR = " | ";
    private static final String CONTINUATION = "→";
    private static final String INDENTATION = "  ";

    private static final int PROCESS_IDS_UPDATE_INTERVAL_MILLIS = 1224;

    private static final int HISTORY_LENGTH = 1000;

    // State,
    private static boolean skipProcessIDCheck;
    private static ArrayList<String> processIDs = new ArrayList<String>();

    private static String logLevelToShow="V";  // All.

    private static Process logcatProcess;
    private static boolean appClosed;
    private static boolean stopEverything;

    private static String[] history = new String[HISTORY_LENGTH];
    private static int currentLocationInHistory, historyLength;

    public static void main(final String args[]) {

        clearAndroidStudioConsole();
        System.out.println("besm Allah");

        // Get processes ids of the provided package,
        if (args.length==0) {
            skipProcessIDCheck = true;
        } else {
            skipProcessIDCheck = false;
            getProcessIDs    (args[0]);    // Do it once before we start.
            monitorProcessIDs(args[0]);    // Do it periodically from now on.
        }

        // Start capturing and prettifying logcat,
        if (!monitorLogcat()) {
            stopEverything = true;
            return;
        }

        // Handle user input,
        handleUserInput();
    }

    private static void watch(final Process process, final ProcessListener listener) {

        // Read process standard output and send it to the listener line by line,
        new Thread() {
            public void run() {
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                String line = "";
                try {
                    do {
                        if (bufferedReader.ready()) {
                            line = bufferedReader.readLine();
                            if (line!=null && !line.isEmpty()) listener.onNewLine(line);
                        } else {
                            Thread.sleep(100);
                        }
                    } while (line!=null && !stopEverything);
                } catch (Exception e) { e.printStackTrace(); }
            }
        }.start();
    }

    private static void monitorProcessIDs(String packageName) {

        // Continuously monitor the process IDs of this package and update when changed,
        new Thread() {
            public void run() {
                do {
                    try { Thread.sleep(PROCESS_IDS_UPDATE_INTERVAL_MILLIS); } catch (InterruptedException e) {}
                    getProcessIDs(packageName);
                } while (!stopEverything);
            }
        }.start();
    }

    private static void getProcessIDs(String packageName) {

        // Get the process IDs associated with this package once,
        ArrayList<String> newProcessIDs = new ArrayList<String>();
        Runtime runtime = Runtime.getRuntime();
        try {
            Process getPIDProcess = runtime.exec(ADB_FILE_PATH + " shell ps");
            watch(getPIDProcess, (line) -> {
                if (line.contains(packageName)) {
                    newProcessIDs.add(removeRedundantSpaces(line).split(" ")[1]);
                }
            });
            getPIDProcess.waitFor();
            Thread.sleep(500);  // Make sure we've already handled all the input from the process.
        } catch (Exception e) { e.printStackTrace(); }

        // Return immediately if program is closed,
        if (stopEverything) return ;

        // Some action upon getting the pid(s),
        boolean shouldRepeatHistory = false;
        if (newProcessIDs.isEmpty()) {

            // Just closed,
            if (!appClosed) {
                appClosed = true;
                prettify("----- App closed -----");
            }
        } else if (appClosed) {

            // Just opened, clear,
            appClosed = false;
            clearAndroidStudioConsole();
            prettify("----- App opened -----");
            shouldRepeatHistory = true;
        } else {

            // Detect changes in processes,
            for (String pid : newProcessIDs) {
                if (!processIDs.contains(pid)) {
                    clearAndroidStudioConsole();
                    prettify("----- Process(es) changed (or app restarted - some logs could have been missed) -----");
                    shouldRepeatHistory = true;
                    break ;
                }
            }
        }

        // Set the new PID(s),
        processIDs = newProcessIDs;
        if (shouldRepeatHistory) repeatHistory();
    }

    private static boolean monitorLogcat() {

        Runtime runtime = Runtime.getRuntime();
        try {
            logcatProcess = runtime.exec(ADB_FILE_PATH + " logcat -v threadtime");
            watch(logcatProcess, (line) -> {

                // Learn history, in case we need to repeat it,
                if (appClosed || processLogcatLine(line)) {
                    history[currentLocationInHistory] = line;
                    currentLocationInHistory = (currentLocationInHistory + 1) % history.length;
                    if (historyLength<history.length) historyLength++;
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

        return true;
    }

    private static boolean processLogcatLine(String line) {
        try {
            return prettify(line);
        } catch (Exception e) {
            print(line, OTHER_COLOR);
            System.out.println();

            // Debug,
            e.printStackTrace();
            return true;
        }
    }

    // Returns true if line should be kept in history,
    private static synchronized boolean prettify(String line) {

        if (line.startsWith("-")) {
            // It's a "beginning of <something>" line,
            print(line, HINT_COLOR);
            System.out.println();
            return true;
        }

        // Get the individual fields,
        String      date = line.substring(0, line.indexOf(' ')); line = line.substring(line.indexOf(' ')+1); line = line.trim();
        String      time = line.substring(0, line.indexOf(' ')); line = line.substring(line.indexOf(' ')+1); line = line.trim();
        String processID = line.substring(0, line.indexOf(' ')); line = line.substring(line.indexOf(' ')+1); line = line.trim();

        // Break early if possible,
        if (!skipProcessIDCheck && !processIDs.contains(processID.trim())) return false;

        // Continue parsing,
        String  threadID = line.substring(0, line.indexOf(' ')); line = line.substring(line.indexOf(' ')+1); line = line.trim();
        String  logLevel = line.substring(0, line.indexOf(' ')); line = line.substring(line.indexOf(' ')+1); line = line.trim();

        // Break early if possible,
        switch (logLevel) {
            case "V": if (!"V"    .contains(logLevelToShow)) return true; break;
            case "D": if (!"VD"   .contains(logLevelToShow)) return true; break;
            case "I": if (!"VDI"  .contains(logLevelToShow)) return true; break;
            case "W": if (!"VDIW" .contains(logLevelToShow)) return true; break;
            case "E": if (!"VDIWE".contains(logLevelToShow)) return true; break;
        }

        // Continue parsing,
        String       tag = line.substring(0, line.indexOf(':')); line = line.substring(line.indexOf(':')+1); line = line.trim();

        // Because some tags have a trailing ":",
        if (line.startsWith(":")) {
            tag += ":";
            line = line.substring(1);
        }

        // Indent lines starting by "at",
        String indentation = "";
        if (line.startsWith("at ")) {
            indentation = "   " + INDENTATION;
            line = " " + INDENTATION + line;
        }

        // Print the prettified log,
        Color color;
        switch (logLevel) {
            case "V": color = V_COLOR; break;
            case "D": color = D_COLOR; break;
            case "I": color = I_COLOR; break;
            case "W": color = W_COLOR; break;
            case "E": color = E_COLOR; break;
            default:
                color = Color.RESET;
        }

        String fields = adjustLength(     date,       DATE_LENGTH) + SEPARATOR +
                        adjustLength(     time,       TIME_LENGTH) + SEPARATOR +
                        adjustLength(processID, PROCESS_ID_LENGTH) + SEPARATOR +
                        adjustLength( threadID,  THREAD_ID_LENGTH) + SEPARATOR +
                        adjustLength( logLevel,  LOG_LEVEL_LENGTH) + SEPARATOR +
                        adjustLength(      tag,        TAG_LENGTH) + SEPARATOR;

        // Split the message onto multiple lines if needed,
        String message = chunkPreservingParentheses(line, MESSAGE_LENGTH, 2);
        print(fields + message, color);
        System.out.println();

        while (line.length() > message.length()) {

            // Debug,
            //print(line, OTHER_COLOR);
            //System.out.println("Line: " + line.length() + "length: " + message.length() + ", cont: " + CONTINUATION.length() + "dent: " + indentation.length());
            //System.out.println();

            // Remove the already printed part.
            line = line.substring(message.length()-CONTINUATION.length());

            // Add a dot to make links work,
            boolean shouldAddDot=false;
            if (line.matches("^[^\\.]*\\(.*:[123456789][1234567890]*\\).*")) shouldAddDot = true;

            // Indent,
            line = (shouldAddDot ? "." : (indentation.isEmpty() ? "" : " ")) + indentation + line;

            // Take another chunk,
            message = chunkPreservingParentheses(line, MESSAGE_LENGTH, 2+indentation.length());

            // Front pad to align this part with the message body,
            String paddedMessage = message;
            for (int i=0; i<fields.length(); i++) paddedMessage = ' ' + paddedMessage;

            // Print,
            print(paddedMessage, color);
            System.out.println();
        }

        return true;  // Keep in local buffer.
    }

    private static String adjustLength(String text, int length) {
        while (text.length() < length) text += ' ';
        if (text.length() > length) {
            text = text.substring(0, length-CONTINUATION.length());
            text += CONTINUATION;
        }
        return text;
    }

    private static String chunkPreservingParentheses(String text, int length, int minChunckLength) {

        if (text.length() <= length) return text;

        // Take a chunk out of the text,
        String chunk = text.substring(0, length-CONTINUATION.length()) + CONTINUATION;

        // Check if a paranthesis was opened and not closed,
        int lastOpenParanthesisIndex = chunk.lastIndexOf('(');
        int lastCloseParanthesisIndex = chunk.lastIndexOf(')');
        if (lastCloseParanthesisIndex <= lastOpenParanthesisIndex) {  // Also works when either is not found.
            if (minChunckLength<1) minChunckLength = 1;
            if (lastOpenParanthesisIndex > minChunckLength+CONTINUATION.length()) { // Avoid endless loops.
                int includeParenthesisSize = (CONTINUATION.length()>0) ? 1 : 0;
                chunk = text.substring(0, lastOpenParanthesisIndex+includeParenthesisSize-CONTINUATION.length()) + CONTINUATION;
            }
        }

        return chunk;
    }

    private static void repeatHistory() {
        int index = currentLocationInHistory-historyLength;
        if (index < 0) index += history.length;
        for (int i=0; i<historyLength; i++) {
            processLogcatLine(history[index]);
            index = (index + 1) % history.length;
        }
    }

    private static void print(String text, Color color) {
        System.out.print(color);
        System.out.print(text);
        System.out.print(Color.RESET);
    }

    private static String removeRedundantSpaces(String text) {
        String newText = text.replace("  ", " ");
        while (!text.equals(newText)) {
            text = newText;
            newText = text.replace("  ", " ");
        }
        return text;
    }

    private static void clearAndroidStudioConsole() {

        // Couldn't find a reliable way to clear Intellij terminal scrollback, so we just print
        // a LOT of newlines,
        StringBuilder bunchOfNewLines = new StringBuilder();
        for (int i=0; i<124; i++) bunchOfNewLines.append(System.lineSeparator());
        System.out.print(bunchOfNewLines);

        // Scroll the current line to the top of the window,
        try {
            // If we are on Windows,
            new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
        } catch (Exception e) {

            // We are not on Windows,
            bunchOfNewLines = new StringBuilder();
            for (int i=0; i<124; i++) bunchOfNewLines.append("\b\r");
            System.out.print(bunchOfNewLines);
        }
    }

    private static void handleUserInput() {

        // Line read. Unfortunately, java doesn't provide character by character reading out of the box.
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String input = "";
        do {
            try {
                if (bufferedReader.ready()) {
                    input = input = bufferedReader.readLine().toUpperCase();

                    // Set log level,
                    if (input.equals("V")||input.equals("D")||input.equals("I")||input.equals("W")||input.equals("E")) {

                        if (!logLevelToShow.equals(input)) {
                            logLevelToShow = input;
                            clearAndroidStudioConsole();
                            repeatHistory();
                        }

                        prettify("----- Log level set to " + logLevelToShow + " -----");

                    } else if (input.equals("C")) {

                        // Clear screen and history,
                        clearAndroidStudioConsole();
                        historyLength = 0;
                    }
                } else {
                    Thread.sleep(100);
                }
            } catch (Exception e) { e.printStackTrace(); }

            // Check if the logcat process is still alive,
            if (!logcatProcess.isAlive()) {
                prettify("----- adb logcat process terminated -----");
                stopEverything = true;
            }

        } while (!stopEverything && !input.equals("Q"));

        // Allow all monitoring threads to exit,
        stopEverything = true;
    }

    interface ProcessListener {
        void onNewLine(String line);
    }

    enum Color {

        // Thanks to this answer: https://stackoverflow.com/a/51944613/1942069

        //Color end string, color reset
        RESET("\033[0m"),

        // Regular Colors. Normal color, no bold, background color etc.
        BLACK  ("\033[0;30m"),
        RED    ("\033[0;31m"),
        GREEN  ("\033[0;32m"),
        YELLOW ("\033[0;33m"),
        BLUE   ("\033[0;34m"),
        MAGENTA("\033[0;35m"),
        CYAN   ("\033[0;36m"),
        WHITE  ("\033[0;37m"),

        // Bold
        BLACK_BOLD  ("\033[1;30m"),
        RED_BOLD    ("\033[1;31m"),
        GREEN_BOLD  ("\033[1;32m"),
        YELLOW_BOLD ("\033[1;33m"),
        BLUE_BOLD   ("\033[1;34m"),
        MAGENTA_BOLD("\033[1;35m"),
        CYAN_BOLD   ("\033[1;36m"),
        WHITE_BOLD  ("\033[1;37m"),

        // Underline
        BLACK_UNDERLINED  ("\033[4;30m"),
        RED_UNDERLINED    ("\033[4;31m"),
        GREEN_UNDERLINED  ("\033[4;32m"),
        YELLOW_UNDERLINED ("\033[4;33m"),
        BLUE_UNDERLINED   ("\033[4;34m"),
        MAGENTA_UNDERLINED("\033[4;35m"),
        CYAN_UNDERLINED   ("\033[4;36m"),
        WHITE_UNDERLINED  ("\033[4;37m"),

        // Background
        BLACK_BACKGROUND  ("\033[40m"),
        RED_BACKGROUND    ("\033[41m"),
        GREEN_BACKGROUND  ("\033[42m"),
        YELLOW_BACKGROUND ("\033[43m"),
        BLUE_BACKGROUND   ("\033[44m"),
        MAGENTA_BACKGROUND("\033[45m"),
        CYAN_BACKGROUND   ("\033[46m"),
        WHITE_BACKGROUND  ("\033[47m"),

        // High Intensity
        BLACK_BRIGHT  ("\033[0;90m"),
        RED_BRIGHT    ("\033[0;91m"),
        GREEN_BRIGHT  ("\033[0;92m"),
        YELLOW_BRIGHT ("\033[0;93m"),
        BLUE_BRIGHT   ("\033[0;94m"),
        MAGENTA_BRIGHT("\033[0;95m"),
        CYAN_BRIGHT   ("\033[0;96m"),
        WHITE_BRIGHT  ("\033[0;97m"),

        // Bold High Intensity
        BLACK_BOLD_BRIGHT  ("\033[1;90m"),
        RED_BOLD_BRIGHT    ("\033[1;91m"),
        GREEN_BOLD_BRIGHT  ("\033[1;92m"),
        YELLOW_BOLD_BRIGHT ("\033[1;93m"),
        BLUE_BOLD_BRIGHT   ("\033[1;94m"),
        MAGENTA_BOLD_BRIGHT("\033[1;95m"),
        CYAN_BOLD_BRIGHT   ("\033[1;96m"),
        WHITE_BOLD_BRIGHT  ("\033[1;97m"),

        // High Intensity backgrounds
        BLACK_BACKGROUND_BRIGHT  ("\033[0;100m"),
        RED_BACKGROUND_BRIGHT    ("\033[0;101m"),
        GREEN_BACKGROUND_BRIGHT  ("\033[0;102m"),
        YELLOW_BACKGROUND_BRIGHT ("\033[0;103m"),
        BLUE_BACKGROUND_BRIGHT   ("\033[0;104m"),
        MAGENTA_BACKGROUND_BRIGHT("\033[0;105m"),
        CYAN_BACKGROUND_BRIGHT   ("\033[0;106m"),
        WHITE_BACKGROUND_BRIGHT  ("\033[0;107m");

        private final String code;

        Color(String code) { this.code = code; }
        @Override public String toString() { return code; }
    }
}

Just dump this code into Logcat.java and compile using:

javac Logcat.java

And run inside the Android Studio's embedded terminal:

java Logcat <your.package.name>

For example:

java Logcat com.nomone.vr_desktop

The result looks like this:

My own Logcat prettifier

It's highly customizable, I've separated most of the options in the first section of the app, so you can tweak the colors and formatting easily. If the adb tool is not in your PATH environment variable, just set its full path in the ADB_FILE_PATH variable (in the code) before compiling.

When the application is running, you can type the following shortcuts:

  • c to clear the screen and local buffer.
  • v, i, d, w, e to change the logcat level.
  • q to quit gracefully. Ctrl+c works too.

Unfortunately, you have to press enter after pressing these keys. Seems like Java doesn't allow single character input from console without writing system specific code. Sorry!

Disclaimer

  • This doesn't work if multiple devices are connected using adb.
  • I haven't thoroughly tested this. I've only used it for a while on a few devices.
  • I haven't tested this on Windows or Mac, but I tried to avoid using anything system specific, so it should still work.

I hope this solves your problem :)

shaedrich
  • 5,457
  • 3
  • 26
  • 42
Raslanove
  • 649
  • 9
  • 16
  • So much work, and so little praise. Here, have an internet point. (Of course, it would be nicer when this was fixed in Android Studio) – Micha Jan 14 '21 at 10:13
6

In my case, in the developer options menu there is an option called

Revoke USB debugging authorisations.

Once you revoke all the existing authorisations it will ask again to trust the computer that you are using after that it started to show the logs again.

Gunhan
  • 6,807
  • 3
  • 43
  • 37
5

In Android 3.6.1 I had to:

  • Upgrade to latest Android Studio version (4.x.x)
  • Restart Logcat
  • Restart the app
  • Restart Android Studio
  • Restart the Android testing device
Pablo Alfonso
  • 2,317
  • 1
  • 18
  • 24
  • Hey, I'm facing the problem since I upgraded recently. I tried the steps given above. Apparently they didn't work for me. Can you help me with this. – Chandu Apr 02 '20 at 12:56
  • 1
    Restarting the android device fixed my problem (e.g. phone, tablet) – Eric May 01 '20 at 18:41
4

This may not be your issue, but I've found that when having multiple windows of Android Studio open, logcat is only directed to one of them, and not necessarily the one that's running an active application.

For example, Window 1 is where I'm developing a Tic-Tac-Toe app, and Window 2 is where I'm developing a weather app. If I run the weather app in debug mode, it's possible only Window 1 will be able to display logcat entries.

Scott
  • 3,663
  • 8
  • 33
  • 56
4

On the right side of tab "Devices logcat" there is the button "Show only Logcat from selected Process". Its not perfect, because everytime I run another process I need to push it again, but thats the only solution that works for me. So far...

user3170595
  • 109
  • 1
  • 1
  • 12
  • Logging wasn't showing up for me because I changed my application ID, and this dropdown was selected to the old one (app: com.example.app). Changing it to "Show only selected application" restored logging. – John D. Jun 17 '15 at 01:42
4

For me, the problem was that the device was connected in the Charge only mode.

Changing the mode to Media device (MTP) (or Transfer files in some devices) solved the problem.

Ícaro
  • 1,432
  • 3
  • 18
  • 36
Android Admirer
  • 2,310
  • 2
  • 17
  • 38
4

Step 1: Connect Your Phone with Android Developer option On and USB Debug On.

Step 2: Go TO View > Tools Window > Logcat

Step 3: Before Run Project Make Sure Your Phone Connect Android Studio. Then run application

Note: If You Can not Show Logcat Just Restart Android Studio : File > Invalid Caches/ restart

Arkerone
  • 1,971
  • 2
  • 22
  • 35
Ashif
  • 441
  • 5
  • 12
3

In Android studio 0.8.0 you should enable ADB integration through Tools -> Android, before run your app. Then the log cat will work correctly. Notice that if you make ADB integration disabled while your app is running and again make it enable, then the log cat dosen't show anything unless you rebuild your project.

Vahid Ghadiri
  • 3,966
  • 7
  • 36
  • 45
3

My problem solved, after I add android:debuggable="true" under application in your AndroiManifest.xml (even the ide mark as a wrong syntax!????)

UmAnusorn
  • 10,420
  • 10
  • 72
  • 100
3

In my case I just had filtered the output so it appeared empty even after restarting Logcat etc.

hariom
  • 121
  • 9
3

I checked the answer and only found my mistake accidentally while checking my logcat. Make sure the box on the right says "Show only selected application". Mine was showing "Firebase", so it showed me messages from Firebase.

enter image description here

2

In Android Studio 0.8.9, I opened Android Device Monitor, selected my emulator from the Devices list and got the output in the LogCat tab.

After that, I went back to the main view of Android Studio and selected Restore Logcat view in the right of the Android DDMS tab and there it was!

If this doesn't work, you could see your logcat in the Android Device Monitor as I explained in the first sentence.

rgc92
  • 125
  • 9
2

Make sure you have enabled the build variant to "debug" in the Build Variants context menu. (You can find this at the bottom left corner of the window). This option will be set to release mode, if you have signed the apk for the application previously. This causes the debug messages not to show in the log cat.

Aruna Tebel
  • 1,436
  • 1
  • 12
  • 24
2

Had the same issue today.

Apparently I had eclipse running too and all the logcat output was redirected to eclipse. Since the logs can only be shown at once place, make sure you dont have multiple debuggers running.

Veeru
  • 4,936
  • 2
  • 43
  • 61
2

Make sure you are importing the right class

import android.util.Log;
Mina Gabriel
  • 23,150
  • 26
  • 96
  • 124
2

I just fixed it on mine. Look for tiny icons on the far right of the DDMS display which restore the Devices Logcat view and the ADB View.

When the DDMS first came up with both the "ADB Logs" and the "Devices | logcat" tab showing. The "Devices | logcat" is the one that should be showing the device output, but was blank. Somehow I managed to hide one or the other of those tabs, I forget exactly how. But, off to the right there was a tiny icon that said "Restore ADB" view, and I clicked it and it came up. Then there was another tiny icon that said "Restore Devices logcat view". I clicked that, and all of a sudden it appeared and was showing the device output again.

Jack BeNimble
  • 35,733
  • 41
  • 130
  • 213
  • It helped me to see `LogCat` during wi-fi debugging. I opened `Device File Explorer`, saw that no authorized devices were in the list and accepted an RSA fingerprint on a smartphone. After that I could see a `Logcat`, but it often breaks and sends these fingerprints again. – CoolMind Dec 20 '18 at 08:54
2

enter image description here

  1. First make Sure developer option is enabled in your device.
  2. Device is connected.
  3. Verbose.
  4. Show Only Selected application.
Sunil
  • 3,404
  • 10
  • 23
  • 31
Vinayak
  • 439
  • 4
  • 10
2

That occasionally occurs to me while using emulator. I just plug in a device and run the app. The Logcat gets back to work and so it does when I get back to the emulator. I guess that just switching two devices and/or emulators does the trick as well.

MGLabs
  • 91
  • 6
2

Also be careful for this bad boy (even with Restart of android studio not disappeared):

enter image description here

Ahad Porkar
  • 1,666
  • 2
  • 33
  • 68
1

Logcat has a little icon to the right of logcat. You can use the icon to turn logcat on and off. I can usually make logcat active by clicking the icon (maybe several times).

VectorVortec
  • 667
  • 7
  • 10
1

Full nuclear solution. ONLY USE THIS AFTER TRYING EVERYTHING ELSE because this will erase all your settings and preferences as well as stored images and everything that makes your emulators run until you reinstall and reconfigure. In my case it took about 20 minutes for both steps because I didn't customise a lot except for using Darcula.

  1. Delete your .AndroidStudioBeta config files directory

For linux users this is found under /home/[username]/.AndroidStudioBeta
For windows users, I'm not sure. The documentation on it is rather vague in my opinion. Probably somewhere under C:\Users[your user]\Application Data

  1. Check to see if it works yet, if it doesn't then also reinstall the SDK.

Rather drastic but I tried all the other things on this page, connected device, no filters, restarting the service, everything on this page and it just didn't work.

G_V
  • 2,396
  • 29
  • 44
1

For me it was not working only for my application, it was working, if no filter has been selected (option on right side). But I needed to see only my app, therefore I found out, that if I do my own filter and filter it to package name, it is working as it should. I hope it could help to you too : )

Michal
  • 2,071
  • 19
  • 30
1

Easy fix that worked for me (after trying some of these other suggestion). My logcat was sitting blank in a separate window (on my second screen). Just had to drag the Logcat tab back to it's original place in the debug panel next to the Debugger and Console tabs, and VOILA... it began immediately updating and showing all processes verbose. So (If your logcat is anywhere outside of the debugger panel (i.e. the logcat tab isn't sitting nested alongside the debugger and console tab) then it won't receive updates and will sit there blankly. Don't know if this is an issue with older versions of Android Studio. But again, easy to try and if it works... it works!!

Jon Day
  • 11
  • 1
1

Try the points mentioned by @Robert Karl in this thread . If nothing works then you can surely see the logs through android device monitor.

  1. Launch the android device monitor

  2. select DDMS perspective ,

  3. then select your device as shown in the screenshot .

    You can apply filter as per your requirements

enter image description here

Community
  • 1
  • 1
lakshay
  • 1,018
  • 2
  • 18
  • 30
1

Go to run->debug If incase you have lose connection with host, it will ask permission to reconnect. Click yes. That should do it.

karthik
  • 7,041
  • 1
  • 13
  • 12
1

I had the same symptoms but my problem was way simpler and really my mistake. I had the wrong filter set.

The solution was just to verify that I had the correct filter set.

xemacobra
  • 1,954
  • 2
  • 21
  • 21
1

I just changed the applictionId and logcat stopped working. To reset it you have to change the package name. Just click on top right corner drop down in Logcat window which show your app package name and click on it and then click Edit Filter Configuration now change the package name. It will start working.

Sunny
  • 14,522
  • 15
  • 84
  • 129
1

Try to click on the icon on the very right part of the "Android" view, you should see Logcat tab on the Android view (you can bring Android view up by pressing Alt+6)

palimad
  • 67
  • 3
1

Logcat can fail if you are using more than 1 version of adb at the same time. One in Android Studio, and one in the terminal.

You might have different version of adb from: "sudo apt-get install android-tools-adb" which will create /usr/bin/adb the Android SDK which contains {android-sdk}/platform-tools/adb, or from the output of an AOSP build which creates out/host/linux-x86/bin/adb

To see if this problem effects you, open idea.log using "Help -> Show Log in Files" and look for a line like "Initializing adb using:/home/repkap11/android-sdk/platform-tools/adb". Compare this path with "which adb" in your terminal. If they don't match, this problem effects you.

Android studio looks for {android-sdk}/platform-tools/adb and doesn't care about your PATH. I replaced the version of adb in android-sdk using a symlink, but simply "sudo apt-get remove android-tools-adb" would work as well.

repkap11
  • 757
  • 7
  • 9
1

Some custom rom's disable logging for performance reasons (squeezing %'s wherever they can) Check your rom's in-built apps or tweak menu of your rom to enable this.

I was running Kushan's Galaxy S4 Rom on my i9505 and I wasn't aware that it had disabled logging by default in order to gain the most minute level of performance increase, but apparently this isn't uncommon on custom built "performance" oriented roms.. Took me an age to discover this - very annoying as it would show me how many messages were logged, just not their detail.

Mullazman
  • 507
  • 5
  • 15
1

I tried the suggestions above. However, none of them worked. I then did the following which surprisingly worked:

  1. Disconnect the USB from the device
  2. Connected the device via Wi-Fi using the commands adb tcpip 5555 and adb connect <device ip>
  3. Disconnected the device from the adb using adb kill-server
  4. Connected the device back via USB

The LogCat then showed the logs. Even though the logs were available at step 2, the following steps resolved the issue for me when connecting via USB.

Syuqri
  • 86
  • 1
  • 6
1

In my case I was sending empty tag i.e

Log.d("","My Log");

Instead send a tag name

Log.d("Class name","My Log");

Hope it helps someone

ABHISHEK G
  • 198
  • 1
  • 10
1

Rebooting the phone I was testing fixed the issue.

I used an old LG4 with Android 6.

I tried unplugging and plugging again, restarting Android Studio, restarting the logcat, invalidating caches - Nothing worked.

Richard Miller
  • 576
  • 1
  • 7
  • 18
1

For me disabling Verify apps over USB and Verify bytecode of debuggable apps helped me to make the logcat much more reliable.

enter image description here

humazed
  • 74,687
  • 32
  • 99
  • 138
0

Nothing from all of this helped, my logcat was disfunctional.

After a lot of angry searching I found a solution that seems to work:
1. Make sure logcat itself is working (use DDMS from Tools->Android) and if it does close DDMS window again
2. Now go to Tab 5 (Debug), there select Logcat (this is not the same logcat as in Window 6!)
3. The window is empty just like Window 6, but now start a debugging run.
For me logcat in the Debug window now started to show all the stuff again!
Also when normally running the application the Debug->logcat view is still functional while the Tool Window #6 "logcat" is disfunctional as before

This is a hack, however it leads to the normal logcat behaviour with highlighted lines and syntax you need for debugging and developing. Just from now on you need to access it through the debug Window.

John
  • 7,507
  • 3
  • 52
  • 52
0

Check if you have hided it...If it is hiding problems the go through given image to display it or ALT + 6enter image description here

Manoj Behera
  • 2,736
  • 22
  • 13
0

To run Logcat, restart the Logcat and then open DDMS(to open it,click on the Android icon in top right corner of Android DDMS. ) and set the Log Level= Debug. And Run your app.

jerry007
  • 1
  • 1
0

I found 3 ways to solve this.

  1. Debug on an Android 4.0 device (I ran it on an android Lollipop device before).
  2. Click the restart button in DDMS.
  3. Launch Android Device Monitor , and you will find log in logcat. Good luck ~
0

In my case it disconnected over the TCP connection, even though the device appeared.

Calling

adb connect <device ip>

Restarted logcat OK.

htafoya
  • 18,261
  • 11
  • 80
  • 104
0

In my case, I tried to solve this with other answers, with no results. I discovered, unintentionally, that empty tags are almost never shown (Android Studio 1.4). So, try to put any letter (blank spaces won't work) inside the TAG.

Log.wtf("x", "Android Studio Team, solve this, please!");
Eduardo Poço
  • 2,819
  • 1
  • 19
  • 27
0

I had a custom ROM on my phone which for some reason did not output logcat, but the emulator and another device did. Wiping and installing the ROM got the logcat working again.

stretch
  • 211
  • 1
  • 2
  • 10
0

Well I've tried all of the other answers and nothing is working for poor logcat. My issue with logcat is that it never worked to begin with. From the time I installed Android studio and finally was able to connect a device to adb it never gave me output. It's probably caused by my borked 32 bit Windows 7 setup though... So I wrote a batch script to run through the terminal to run apps with logcat.

adb shell am start -n "com.package.name/com.package.name.Activity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
adb shell pidof com.package.name > pid
for /f %%i in (pid) do (set pid=%%i)
echo %pid%
adb logcat *:V --pid=%pid%
ENDLOCAL

Put this with corrected directory paths and package names into a logcat.bat(or whatever.bat) file.

place the file in your AndroidStudioProjects/package_name/ folder then you can run

C:\User\me\AndroidStudioProjects\package_name>logcat(or whatever)

in the terminal.

Note that you can change what the logcat displays by changing

*:V

In the adb logcat command. (example *:E shows only (E)rror tags).

I hope this was helpful to someone else.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Finnrir
  • 15
  • 4
0

You may put some text in the search and filter out the Logcat result.
That was the reason for my problem :)

Kurdish Programmer
  • 403
  • 1
  • 4
  • 14
0

In addition to all great answers: make sure that you import right BuildConfig if you use it. I'm using BuildConfig.DEBUG, so one day my IDE automatically imported the wrong class

import com.google.firebase.BuildConfig;

or it may be

import com.adjust.sdk.BuildConfig;

After changing import to the right one everything was fine:

import com.yourapp.BuildConfig;
remain4life
  • 1,201
  • 2
  • 12
  • 11
0

Restart your logcat . It will fixed

Tarif Chakder
  • 1,708
  • 1
  • 11
  • 10
0

For Windows user:

Use this script tool. Make sure you have already set the ADB env for the system. Android Logcat script

  1. Save to bat file
  2. Edit file. Replace com.example.abc with your package id
  3. Double click to open the file or open via MobaXTerm (for easy find the text)

p/s: Let's star my repo if this answer is helpful. Thanks!

Huy Nguyen
  • 1,032
  • 14
  • 38
0

Check for space in the log-tag. If your tag consist of spaces then remove the space and then run. You will be able to view logs.

AMT
  • 136
  • 5
0

Disable and uninstall any plugins that you have recently installed and are not using.

Mahmut K.
  • 707
  • 1
  • 8
  • 20
0

if you use Android Emulator, you can Wipe Data then start the emulator again. only this work for me enter image description here

Jetwiz
  • 642
  • 7
  • 14
0

Make sure you have selected the correct emulator and that field right next to emulator selector is not empty (in the Logcat console).

0

Check the LogCat Sitteng in My case i Uncheck every thing which make issu from me

enter image description here

Again i check everything which works for me

Areeba Qurashi
  • 119
  • 1
  • 8
0

open the terminal and type adb logcat make sure you have one device connected.

0

enter image description here

Upon running adb logcat, I realised that the emulator wouldn't show any logs unless it was the only device connected to Android Studio. I simply unplugged the other connected testing devices and it started running flawlessly.

ibyte
  • 463
  • 4
  • 17