How to get logs from Android

Via command line

Use Logcat command-line tool on your computer

Logcat is a command-line tool that dumps a log of system messages, including stack traces when the device throws an error and messages that you have written from your app with the Log class.
in Logcat command-line tool  |  Android Developers

For that you will need to have Android Debug Bridge (adb) installed on your computer. There a couple of different ways to installed it: Using the standalone package (documented here) but you can also use the sdk-manager or if you already have installed the Android Studio.

  1. Use the standalone Android SDK Platform-Tools package, you can download it here. You can then extract it to a place where your computer recognizes it.
    • Example, on Linux: Extract the package file to your /home/<youruserNameHere>/.local/bin/platform-tools or /home/<youruserNameHere>/bin/platform-tools
    • Then make sure that folder is correctly added to your system PATH variable with export: by adding the following line to your .bashrc
      export PATH=$PATH:/home/<youruserNameHere>/.local/bin/platform-tools
      
    • Close and open your terminal or re-evaluate your .bashrc file with source .bashrc
  2. You can now use logcat to view the messages in real time
    adb logcat
    
    • It will probably output the following:
    * daemon not running; starting now at tcp:5037
    * daemon started successfully
    - waiting for device -
    
  3. To collect logs using ADB, use the following command. This command will export a continuous log, so use Ctrl + C to stop it.
    adb logcat > logcat.txt
    
  4. You can now plug in your phone. For more info on the correct syntax see logcat#Syntax

With Android studio

The Android studio also allows you to view log messages right inside of the Android studio > logcat window.

With an application

There is also the possibility to export those log messages from within your Android phone without resorting to command-line nor Android studio: https://www.xda-developers.com/how-to-take-logs-android/