Dave's Brain

Browse - Programming Tips - How can I avoid hardcoding log tags?

Date: 2013feb28
Platform: Android
Language: Java
Keywords: LOG_TAG, reflection

Q.  How can I avoid hardcoding log tags?

A.

class MyClass { // Make a tag without hardcoding static final String tag = this.getClass().getSimpleName(); MyFunction() { // Use it Log.i(tag, "Stuff"); } }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.