blob: c30ddf6153ba9ab65a2e89b6c1c1e59558e16e56 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2020 RBEI and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v. 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Adhith Gopal - Initial API and Implementation
* Santhosh Gokhale D
*******************************************************************************/
package org.eclipse.blockchain.core;
import java.util.StringJoiner;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
/**
* Plugin Activator
*/
public class BlockchainCore extends Plugin {
private static BlockchainCore instance;
/**
* Plugin ID
*/
public static final String PLUGIN_ID = "org.eclipse.blockchain.core";
/**
* @return - Blockchain core instance
*/
public static BlockchainCore getInstance() {
if (instance == null) {
instance = new BlockchainCore();
}
return instance;
}
/**
* This is used to log tool related exception
*
* @param pluginId - If null/empty default plugin id will be taken.
* @param message - The short message must not be null/empty
* @param e - The exception trace must not be null/empty
*/
public void logException(final String pluginId, final String message, final Exception e) {
String pluginDetails = pluginId;
if ((pluginDetails == null) || pluginDetails.isEmpty()) {
pluginDetails = PLUGIN_ID;
}
if (e == null) {
return;
}
Status status = new Status(IStatus.ERROR, pluginDetails, message + System.lineSeparator() + getError(e));
instance.getLog().log(status);
}
private String getError(final Exception e) {
StringJoiner errorTrace = new StringJoiner(System.lineSeparator());
errorTrace.add(e.getMessage());
for (StackTraceElement ste : e.getStackTrace()) {
errorTrace.add(ste.toString());
}
if (e.getCause() != null) {
errorTrace.add(e.getCause().toString());
}
return errorTrace.toString();
}
}