static <T> T trace(Level level, Object reason) {
        // NOTE: do not make this method private as it affects stack traces
        try {
            if (System.getProperty(propertyName) != null) {
                StackTraceElement[] st = Thread.currentThread().getStackTrace();
                String method = "???";
                String cls = ToolProvider.class.getName();
                if (st.length > 2) {
                    StackTraceElement frame = st[2];
                    method = String.format((Locale)null, "%s(%s:%s)",
                                           frame.getMethodName(),
                                           frame.getFileName(),
                                           frame.getLineNumber());
                    cls = frame.getClassName();
                }
                Logger logger = Logger.getLogger(loggerName);
                if (reason instanceof Throwable) {
                    logger.logp(level, cls, method,
                                reason.getClass().getName(), (Throwable)reason);
                } else {
                    logger.logp(level, cls, method, String.valueOf(reason));
                }
            }
        } catch (SecurityException ex) {
            System.err.format((Locale)null, "%s: %s; %s%n",
                              ToolProvider.class.getName(),
                              reason,
                              ex.getLocalizedMessage());
        }
        return null;
    }
static < T > T trace ( Level level , Object reason ) { try { if ( System . getProperty ( propertyName ) != null ) { StackTraceElement [ ] st = Thread . currentThread ( ) . getStackTrace ( ) ; String method = "???" ; String cls = ToolProvider . class . getName ( ) ; if ( st . length > 2 ) { StackTraceElement frame = st [ 2 ] ; method = String . format ( ( Locale ) null , "%s(%s:%s)" , frame . getMethodName ( ) , frame . getFileName ( ) , frame . getLineNumber ( ) ) ; cls = frame . getClassName ( ) ; } Logger logger = Logger . getLogger ( loggerName ) ; if ( reason instanceof Throwable ) { logger . logp ( level , cls , method , reason . getClass ( ) . getName ( ) , ( Throwable ) reason ) ; } else { logger . logp ( level , cls , method , String . valueOf ( reason ) ) ; } } } catch ( SecurityException ex ) { System . err . format ( ( Locale ) null , "%s: %s; %s%n" , ToolProvider . class . getName ( ) , reason , ex . getLocalizedMessage ( ) ) ; } return null ; }
/*
Define the system property "sun.tools.ToolProvider" to enable
debugging:

java ... -Dsun.tools.ToolProvider ...