In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use JDK log in Android". The explanation in this article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use JDK log in Android".
1. Inherit the Handler abstract class
2. Implement publish,flush and close methods. Where the publish method is used to publish a log record. The flush method is to clear the memory buffer. The close method releases the resources requested by the Handler class (such as files, socket, etc.) when the application is closed.
3. Set the default Formatter,Filter and Level objects. If necessary, you can read the configuration file to set these parameters when the class is initialized.
Public class MyFormatter extends Formatter {private final String lineSeparator = System.getProperty ("line.separator"); @ Override public String format (LogRecord record) {StringBuffer sb = new StringBuffer (); String message = formatMessage (record); sb.append (record.getLevel (). GetLocalizedName ()); sb.append (message); sb.append (lineSeparator); if (record.getThrown ()! = null) {try {StringWriter sw = new StringWriter (); PrintWriter pw = new PrintWriter (sw) Record.getThrown (). PrintStackTrace (pw); pw.close (); sb.append (sw.toString ());} catch (Exception ex) {}} return sb.toString ();}}
Here the reportError method outputs the error information in the log class to the outside world, and the ErrorManager class implemented by the ErrorManager class is responsible for recording the errors of Handler in the logging framework. Typically, the error is printed to the console.
Each specific log message is encapsulated into a LogRecord object by the Android JDK logging framework, which is partially defined as shown in the listing. As you can see from the listing, the LogRecord class contains information about the level of a log message, message text, time, parameters, threads, and so on, which are handled by objects such as Handler,Formatter and Filter. At the same time, the class is serializable and can be serialized to the network and files. This class can also be bound to a ResourceBundle object to localize the message string. Describes the implementation of a typical custom Handler class.
Thank you for reading, the above is the content of "how to use JDK log in Android". After the study of this article, I believe you have a deeper understanding of how to use JDK log in Android, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.