Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update of the FAQ Log entry #1623

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions docs/FAQ/FAQ_How_do_I_use_the_platform_logging_facility.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@


FAQ How do I use the platform logging facility?
===============================================

The Eclipse runtime plug-in provides a simple set of APIs for logging exceptions, warnings, or other information useful in debugging or servicing a deployed Eclipse product. The intent of the log is to record information that can be used later to diagnose problems in the field. Because this information is not directed at users, you do not need to worry about translating messages or simplifying explanations into a form that users will understand. The idea is that when things go wrong in the field, your users can send you the log file to help you figure out what happened.
The Eclipse ILog class provides a simple set of APIs for logging exceptions, warnings, or other information useful in debugging or servicing a deployed Eclipse product.
The intent of the log is to record information that can be used later to diagnose problems in the field.
Because this information is not directed at users, you do not need to worry about translating messages or simplifying explanations into a form that users will understand.
The idea is that when things go wrong in the field, your users can send you the log file to help you figure out what happened.

Each plug-in has its own log associated with it, but all logged information eventually makes its way into the platform log file (see the getLogFileLocation method on Platform).

You can write any kind of IStatus object to the log file, including a MultiStatus if you have hierarchies of information to display. If you create your own subclass of the utility class Status, you can override the getMessage method to return extra information to be displayed in the log file. Many plug-ins add utility classes for writing messages and errors to the log:

import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.ILog;
...
public class MyLogger {
...
private static final Bundle BUNDLE = FrameworkUtil.getBundle(MyLogger.class);
private static final ILog LOGGER = Platform.getLog(BUNDLE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line still necessary?
At least while viewing this on the phone I can't see a reference.



...
public static void test(){
ILog.get().info("Starting");
try {
log("Eclipse Style Logging");
}
catch(Exception e){
log("Oops!", e);
// do something that may cause an exception
}
catch (Exception e){
ILog.get().error("Generating template failed!", e);
}
ILog.get().warn("Creating a warning..");
}

public static void log(String msg) {
log(msg, null);
}

public static void log(String msg, Exception e) {
LOGGER.log(new Status((e==null?Status.INFO:Status.ERROR), BUNDLE.getSymbolicName(), msg, e));
}

During development, you can browse and manipulate the platform log file using the Error Log view (**Window > Show View > General > Error Log**). You can also have the log file mirrored in the Java console by starting Eclipse with the -consoleLog command-line argument.
During development, you can browse and manipulate the platform log file using the Error Log view (**Window > Show View > General > Error Log**).
You can also have the log file mirrored in the Java console by starting Eclipse with the -consoleLog command-line argument.

eclipse -vm c:\\jre\\bin\\java.exe -consoleLog

We explicitly pass the VM because on Windows you have to use java.exe instead of javaw.exe if you want the Java console window to appear.

You can also write any kind of IStatus object to the log file, including a MultiStatus if you have hierarchies of information to display.
If you create your own subclass of the utility class Status, you can override the getMessage method to return extra information to be displayed in the log file.



See Also:
---------

Expand Down
Loading