当前位置: 首页>>代码示例>>Java>>正文


Java Util.stackTraceToString方法代码示例

本文整理汇总了Java中com.mysql.jdbc.Util.stackTraceToString方法的典型用法代码示例。如果您正苦于以下问题:Java Util.stackTraceToString方法的具体用法?Java Util.stackTraceToString怎么用?Java Util.stackTraceToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mysql.jdbc.Util的用法示例。


在下文中一共展示了Util.stackTraceToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findCallingClassAndMethod

import com.mysql.jdbc.Util; //导入方法依赖的package包/类
public static String findCallingClassAndMethod(Throwable t) {
    String stackTraceAsString = Util.stackTraceToString(t);

    String callingClassAndMethod = CALLER_INFORMATION_NOT_AVAILABLE;

    int endInternalMethods = stackTraceAsString.lastIndexOf("com.mysql.jdbc");

    if (endInternalMethods != -1) {
        int endOfLine = -1;
        int compliancePackage = stackTraceAsString.indexOf("com.mysql.jdbc.compliance", endInternalMethods);

        if (compliancePackage != -1) {
            endOfLine = compliancePackage - LINE_SEPARATOR_LENGTH;
        } else {
            endOfLine = stackTraceAsString.indexOf(LINE_SEPARATOR, endInternalMethods);
        }

        if (endOfLine != -1) {
            int nextEndOfLine = stackTraceAsString.indexOf(LINE_SEPARATOR, endOfLine + LINE_SEPARATOR_LENGTH);

            if (nextEndOfLine != -1) {
                callingClassAndMethod = stackTraceAsString.substring(endOfLine + LINE_SEPARATOR_LENGTH, nextEndOfLine);
            } else {
                callingClassAndMethod = stackTraceAsString.substring(endOfLine + LINE_SEPARATOR_LENGTH);
            }
        }
    }

    if (!callingClassAndMethod.startsWith("\tat ") && !callingClassAndMethod.startsWith("at ")) {
        return "at " + callingClassAndMethod;
    }

    return callingClassAndMethod;
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:35,代码来源:LogUtils.java

示例2: expandProfilerEventIfNecessary

import com.mysql.jdbc.Util; //导入方法依赖的package包/类
public static Object expandProfilerEventIfNecessary(Object possibleProfilerEvent) {

        if (possibleProfilerEvent instanceof ProfilerEvent) {
            StringBuilder msgBuf = new StringBuilder();

            ProfilerEvent evt = (ProfilerEvent) possibleProfilerEvent;

            String locationInformation = evt.getEventCreationPointAsString();

            if (locationInformation == null) {
                locationInformation = Util.stackTraceToString(new Throwable());
            }

            msgBuf.append("Profiler Event: [");

            switch (evt.getEventType()) {
                case ProfilerEvent.TYPE_EXECUTE:
                    msgBuf.append("EXECUTE");

                    break;

                case ProfilerEvent.TYPE_FETCH:
                    msgBuf.append("FETCH");

                    break;

                case ProfilerEvent.TYPE_OBJECT_CREATION:
                    msgBuf.append("CONSTRUCT");

                    break;

                case ProfilerEvent.TYPE_PREPARE:
                    msgBuf.append("PREPARE");

                    break;

                case ProfilerEvent.TYPE_QUERY:
                    msgBuf.append("QUERY");

                    break;

                case ProfilerEvent.TYPE_WARN:
                    msgBuf.append("WARN");

                    break;

                case ProfilerEvent.TYPE_SLOW_QUERY:
                    msgBuf.append("SLOW QUERY");

                    break;

                default:
                    msgBuf.append("UNKNOWN");
            }

            msgBuf.append("] ");
            msgBuf.append(locationInformation);
            msgBuf.append(" duration: ");
            msgBuf.append(evt.getEventDuration());
            msgBuf.append(" ");
            msgBuf.append(evt.getDurationUnits());
            msgBuf.append(", connection-id: ");
            msgBuf.append(evt.getConnectionId());
            msgBuf.append(", statement-id: ");
            msgBuf.append(evt.getStatementId());
            msgBuf.append(", resultset-id: ");
            msgBuf.append(evt.getResultSetId());

            String evtMessage = evt.getMessage();

            if (evtMessage != null) {
                msgBuf.append(", message: ");
                msgBuf.append(evtMessage);
            }

            return msgBuf;
        }

        return possibleProfilerEvent;
    }
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:81,代码来源:LogUtils.java


注:本文中的com.mysql.jdbc.Util.stackTraceToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。