jdk/src/share/classes/java/util/logging/LogRecord.java
changeset 7026 9f2ec5fad124
parent 5506 202f599c92aa
child 7668 d4a77089c587
child 7803 56bc97d69d93
equal deleted inserted replaced
7025:6e002f9a2899 7026:9f2ec5fad124
   527         needToInferCaller = false;
   527         needToInferCaller = false;
   528         JavaLangAccess access = SharedSecrets.getJavaLangAccess();
   528         JavaLangAccess access = SharedSecrets.getJavaLangAccess();
   529         Throwable throwable = new Throwable();
   529         Throwable throwable = new Throwable();
   530         int depth = access.getStackTraceDepth(throwable);
   530         int depth = access.getStackTraceDepth(throwable);
   531 
   531 
   532         String logClassName = "java.util.logging.Logger";
       
   533         String plogClassName = "sun.util.logging.PlatformLogger";
       
   534         boolean lookingForLogger = true;
   532         boolean lookingForLogger = true;
   535         for (int ix = 0; ix < depth; ix++) {
   533         for (int ix = 0; ix < depth; ix++) {
   536             // Calling getStackTraceElement directly prevents the VM
   534             // Calling getStackTraceElement directly prevents the VM
   537             // from paying the cost of building the entire stack frame.
   535             // from paying the cost of building the entire stack frame.
   538             StackTraceElement frame =
   536             StackTraceElement frame =
   539                 access.getStackTraceElement(throwable, ix);
   537                 access.getStackTraceElement(throwable, ix);
   540             String cname = frame.getClassName();
   538             String cname = frame.getClassName();
       
   539             boolean isLoggerImpl = isLoggerImplFrame(cname);
   541             if (lookingForLogger) {
   540             if (lookingForLogger) {
   542                 // Skip all frames until we have found the first logger frame.
   541                 // Skip all frames until we have found the first logger frame.
   543                 if (cname.equals(logClassName) || cname.startsWith(plogClassName)) {
   542                 if (isLoggerImpl) {
   544                     lookingForLogger = false;
   543                     lookingForLogger = false;
   545                 }
   544                 }
   546             } else {
   545             } else {
   547                 if (!cname.equals(logClassName) && !cname.startsWith(plogClassName)) {
   546                 if (!isLoggerImpl) {
   548                     // skip reflection call
   547                     // skip reflection call
   549                     if (!cname.startsWith("java.lang.reflect.") && !cname.startsWith("sun.reflect.")) {
   548                     if (!cname.startsWith("java.lang.reflect.") && !cname.startsWith("sun.reflect.")) {
   550                        // We've found the relevant frame.
   549                        // We've found the relevant frame.
   551                        setSourceClassName(cname);
   550                        setSourceClassName(cname);
   552                        setSourceMethodName(frame.getMethodName());
   551                        setSourceMethodName(frame.getMethodName());
   556             }
   555             }
   557         }
   556         }
   558         // We haven't found a suitable frame, so just punt.  This is
   557         // We haven't found a suitable frame, so just punt.  This is
   559         // OK as we are only committed to making a "best effort" here.
   558         // OK as we are only committed to making a "best effort" here.
   560     }
   559     }
       
   560 
       
   561     private boolean isLoggerImplFrame(String cname) {
       
   562         // the log record could be created for a platform logger
       
   563         return (cname.equals("java.util.logging.Logger") ||
       
   564                 cname.startsWith("java.util.logging.LoggingProxyImpl") ||
       
   565                 cname.startsWith("sun.util.logging."));
       
   566     }
   561 }
   567 }