package com.eactive.eai.common.util.logger;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;

public class CustomLineOfCallerConverter extends ClassicConverter {
	public String convert(ILoggingEvent le) {
		StackTraceElement[] cda = le.getCallerData();
		if (cda != null && cda.length > 0) {
			if (cda[0].getFileName().equals("Logger.java") && cda.length > 1) {
				if (cda[1].getFileName().equals("Logger.java") && cda.length > 2){
					return Integer.toString(cda[2].getLineNumber());
				}			
				return Integer.toString(cda[1].getLineNumber());
			}
			return Integer.toString(cda[0].getLineNumber());
		} else {
			return "?";
		}
	}
}