How can I remove my package name from Logcat? - android

My package name is getting in the way of me easily reading my logcat messages. I have to scroll way to the right to see anything. Each line is preceded with:
08-07 00:52:58.237 16332-16332/com.mycompay.mypackage.mypackage/System.out:
How can I get rid of the package name there? And what is the 16332-16332 doing there? Can I get rid of that too?

For Custom Logcat You should read Write and View Logs with Logcat
Every Android log message has a tag and a priority associated with it.
The tag of a system log message is a short string indicating the
system component from which the message originates .
The log message FORMAT is:
date time PID-TID/package priority/tag: message
PID stands for process identifier and TID is thread identifier; they
can be the same if there’s only one thread.

People love visual answers, so I'll duplicate the comment here. I believe it will help you understand this faster.
#Mike Miller:
Check out the section titled "Configuring the logcat Header Display." Just click the settings icon on the left side of logcat

For android studio electric eel and above. Use the following icon to edit the logcat - https://i.stack.imgur.com/L6KBg.png

Related

Android Studio Electric Eel's New Logcat - How do I get only the logs I manually logged?

In the old logcat all I would have to do is type my package name in the search bar.
e.g com.dave.mynewapp
but now when you type in the package name it constantly displays log messages EVERY SINGLE SECOND that I don't need making it hard to debug.
Also now, the cursor doesn't automatically scroll down when a new log appears making it even more frustrating
I am able to filter it by typing the activity name... e.g MainActivity, but it becomes very annoying to type out every single class name that I have logs in.
Is there a way to get all the logs I manually created, but ignore the clutter I have in the picture above?
maybe you can try this :
filter specify the package name package:com.dave.mynewapp
filter specify the Tag tag:MainActivity
filter mutil tags like package:com.dave.mynewapp tag:MainActivity tag:MainActivity2
detail info about this link https://developer.android.com/studio/debug/logcat
I had luck by filtering on: tag:info
var tag = "info"
Log.i(tag, "Names: $names")

TextInputLayout not showing error message after clearing

I am using TextInputLayout from com.android.support:design:23.3.0
When I first apply an error it is shown correctly.
mInputPassword.setError(getString(R.string.error_invalid_password));
mInputEmail.setError(getString(R.string.error_field_required));
On the next login attempt I clear the error.
mInputEmail.setError(null);
mInputPassword.setError(null);
Then I run the validation and set the error again using the same code as above but this time the red line is applied but the error text is missing.
Anyone have any ideas on why this might be happening or have experienced similar situations?
I saw something similar reported here but it is for an older version of the design library and don't know if it is still a issue in the verison I am using,
You simply has to do these steps:
setErrorEnabled(true);
setError("error");
for clearing:
setError(null);
setErrorEnabled(false);
repeat the first step to set a new error. setError(null) clears the error message and icon, so I think the view to show is simply gone and setErrorEnabled(false) will reset it.
You are clearing the Error Message String:
mInputEmail.setError(null);
mInputPassword.setError(null);
So when you rerun the validation, you will get a blank string.
If you want the error message to go away, clear the erroneous text from the textview:
mInputEmail.setText("");
mInputPassword.setText("");

Why shouldn't I use System.out.println() in android

In the Android Open Source Project's code style, it states that we shouldn't use System.out.println() but I don't understand why. Can anyone explain? What should I use to trace my app's log?
Here's the line for reference:
System.out.println() (or printf() for native code) should never be used. System.out and System.err get redirected to /dev/null, so your print statements will have no visible effects. However, all the string building that happens for these calls still gets executed.
You should use the android.util.Log class.
Here's a description of what the Log class does:
API for sending log output.
Generally, you should use the Log.v(), Log.d(), Log.i(), Log.w(), and Log.e() methods to write logs. You can then view the logs in logcat.
The order in terms of verbosity, from least to most is ERROR, WARN, INFO, DEBUG, VERBOSE. Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.
These are the available methods of the Log class:
Log.d() - Send a DEBUG log message.
Log.e() - Send an ERROR log message.
Log.i() - Send an INFO log message.
Log.v() - Send a VERBOSE log message.
Log.w() - Send a WARN log message.
Log.wtf() - What a Terrible Failure: Report an exception that should never happen.
The methods above (with the exception of Log.w and Log.wtf which have 3 possible patterns of arguments) require the following arguments:
String tag, String msg:
tag: Used to identify the source of a log message. This value may be null.
msg: The message you would like logged. This value may be null.
String tag, String msg, Throwable tr - Similar to the first pattern, but allows for an exception to be specified. This pattern should be used if you want to log an exception to the log output.
(For Log.w and Log.wtf) String tag, Throwable tr Similar to the third pattern, but does not allow for a message to be specified. Note that you can still pass a message but it should be in the second arrangement of arguments.
EDIT: Going straight to answer your question: println() of System.out and System.err will still be displayed in logcat but with limitations.
You can't log VERBOSE, ERROR, or DEBUG using System.out or System.err.
You can't define your own tag, it will display System.err or System.out with your text. For instance:
System.out.println("Hello!") is equivalent to Log.i("System.out","Hello!")
System.err.println("Hello!") is equivalent to Log.w("System.err","Hello!")
System.out.println("") in android will not run well because there is no Terminal that the app is corrected to.
You would be better off using Log.(d)(v)(e)(i)(w), because there is something actively monitoring LogCat.
System.out.println() will print to LogCat, but only after an additional set of System instuctions, making it not as efficient, however, as i said, it still works.
if we want to trace the android project
we can do it using Log class
there is some methods like
Log.e(TAG,MESSAGE)
Log.v(TAG,MESSAGE)
Log.w(TAG,MESSAGE)
Log.d(TAG,MESSAGE)
Log.i(TAG,MESSAGE)
its a static method of Utils package. put it line by line and u can watch it in the LogCat..
thats at enjoy with android
From your own link:
System.out.println() (or printf() for native code) should never be
used. System.out and System.err get redirected to /dev/null, so your
print statements will have no visible effects. However, all the string
building that happens for these calls still gets executed.
In addition, at the beginning of that page, it says:
The rules below are not guidelines or recommendations, but strict
rules. Contributions to Android generally will not be accepted if they
do not adhere to these rules.
So DON'T do it!
You can use the built in Log utility that will print right out to the LogCat.
You can use Log.e(String, String) for errors which will appear in red. There is also v, d, i, and w for verbose, debug, info, and warning respectively.
The following should do the trick to print the exception
1. Log.d("myapp", Log.getStackTraceString(new Exception()));
or
2. You can get longer stack traces by digging deeper. For example:
Log.getStackTraceString(e.getCause().getCause());
Log is the best way to trace our android project
like following code...
it will help u...
just look in DDMS logCat that how exactly project is build...
requirement... android.utils.Log; package is used..
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for(int i=0;i
{
Log.e("i = ",""+i);
Log.v("i = ",""+i);
Log.i("i = ",""+i);
Log.w("i = ",""+i);
Log.d("i = ",""+i);
}
}
i hope it will help u

eclipse android logcat showing everything

Sometimes when I'm working with my android projects, and hook up my phone, the logcat in Eclipse starts to report EVERYTHING that's happening on my phone, not just the stuff relative to the project I'm working on. It only does this sometimes though.
How do I stop it from showing everything and just show the things relative to my project?
EDIT:
I forgot to say i already know about filters, sorry. I was just wondering why sometimes eclipses logcat shows everything my phone is doing, while other times it only shows what's relative to the project i'm currently working with when running it on the phone.
I forgot to say i already know about filters, sorry.
Then it is because you have a filter selected and/or eclipse has encountered an error and is just not showing everything it should be.
First Answer
Next to your logcat window should be a Filter window. Create a filter there. Then select the filter by clicking the filter you have made or was put there automatically by eclipse.
You can filter on several things.
Most people will create a static string in their Main Activity/Service containing the application name. Use this static string as your TAG for all of your Logs. Then you can filter on this string you put for the static string.
Also, right clicking in the logcat window will bring up a filter dialog.
You can click on the session filter (left)
Use
Log.d("key","value");
Log.d("key1","value");
Log.d("key2","value");
Log.d("key2","value");
If you want to see only key1 messages ,then go to Logcat
click on add new logcat filter at top left corner(green color + symbol)
then a dialog box will be shown
then a dialog box will be shown, in that write Filter Name ie anyname
and in , by Log Tag write key1 and click on ok button.Now you will see a new filter on left side of your logcat
click on that,you will get only key1 messages
I could fix this by selecting my app in the DDMS-view.
It is important to select the app and not only the device. Latter will only create this useless "(Session-Filter)"
And this happens "sometimes" quite like the author asked for, i think if you change your mobile phone or just disconnect it.
http://developer.android.com/tools/debugging/ddms.html#logcat
You can also setup your own custom filter to specify more details such as filtering messages with the log tags or with the process id that generated the log message. The add filter, edit filter, and delete filter buttons let you manage your custom filters.
Use filters to define what you want to look at.
If you are using Eclipse, when viewing the LogCat view, there is a little green "+" button in the upper right corner. This will allow you to create a filter. Simply give your filter a name and input the TAG it should filter by.
If you are developing with Eclipse creating a log filter is what you are looking for.
If you are using logcat through adb from the command line: Filter LogCat to get only the messages from My Application in Android?

LogCat filtering

Is there a way to quickly filter the logs by PID?
I'm tired of typing in the filter name and PID manually each time.
It seem so straightforward and logical to right-click the message and choose "Filter by id" from the context menu, but LogCat has nothing similar :\ Or has it? Any LogCat alternatives out there?
Wow, take it easy, you just need to input Filter Name and Log Tag being the same text and leave empty the PID. That's enough buddy :)
Sample, I want to filter all tag MyApp, then just create new filter with
Filter Name: MyApp (or whatever)
Log Tag: MyApp (must be exactly)
PID: (leave empty, input nothing)
Type: pick one of the list that suits
:)

Categories

Resources