mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Nicolas Capponi
28.34.2014 1d5d1a6a4a0a58d6bb4803527dacb6641c027816
opendj3-server-dev/src/server/org/opends/server/loggers/debug/DebugTracer.java
@@ -33,10 +33,6 @@
import org.opends.server.loggers.LogCategory;
import java.util.Map;
import com.sleepycat.je.OperationStatus;
import com.sleepycat.je.Transaction;
import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.Database;
/**
 * Class for source-code tracing at the method level.
@@ -382,174 +378,6 @@
  }
  /**
   * Log a JE database access event.
   *
   * @param level the level of the log message.
   * @param status status of the JE operation.
   * @param database the database handle.
   * @param txn  transaction handle (may be null).
   * @param key  the key to dump.
   * @param data the data to dump.
   */
  public void debugJEAccess(LogLevel level, OperationStatus status,
                            Database database, Transaction txn,
                            DatabaseEntry key, DatabaseEntry data)
  {
    if(DebugLogger.debugEnabled())
    {
      StackTraceElement[] stackTrace = null;
      StackTraceElement[] filteredStackTrace = null;
      StackTraceElement callerFrame = null;
      for (PublisherSettings settings : publisherSettings)
      {
        TraceSettings activeSettings = settings.classSettings;
        Map<String, TraceSettings> methodSettings = settings.methodSettings;
        if (shouldLog(DebugLogCategory.MESSAGE, activeSettings) || methodSettings != null)
        {
          if(stackTrace == null)
          {
            stackTrace = Thread.currentThread().getStackTrace();
          }
          if (callerFrame == null)
          {
            callerFrame = getCallerFrame(stackTrace);
          }
          String signature = callerFrame.getMethodName();
          // Specific method settings still could exist. Try getting
          // the settings for this method.
          if(methodSettings != null)
          {
            TraceSettings mSettings = methodSettings.get(signature);
            if (mSettings == null)
            {
              // Try looking for an undecorated method name
              int idx = signature.indexOf('(');
              if (idx != -1)
              {
                mSettings =
                    methodSettings.get(signature.substring(0, idx));
              }
            }
            // If this method does have a specific setting and it is not
            // suppose to be logged, continue.
            if (mSettings != null)
            {
              if(!shouldLog(DebugLogCategory.MESSAGE, mSettings))
              {
                continue;
              }
              else
              {
                activeSettings = mSettings;
              }
            }
          }
          String sl = callerFrame.getFileName() + ":" +
              callerFrame.getLineNumber();
          if (filteredStackTrace == null && activeSettings.stackDepth > 0)
          {
            filteredStackTrace =
                DebugStackTraceFormatter.SMART_FRAME_FILTER.
                    getFilteredStackTrace(stackTrace);
          }
          settings.debugPublisher.traceJEAccess(activeSettings, signature,
                                                sl, status, database, txn,
                                                key, data, filteredStackTrace);
        }
      }
    }
  }
  /**
   * Log a protocol element.
   *
   * @param level the level of the log message.
   * @param elementStr the string representation of protocol element.
   */
  public void debugProtocolElement(LogLevel level, String elementStr)
  {
    if(DebugLogger.debugEnabled() && elementStr != null)
    {
      StackTraceElement[] stackTrace = null;
      StackTraceElement[] filteredStackTrace = null;
      StackTraceElement callerFrame = null;
      for (PublisherSettings settings : publisherSettings)
      {
        TraceSettings activeSettings = settings.classSettings;
        Map<String, TraceSettings> methodSettings = settings.methodSettings;
        if (shouldLog(DebugLogCategory.MESSAGE, activeSettings) || methodSettings != null)
        {
          if(stackTrace == null)
          {
            stackTrace = Thread.currentThread().getStackTrace();
          }
          if (callerFrame == null)
          {
            callerFrame = getCallerFrame(stackTrace);
          }
          String signature = callerFrame.getMethodName();
          // Specific method settings still could exist. Try getting
          // the settings for this method.
          if(methodSettings != null)
          {
            TraceSettings mSettings = methodSettings.get(signature);
            if (mSettings == null)
            {
              // Try looking for an undecorated method name
              int idx = signature.indexOf('(');
              if (idx != -1)
              {
                mSettings =
                    methodSettings.get(signature.substring(0, idx));
              }
            }
            // If this method does have a specific setting and it is not
            // suppose to be logged, continue.
            if (mSettings != null)
            {
              if(!shouldLog(DebugLogCategory.MESSAGE, mSettings))
              {
                continue;
              }
              else
              {
                activeSettings = mSettings;
              }
            }
          }
          String sl = callerFrame.getFileName() + ":" +
              callerFrame.getLineNumber();
          if (filteredStackTrace == null && activeSettings.stackDepth > 0)
          {
            filteredStackTrace =
                DebugStackTraceFormatter.SMART_FRAME_FILTER.
                    getFilteredStackTrace(stackTrace);
          }
          settings.debugPublisher.traceProtocolElement(activeSettings, signature,
                                                       sl, elementStr,
                                                       filteredStackTrace);
        }
      }
    }
  }
  /**
   * Gets the name of the class this tracer traces.
   *
   * @return The name of the class this tracer traces.