Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you usually Tag log entries? (android)

I assume most of you are aware of android.util.Log All logging methods accept 'String tag' as a first argument.

And my question is How do you usually tag your logs in your applications? I've seen some hardcode like this:

public class MyActivity extends Activity {     private static final String TAG = "MyActivity";     //...     public void method () {         //...         Log.d(TAG, "Some logging");     } } 

This doesn't look nice because of many reasons:

  • You can tell me this code doesn't have hardcode, but it does.
  • My application could have any number of classes in different packages with the same name. So it would be hard to read the log.
  • It isn't flexible. You always have put a private field TAG into your class.

Is there any neat way to get a TAG for a class?

like image 581
andrii Avatar asked Dec 02 '11 11:12

andrii


People also ask

What is tag in log?

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 (for example, ActivityManager ).

Where do Android logs go?

To access the logging output, run the 'adb' executable with following arguments to capture the Android Enterprise related logging: Windows: C:\Users\[username]\AppData\Local\Android\sdk\platform-tools> adb logcat -G 32M; adb shell setprop persist. log. tag.


1 Answers

I use a TAG, but I initialise it like this:

private static final String TAG = MyActivity.class.getName(); 

This way when I refactor my code the tag will also change accordingly.

like image 58
gianpi Avatar answered Oct 07 '22 16:10

gianpi