/*******************************************************************************
 * Copyright 2014 Centre for Development of Advanced Computing(C-DAC), Pune
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package in.cdac.medinfo.csnotk.csnolib.util;

import in.cdac.medinfo.csnotk.csnolib.commons.Constants;

//Log4j
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;


/**
 * Class Logger is the utility class which logs the exceptions or messages.
 */
public class LoggerUtility
{
	//To be used by other classes
	public static final Marker CONSOLE = MarkerManager.getMarker("Console");
	public static final Marker Log = MarkerManager.getMarker("Log");
	public static final Marker ConsoleWithLog = MarkerManager.getMarker("ConsoleWithLog");
	public static final Marker ConsoleWithException = MarkerManager.getMarker("ConsoleWithException");
	public static final Marker Exception = MarkerManager.getMarker("Exception");
	public static final Marker DISBException = MarkerManager.getMarker("DISBException");
	public static final Marker MapICDException = MarkerManager.getMarker("MapICDException");
	public static final Marker ConsoleWithMapICDException = MarkerManager.getMarker("ConsoleWithMapICDException");


	/**
	 * Create user defined message structure from Exception.
	 * @param exception	{@link String} value representing error message
	 */
	public static String createErrorMessage(Exception exception){
		StackTraceElement[] arrStackTraceElement;
		arrStackTraceElement = exception.getStackTrace();
		String strMessage="";
		try{
		strMessage = exception.getClass() + Constants.NEW_LINE
				+ Constants.CLASS_NAME
				+ arrStackTraceElement[0].getClassName()
				+ Constants.NEW_LINE + Constants.METHOD_NAME
				+ arrStackTraceElement[0].getMethodName()
				+ Constants.NEW_LINE + Constants.LINE_NUMBER
				+ arrStackTraceElement[0].getLineNumber()
				+ Constants.NEW_LINE + Constants.MESSAGE_DESCRIPTION
				+ exception.getMessage();
		}catch(Exception e){
			return strMessage;
		}
			return strMessage;
	}

}
