How to display plug-in logs in the error log of eclipse

Source: Internet
Author: User
Tags throwable

Exception and log have to be processed when developing any software, as does Eclipse plug-in. Fortunately, the eclipse PVDF provides a mechanism to record and display exceptions and logs: Error Log view. As part of the eclipse SDK, the penetration rate of PDIS very high, so unless you are doing RCP, you can use error log view to handle exception
And log should be your best choice. Of course, this also brings about the dependence on PDE.

Using error log view is actually very simple. Each plug-in activator class has a getlog () method, which returns an ilog object, this object records the exception and log to the error log view. The main method for ilog objects is log. As the name suggests, it receives an istatus-type object and records its status. Eclipse and many common plug-ins (such as jdt) implement many istatus, and the most common is the status class. We can simply use it or create our own
Istatus implementation. The status constructor has five parameters:

 

In this way, we can write a logutil class to take charge of log work,CodeAs follows:

 

Package demo; import Org. eclipse. core. runtime. ilog; import Org. eclipse. core. runtime. status; import XXX. pluginactivator; public class eclipseerrorlog {Private Static ilog logger = NULL; static {logger = pluginactivator. getdefault (). getlog ();} private eclipseerrorlog () {// nothing to do} public static void logcancel (string message, throwable exception) {logger. log (new status (status. cancel, pluginactivator. plugin_id, status. OK, message, exception);} public static void logerror (string message, throwable exception) {logger. log (new status (status. error, pluginactivator. plugin_id, status. OK, message, exception);} public static void loginfo (string message, throwable exception) {logger. log (new status (status. info, pluginactivator. plugin_id, status. OK, message, exception);} public static void logok (string message, throwable exception) {logger. log (new status (status. OK, pluginactivator. plugin_id, status. OK, message, exception);} public static void logwarning (string message, throwable exception) {logger. log (new status (status. warning, pluginactivator. plugin_id, status. OK, message, exception ));}}

 

In addition, you can use the addloglistener method of ilog and the removeloglistener method to add and delete event listeners for log actions. These listener can help us do some additional things after logging is complete. For example, if the log is recorded at the error level, an alert dialog box may pop up to tell the user that an error has occurred. However, if the log is at the info level, this is unnecessary.

 

 

Note:

This article Reprinted from: http://hintcnuie.javaeye.com/blog/787932

    • int severity: log level, which can be OK, error, info, warning, or cancel. These constants are defined in the status class.
    • string pluginid: ID of the current plug-in.
    • int code: Status Code specified by plug-in. Generally, status. OK is used if this parameter is not required.
    • string message: log information.
    • throwable exception: exception of the record. If no exception exists, null is input.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.