Пример #1
0
  /**
   * We're about to push the info to the log, so do final adjustments on the logEntry object,
   * setting up data.
   *
   * @param logEntry LogEntry that holds the info to be logged
   * @param factory ResourceFactory the source for the DB connection
   */
  private static void prepLogEntry(LogEntry logEntry, ResourceFactory factory) {
    if (null == logEntry.serviceName) {
      logEntry.serviceName = factory.getSystemName();
    }

    StringBuilder desc = new StringBuilder(MAX_LOG_DESC);
    if (logEntry.clazz != null) {
      String className = logEntry.clazz.getName();
      int idx = className.lastIndexOf('.');

      desc.append(idx == -1 ? className : className.substring(idx + 1));
      desc.append(".");
      desc.append(logEntry.method);
    }

    if (!Str.isEmpty(logEntry.desc)) {
      desc.append(" ");
      desc.append(logEntry.desc);
    }

    if (logEntry.throwable != null) {
      desc.append(" Exception: ");
      if (logEntry.level.ordinal() >= factory.getStackTraceLevel().ordinal()) {
        desc.append(System.getProperty("line.separator"));
        desc.append(Stack.getShortStack(logEntry.throwable));
      } else {
        desc.append(logEntry.throwable.toString());
      }
    }

    logEntry.desc = desc.substring(0, Math.min(MAX_LOG_DESC, desc.length()));
  }
Пример #2
0
        @Override
        public ResourceFactory get() {
          ResourceFactory ret = super.get();
          if (null == ret) {
            Throwable t = new Throwable("*snapshot*");
            String msg = new Date() + ": Attempt to use ResourceFactory before it's initialized";
            System.out.println(msg + '\n' + Stack.getShortStack(t));
            throw new IllegalStateException(msg, t);
          }

          return ret;
        }