@RestControllerAdvice @Slf4j public class GlobalException { @ExceptionHandler(ServiceException.class) public String serviceExceptionHandler(ServiceException e) { StackTraceElement stackTraceElement = e.getStackTrace()[0]; / / get the name of the class String className = stackTraceElement. GetClassName (); String filePath = stackTraceElement.getFileName(); int lineNumber = stackTraceElement.getLineNumber(); String methodName = stackTraceElement.getMethodName(); Log.info (" Class Name :{}, File Path :{}, Number of Lines :{}, Method Name :{}", ClassName, FilePath, LineNumber, MethodName); Return "className :" + className + ", filePath :" + filePath + ", lineNumber :" + lineNumber +"; }}