下面列出了怎么用org.eclipse.core.runtime.ILog的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
protected void append(LoggingEvent event) {
if (isDoLog(event.getLevel())) {
String logString = layout.format(event);
ILog myLog = getLog();
if (myLog != null) {
String loggerName = event.getLoggerName();
int severity = mapLevel(event.getLevel());
final Throwable throwable = event.getThrowableInformation() != null ? event.getThrowableInformation()
.getThrowable() : null;
IStatus status = createStatus(severity, loggerName, logString, throwable);
// Injector injector = N4JSActivator.getInstance().getInjector(N4JSActivator.ORG_ECLIPSE_N4JS_N4JS);
// if (injector != null) {
getLog().log(status);
// }
} else {
// nothing to do (message should be logged to stdout by default appender)
}
}
}
@Override
protected void append(LoggingEvent event) {
if (isDoLog(event.getLevel())) {
String logString = layout.format(event);
ILog myLog = getLog();
if (myLog != null) {
String loggerName = event.getLoggerName();
int severity = mapLevel(event.getLevel());
final Throwable throwable = event.getThrowableInformation() != null ? event.getThrowableInformation()
.getThrowable() : null;
IStatus status = createStatus(severity, loggerName, logString, throwable);
getLog().log(status);
} else {
// nothing to do (message should be logged to stdout by default appender)
}
}
}
private void msg(int msgType, String message, Throwable error) {
int ct = squelchTimeout != 0L ? 0 : counter.incrementAndGet();
boolean printSquelchWarning = false;
if (squelchTimeout != 0L) {
long now = System.currentTimeMillis();
if (squelchTimeout > now) return;
squelchTimeout = now + SQUELCH_TIMEOUT;
printSquelchWarning = true;
} else if (ct >= MAX_LOG) {
squelchTimeout = System.currentTimeMillis() + SQUELCH_TIMEOUT;
printSquelchWarning = true;
}
ILog log = Platform.getLog(bundle);
log.log(new Status(msgType, DEFAULT_BUNDLE_NAME, message, error));
if (printSquelchWarning) {
log.log(new Status(IStatus.WARNING, DEFAULT_BUNDLE_NAME, "Lombok has logged too many messages; to avoid memory issues, further lombok logs will be squelched for a while. Restart eclipse to start over."));
}
}
@Override
public void presentUpdateDetails(Shell shell, String updateSiteUrl, ILog log,
String pluginId) {
try {
InstallUpdateHandler.launch(updateSiteUrl);
} catch (Throwable t) {
// Log, and fallback on dialog
log.log(new Status(IStatus.WARNING, pluginId,
"Could not open install wizard", t));
MessageDialog.openInformation(
shell,
DEFAULT_DIALOG_TITLE,
"An update is available for the GWT Plugin for Eclipse. Go to \"Help > Install New Software\" to install it.");
}
}
/**
* Defines the standard procedure to handle <code>CoreExceptions</code>.
* Exceptions are written to the plug-in log.
*
* @param exception
* the exception to be logged
* @param message
* the message to be logged
*/
protected void handleCoreException( CoreException exception, String message )
{
Bundle bundle = Platform.getBundle( PlatformUI.PLUGIN_ID );
ILog log = Platform.getLog( bundle );
if ( message != null )
log.log( new Status( IStatus.ERROR,
PlatformUI.PLUGIN_ID,
0,
message,
exception ) );
else
log.log( exception.getStatus( ) );
}
@Override
protected void setUp() throws Exception {
ref = mock(IResourceTaskReference.class);
ilog = mock(ILog.class);
prefs = mock(IMechanicPreferences.class);
log = new MechanicLog(ilog);
super.setUp();
}
PlatformHolder(ILog log) {
this.log = log;
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
for (final IProject project : workspace.getRoot().getProjects()) {
if (Platform.isPlatformProject(project)) {
platformProjectAdded(project);
}
}
addResourceChangeListenerToWorkspace();
}
protected void validateState(final IEditorInput input) {
final IDocumentProvider provider = getDocumentProvider();
if (!(provider instanceof IDocumentProviderExtension))
return;
final IDocumentProviderExtension extension = (IDocumentProviderExtension) provider;
try {
extension.validateState(input, getSite().getShell());
} catch (final CoreException x) {
final IStatus status = x.getStatus();
if (status == null || status.getSeverity() != IStatus.CANCEL) {
final Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
final ILog log = Platform.getLog(bundle);
log.log(x.getStatus());
final Shell shell = getSite().getShell();
final String title = "EditorMessages.Editor_error_validateEdit_title";
final String msg = "EditorMessages.Editor_error_validateEdit_message";
ErrorDialog.openError(shell, title, msg, x.getStatus());
}
return;
}
if (fSourceViewer != null)
fSourceViewer.setEditable(isEditable());
}
/** Replies the Eclipse logger to be used.
*
* @return the logger.
*/
protected synchronized ILog getEclipseLogger() {
if (this.eclipseLogger == null) {
this.eclipseLogger = InternalPlatform.getDefault().getLog(getBundle());
}
return this.eclipseLogger;
}
@Before
public void setUp() {
this.old = Debug.out;
Debug.out = mock(PrintStream.class);
this.logger = mock(ILog.class);
// Cannot create a "spyied" version of getILog() since it
// will be directly called by the underlying implementation.
// For providing a mock for the ILog, only subclassing is working.
this.plugin = new SARLMavenEclipsePlugin() {
public ILog getILog() {
return logger;
}
};
SARLMavenEclipsePlugin.setDefault(this.plugin);
}
@Before
public void setUp() {
this.old = Debug.out;
Debug.out = mock(PrintStream.class);
this.logger = mock(ILog.class);
// Cannot create a "spyied" version of getILog() since it
// will be directly called by the underlying implementation.
// For providing a mock for the ILog, only subclassing is working.
this.plugin = new SARLEclipsePlugin() {
public ILog getILog() {
return logger;
}
};
SARLEclipsePlugin.setDefault(this.plugin);
}
@Override
public void newError(int severity, String message, Exception exception) {
String pluginId = JgPlugin.getUniqueIdentifier();
ILog log = JgPlugin.getDefault().getLog();
log.log(new Status(logLevels[severity], pluginId, IStatus.OK, message, exception));
if (IError.WARN < severity)
throw new ErrorExit();
}
protected void validateState(IEditorInput input) {
IDocumentProvider provider = getDocumentProvider();
if (!(provider instanceof IDocumentProviderExtension))
return;
IDocumentProviderExtension extension = (IDocumentProviderExtension) provider;
try {
extension.validateState(input, getSite().getShell());
} catch (CoreException x) {
IStatus status = x.getStatus();
if (status == null || status.getSeverity() != IStatus.CANCEL) {
Bundle bundle = Platform.getBundle(PlatformUI.PLUGIN_ID);
ILog log = Platform.getLog(bundle);
log.log(x.getStatus());
Shell shell = getSite().getShell();
String title = "EditorMessages.Editor_error_validateEdit_title";
String msg = "EditorMessages.Editor_error_validateEdit_message";
ErrorDialog.openError(shell, title, msg, x.getStatus());
}
return;
}
if (fSourceViewer != null)
fSourceViewer.setEditable(isEditable());
}
private ILog getLog() {
ensureInitialized();
return log;
}
public GeneratorLocator ( final BundleContext context, final ILog log )
{
this.context = context;
this.log = log;
}
public MechanicLog(ILog log) {
this.log = Preconditions.checkNotNull(log);
}
private ILog getLog() {
ensureInitialized();
return log;
}
public LoggerImpl(ILog log, String pluginId) {
this.log = log;
this.pluginId = pluginId;
}
private static String getBundleSymbolicName(ILog log) {
return log.getBundle().getSymbolicName();
}
void presentUpdateDetails(Shell shell, String updateSiteUrl, ILog log,
String pluginId);
public static ILog getLog() {
return LOG;
}
@Override
public void logStatus(StatusException se) {
int severity = EclipseUtils.toEclipseSeverity(se);
ILog log = LangCorePlugin.getInstance().getLog();
log.log(EclipseCore.createStatus(severity, se.getMessage(), se.getCause()));
}
public ILog getLogger(){
return Platform.getLog(Platform.getBundle(Activator.PLUGIN_ID));
}
/**
* Log the specified error.
*
* @param message a human-readable message, localized to the current locale.
*/
public static void logError(ILog log, String message) {
logError(log, null, message);
}
/**
* Log the specified error.
*
* @param message a human-readable message, localized to the current locale.
* @param args message arguments.
*/
public static void logError(ILog log, String message, Object... args) {
logError(log, null, message, args);
}
/**
* Log the specified error.
*
* @param exception a low-level exception.
*/
public static void logError(ILog log, Throwable exception) {
logError(log, exception, "Unexpected Exception");
}
/**
* Log the specified error.
*
* @param exception a low-level exception, or <code>null</code> if not
* applicable.
* @param message a human-readable message, localized to the current locale.
*/
public static void logError(ILog log, Throwable exception, String message) {
log(log, IStatus.ERROR, IStatus.OK, message, exception);
}
/**
* Log the specified error.
*
* @param exception a low-level exception, or <code>null</code> if not
* applicable.
* @param message a human-readable message, localized to the current locale.
* @param args message arguments.
*/
public static void logError(ILog log, Throwable exception, String message,
Object... args) {
message = MessageFormat.format(message, args);
log(log, IStatus.ERROR, IStatus.OK, message, exception);
}
/**
* Log the specified information.
*
* @param message a human-readable message, localized to the current locale.
*/
public static void logInfo(ILog log, String message) {
logInfo(log, message, new Object[0]);
}
/**
* Log the specified information.
*
* @param message a human-readable message, localized to the current locale.
* @param args message arguments.
*/
public static void logInfo(ILog log, String message, Object... args) {
message = MessageFormat.format(message, args);
log(log, IStatus.INFO, IStatus.OK, message, null);
}