In the process of program development, log is a widely used mechanism for documenting program execution, which can be used for both program debugging and event logging in product operations. The Android system provides a simple, convenient log mechanism that developers can easily use. This article briefly describes the use of log in Android and the change in the log color in Android Studio.
To use log, we need to import Android.util.Log first, where log is commonly used in 5 ways:log.v () log.d ( ) log.i () LOG.W ( ) and log.e () . According to the initial letter corresponds to VERBOSE,DEBUG,information,WARNING,ERROR. Among them:
1, log.v debugging color is black , any message will be output.
2, the output color of the LOG.D is blue , only output debug debugging meaning, but he will output the upper level of information.
3, LOG.I output is green , general informational message information, it will not output LOG.V and LOG.D information, but will display I, W and e information.
4, log.w the meaning of Orange , can be seen as a warning warning, we generally need to pay attention to optimize the Android code, while selecting it will also output LOG.E information.
5, LOG.E is red, you can think of error errors, here only the red error message, these errors need our careful analysis, view the stack of information.
We create a new button, and then the Click event is set to:
LOG.V ("Mainactivity", "This is Verbose."); LOG.D ("Mainactivity", "This is Debug."); LOG.I ("Mainactivity", "This is Information"); LOG.W ("Mainactivity", "This is Warning."); LOG.E ("Mainactivity", "This is Error.");
At this point, when we click the button, the log message is displayed in Android/logcat:
However, we found that the log information may be white and red on your computer. So how to change the color of log information?
- File->settings or CTRL + ALT +s
- Find Android Logcat, editor-and Colors &fonts, or enter Logcat in the search box above
- Click Verbose, Info, debug options, and then use inberited attributes to remove the tick
- Then select the check box in front of the Foreground, you can double-click the back to choose the color
- Apply–>ok
We can change the log color into the next, we can get the log effect shown.
Log |
Color value |
VERBOSE |
bbbbbb |
DEBUG |
0070BB |
Infomation |
48bb31 |
WARNING |
BBBB23 |
ERROR |
FF0006 |
Assert |
8f0005 |
This will give you the above effect.
The complete code is as follows:
Import Android.app.activity;import android.os.bundle;import Android.util.log;import Android.view.view;import Android.widget.button;public class Mainactivity extends Activity {private button button; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Button = (button) Findviewbyid (R.id.button); Button.setonclicklistener (New View.onclicklistener () {@Override public void OnClick (View v) { LOG.V ("Mainactivity", "This is Verbose."); LOG.D ("Mainactivity", "This is Debug."); LOG.I ("Mainactivity", "This is Information"); LOG.W ("Mainactivity", "This is Warning."); LOG.E ("Mainactivity", "This is Error."); } }); }}
The use and color changes of log for Android development