Android Studio: Logcat vs Run - android

What's the difference between Logcat and Run in Android-Studio?
Logcat has filter-options. Beside that I don't get which specific purpose each serve.
In how far do the messages differ, which become printed to each console?
When do I use which console?

Personally,Logcat is more useful for debugging and being aware of what is going on while the app is running. You set the type of the log and set tags to them, by this way you can easily filter logs. This gives you much more clear picture in terms of logging.it stated in this article
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.
Also, it is stated that (in the same article)
The priority is one of the following character values, ordered from lowest to highest priority:
V: Verbose (lowest priority)
D: Debug
I: Info
W: Warning
E: Error
F: Fatal
S: Silent (highest priority, on which nothing is ever printed)
each one of these shows the logs from their priority to highest one . Verbose, for instance, will print all the logs but if you switch to error , logcat only shows error and fatal logs.
Additionally, if you set a tag filter it will only shows the logs that is tagged with that "tag", of course while keeping the priority filter. For instance
Log.e("tag1","message_1");
Log.e("tag2","message_2");
Assume you have filter the tags with "tag1". The logcat will print "message_1".
Similarly
Log.e("tag1","message_1");
Log.i("tag1","message_2");
Again, assume that you have filter tags by "tag1" and priorities with Error.Then, the logcat will show only "message_1".
For the run tool also shows logs , prints (println etc.) but in comparison with the logcat it will show a lot more stuff (logs, prints (println etc. and phone related informations).
apart from your logs other logs that comes from libraries and phone itself also are shown in the run tool. So it hard to find your own logs.
Run will be useful when the phone and library related information logs needed.(for instance when the phone misses/drop frames it will be printed in run)
Logcat will be useful for your own logs.When you are trying to understand what is going on while the app runs etc..

I have noticed a big difference between the run and the logcat while using avd emulators. I had a deceiving crash on my app, only while I was using the emulators .
every time there was a crash , the logs before the crash were disappearing from the logcat , and I couldn't understand if I see the logs related to the crash. after a week of trying to find a library that prints the logs to a file I found out that everything is printed in the run tab, so I don't need that.

Related

Android : How to enable logging Log.v values which are by default disabled

I am a novice to the Android Studio and working on one group project.I am trying to log some variable values to logging.
When I use Log.e values are properly logged. While when I use Log.w or Log.v nothing gets printed. Here I am switching from logcat from error to verbose and to warning as I am using Log but still can't see anything printed.I previously used Toast but heard that using it might make my app slow and using Log.e everywhere is not a good practice.So how to print logs of lower priority?
I tried referring following resources but didn't find anything that could help me enabling logging for lower priority Logs, Just got the info that for some reason lower priority logs are disabled.
https://developer.android.com/reference/android/util/Log.html
Android Log.v(), Log.d(), Log.i(), Log.w(), Log.e() - When to use each one?
Thank you in advance.
All logs are always default enabled.
I think you are viewing logs in error view.
Check
You are viewing logs in Verbose
Your filter is set to selected app.
You have selected your app not other app. (where in below image no debuggable process is written)
Android Log.v(), Log.d(), Log.i(), Log.w(), Log.e() - When to use each one?
Log.e: This is for when bad stuff happens. Use this tag in places like inside a catch statement. You know that an error has occurred and therefore you're logging an error.
Log.w: Use this when you suspect something shady is going on. You may not be completely in full on error mode, but maybe you recovered from some unexpected behavior. Basically, use this to log stuff you didn't expect to happen but isn't necessarily an error. Kind of like a "hey, this happened, and it's weird, we should look into it."
Log.i: Use this to post useful information to the log. For example: that you have successfully connected to a server. Basically use it to report successes.
Log.d: Use this for debugging purposes. If you want to print out a bunch of messages so you can log the exact flow of your program, use this. If you want to keep a log of variable values, use this.
Log.v: Use this when you want to go absolutely nuts with your logging. If for some reason you've decided to log every little thing in a particular part of your app, use the Log.v tag.
Explanation by link Kurtis Nusbaum
Update:
If above things does not work then you are facing an device setting issue. Some mobiles have set default log level to DEBUG or ERROR. Allow logging from phone setting.
You can check if log is loggable by Log.isLoggable()
Check
Settings -> Accessibility -> Developer options -> advanced logging->set "Allow all"
or
Settings->Accessibility - > Developer Options -> Performance optimization -> Advanced logging -> set "Allow all"
or for other phone search in "developers options": option "logging" and set "all".
also you can use Log.wtf when your Log.d is not working.
try restarting android studio also

Android Studio 3.0 Logcat continuously showing messages and does not stop

When I start debugging my App in Android Studio 3.0 and open the Logcat, it displays so many messages and warnings, but the problem is, it never stops, even when the debugging is completed and the App is terminated, it still prints so many messages continuously.
Can anybody help???
Since you are not debugging or running any application on the device you have connected. Hence, the logcat is displaying the logs generated by all the apps in the device as well as the system logs. Which makes the log cat window go nuts.
What you can do is.
On the top right corner of the log cat window, there is a filter config combo box. Select or create a filter of your own to filter out relevant logs.
The filter could be created using any details, it could be a process ID (PID), the tag name e.g I/ActivityManager: where I stands for Info, V for Verbose, D for Debug and so on.
You can add filter in your Logcat, and mention all the classes whose logs you want to discard.
In the field LogTag (shown in the pic) define a regex like this ^(?!Class A | Class B|#). Here Class A and Class B are the classes whose logs you don't want to see.That's it.
If you see no debuggable application then change it to your app name. If that wont help change the log level to error. Last thing you can try is to filter the results. Good luck!

Logcat is being "spammed", resulting in "Too much output to process"

Whenever I connect my Samsung Galaxy S5 (running Android 4.4.2) to my computer, the Logcat in Android Studio starts being "spammed" by the same message multiple times ~1600 times per second, resulting in the message "Too much output to process" appearing in a yellow box in Logcat. This is when there is no filtering and no debug process selected.
The Logcat message is this:
D/tms_audio_hw/AudioTmsIpc AudioTmsClientListen accept Done gAudioClientAcceptSockFd -1 gAudioClientLocalSockFd 24
Googling it reveals surprisingly little. Actually nothing. I'm not sure, but it seems to be affecting the logging from my application as well, because when I select my application as the debug process, I don't get all the Logcat outputs from my application - sometimes I'll get some, sometimes I'll get others, sometimes I'll get none.
Also, because of this my computer starts using CPU like crazy just to process those messages, resulting in extreme CPU usage and fans at full blast!
What the heck is causing this?
EDIT
I have now looked at exactly how fast these logs are coming in, and it's at a rate of 1600 logs per second, and it's just this same message over and over and over. Don't tell me this is "normal behaviour" unless you are experiencing this on your own devices.
You may have selected "No Filters" in android monitor which causes "Too much output to process error", Change it to "Show only selected Application" then all other Log line are filtered and will not show in Logcat.
Here is snapshot of Android Monitor.
I had a similar problem while testing an app. Initially the log messages displayed as expected and then it started to display my log messages "at random", i.e. showing and then not showing.
Removing the Logcat filter showed the "too much output to process" message. I also noticed that the log was displaying messages relating to apps installed on my phone (I was using a phone to test my app) and had nothing to do with my app.
I disconnected the phone from my laptop, restarted the phone and then re-connected it back to the laptop and ran the app. The Logcat was back to normal, showing the log messages as expected.
That is normal behaviour; it is not related to a particular phone model or Android OS version. When you remove all filters, there's just too much logging output being redirected from everything that can and does log, including system components and various libraries that are loaded at that time.
The recommended default approach is to simply filter out and view only your application's log output and switch to no filtering only when you are specifically debugging something where you need to know what else is happening around that part of code.

Logcat output of my app vanished from logcat output

i have a problem with logcat output of my app:
Normally logging to logcat works. But at some times my app's output seems to be entirely removed from the logcat output. Though i can prove that the app logged, there is not a single line in logcat.
When does this happen:
I shedule my app to wakeup at midnight by a BroadcastReceiver starting a Service. The app wakes up and creates a logfile, writes to that file and to logcat in parallel by calling a function which writes to both. The logfile contains 3 lines written. (and then the app somehow dies.) At least these 3 lines have been also logged to logcat.
Next day i display all logcat messages, which encloses midnight. Not a single line logged for my app.
I think Android has purged my App from memory and at midnight it is loaded again (and crashes because it is not initialized properly). But why is there no logcat output?
thanks for your hint.
Logcat has a size limit. Once this limit is reached, older messages are purged to make room for the new ones coming in. It's not that Logcat is removing your app's messages specifically, it's that in the course of running over night there are so many other messages going to Logcat that yours are being removed.
To see the buffer size on your specific device, plug it in and execute the following command in a shell window:
adb logcat -g
If you need to collect log messages at a time where you can't physically be looking at the output window, you're doing the right thing by logging to a file. I do something similar where I'll set a global flag on the build that tells it whether to log normally or output to a local file on my phone.

Is there any way to view the log messages from our own application in android?

I have developed an Android application that performs some network activity. Inside the classes I have implemented the log messages like verbose, debug, info, warn and error. But when I open logcat with argument -d its listing the entire log messages from the device. So its difficult to trace the log messages of my application. Is there any way to filter the log messages of my application from the entire logcat output?
Every Android log message has a tag and a priority associated with it:
The tag of a log message is a short string indicating the system
component from which the message originates (for example, "View"
for the view system).
The priority is one of the following character values, ordered
from lowest to highest priority:
V — Verbose (lowest priority)
D — Debug
I — Info
W — Warning
E — Error
F — Fatal
S — Silent (highest priority, on which nothing is ever printed)
Here's how to do it:
adb logcat ActivityManager:I MyApp:D *:S
This will make logs with the tag ActivityManager show up if they have an "Info" level priority or above (Warning, Error, Fatal). The same applies to messages with the tag MyApp and a priority of Debug or above. *:S makes all other messages be silent.
Check this out in the documentation: http://developer.android.com/guide/developing/tools/adb.html#logcat
Further tips
I suggest you to keep all other logs to Error or Warning level (*:W). Sometimes you get a problem in your application due some system event or third party application and you do want to be notified of these events!
You might want to change the output format of logcat. Play around with these settings (information in the same link above)
You might want to check out Coloured output for logcat. I've done some modifications to this script to suit better my needs so maybe you could adjust it too. (I tried to send my modifications to the author but he didn't reply).
Logcat has a small + button that lets you create a filter. Use the TAG you used in your app and specify it in the filter. That creates a new tab that shows only your apps messages.
While you're at it, I recommend creating a filter for the AndroidRuntime tag. All your exceptions get dumped in there and you can find them very easy.
Of course you can filter these messages more by category (verbose, warn, error, ..) by using the buttons in the same bar.

Categories

Resources