To add a log frame for the Eclipse plug-in

Source: Internet
Author: User
Tags log4j

Two ways to enhance eclipse log functionality

Why should I use a log?

Good developers know the importance of careful design, testing, and debugging. While Eclipse can help developers implement these tasks, how does it process logs? Many developers believe that logging is an integral part of good software development practices. If you've ever fixed a program that someone else has deployed, you'll certainly agree. Fortunately, the log has little impact on performance, and in most cases does not even have any impact on performance, and the learning curve is very smooth because the log tools are simple and easy to use. Therefore, there is no reason why you should not add log functionality to your application for the best available tools.

Tools that you can use

If you are writing an Eclipse plug-in, you can use the services provided by Org.eclipse.core.runtime.ILog, which can be accessed through the GetLog () method of the Plug class. Just use the correct information to create an Org.eclipse.core.runtime.Status instance and call the ILog log () method.

This log object can receive multiple log listener instances. Eclipse has added two listeners:

One listener writes to the log in the error log view.

A listener writes a log to a log file that is located in "${workspace}/.metadata/.log".

You can also create your own log listener by simply implementing the Org.eclipse.core.runtime.ILogListener interface and adding it to the Log object using the Addloglistener () method. In this way, each log event can invoke the logging () method of the class.

Although all the content is very simple, there are some problems with this approach. If you want to modify a deployed plug-in target, what should be done? Or how do you control the amount of log information that is logged? Also, this implementation can have an impact on performance because it always sends log events to all listeners. That's why we usually see logging in extreme situations, such as error conditions.

On the other hand, there are two outstanding tools dedicated to logging. A java.util.logging package from Java 2 SDK 1.4, and another from Apache, named Log4j.

Both tools employ the concept of a hierarchy of log objects that can send log events to any number of handlers (Handler, called Appender in log4j), which represent the sending of a formatter (Formatter, called in log4j Layout) to format the message. Both of these tools can be configured through a property file. Log4j can also be configured using an XML file.

A logger can have a name and be associated with a level. Loggers can inherit parental settings (levels, handlers). The logger named "org" automatically becomes the parent of another logger named "Org.eclipse", so that regardless of how you set up "org" in the configuration file, these settings can be inherited by the "org.eclipse" logger.

Which tool do I like better? I have used both of these tools, but I prefer log4j. I use java.util.logging only in very simple programs, and I don't want to add Log4j.jar to such a program. For a detailed description of these two tools, see the Java documentation and the Apache site.

An improved log

Wouldn't it be great if there was a way to improve the Eclipse log experience? But there are two problems with this:

The external configuration file is missing.

Performance problems, as well as the lack of fine-grained control over log behavior.

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.