srcanaapps/depexplorer/com.nokia.s60tools.appdep/src/com/nokia/s60tools/appdep/util/LogUtils.java
changeset 0 a02c979e8dfd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/srcanaapps/depexplorer/com.nokia.s60tools.appdep/src/com/nokia/s60tools/appdep/util/LogUtils.java	Sat Jan 09 10:04:11 2010 +0530
@@ -0,0 +1,71 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+
+package com.nokia.s60tools.appdep.util;
+
+import org.eclipse.swt.widgets.Display;
+
+import com.nokia.s60tools.util.console.IConsolePrintUtility;
+
+/**
+ * Miscellaneous logging utilities to be used as tracing aid in case of error 
+ * for which is otherwise hard to find information about the error in end-user environment
+ * unless properly logged also in production environment with exact error data.
+ */
+public class LogUtils {
+
+	/**
+	 * Logs error message and expection's stack trace to product console if we are running code 
+	 * in Eclipse workbench environment. If not (i.e running JUnit tests) 
+	 * catching the exceptions and ignoring them.
+	 * 
+	 * Logging done here because we loose important information because
+	 * cache data load is done inside job that looses stack trace. 
+	 * 
+	 * @param errorMsg Error message to log.
+	 * @param e Exception to log.
+	 */
+	public static void logStackTrace(final String errorMsg, final Exception e) {
+		try {
+			if(e != null) e.printStackTrace();
+			// Scheduling log task to UI thread.
+			Display.getDefault().asyncExec(new Runnable(){
+				public void run() {
+					AppDepConsole.getInstance().println(errorMsg, IConsolePrintUtility.MSG_ERROR);
+					if(e != null){
+						StackTraceElement[] stackTrace = e.getStackTrace();
+						AppDepConsole.getInstance().printStackTrace(stackTrace);															
+					}
+				}				
+			});
+		} catch (Exception e2) {
+			// Ignoring possible errors due to not having workbench environment running.
+		}
+	}
+
+	/**
+	 * Logs internal error message to tool's console and throws run-time exception.
+	 * @param errMsg Error message to log and pass as message to runtime exception. 
+	 * @throws RuntimeException
+	 */
+	static public void logInternalErrorAndThrowException(String errMsg) throws RuntimeException {
+		AppDepConsole.getInstance().println("INTERNAL ERROR: " + errMsg ); //$NON-NLS-1$
+		throw new RuntimeException(errMsg);
+	}
+
+}