Beispiel #1
0
  /**
   * This variant delays the formatting of the string message until it is actually logged
   *
   * @param now
   * @param maxLogInterval suppress time
   * @param maxLogIntervalUnit suppress time units
   * @param logger a {@link VoltLogger}
   * @param level a {@link Level debug level}
   * @param cause evidentiary exception
   * @param stemformat a {@link String#format(String, Object...) string format}
   * @param parameters format parameters
   */
  public static void tryLogForMessage(
      long now,
      final long maxLogInterval,
      final TimeUnit maxLogIntervalUnit,
      final VoltLogger logger,
      final Level level,
      Throwable cause,
      String stemformat,
      Object... parameters) {
    Callable<RateLimitedLogger> builder =
        new Callable<RateLimitedLogger>() {
          @Override
          public RateLimitedLogger call() throws Exception {
            return new RateLimitedLogger(
                maxLogIntervalUnit.toMillis(maxLogInterval), logger, level);
          }
        };

    final RateLimitedLogger rll;
    try {
      rll = m_loggersCached.get(stemformat, builder);
      rll.log(now, level, cause, stemformat, parameters);
    } catch (ExecutionException ex) {
      Throwables.propagate(Throwables.getRootCause(ex));
    }
  }
Beispiel #2
0
 private String formatMessage(Throwable cause, String stemformat, Object... args) {
   String format = stemformat;
   if (cause != null) {
     format =
         new StringBuilder(stemformat.length() + 8)
             .append(stemformat)
             .append("\n%s")
             .toString()
             .intern();
     args = Arrays.copyOf(args, args.length + 1);
     args[args.length - 1] = Throwables.getStackTraceAsString(cause);
   }
   String msg = null;
   try {
     msg = String.format(format, args);
   } catch (MissingFormatArgumentException ex) {
     m_logger.error(
         "failed to format log message. Format: "
             + format
             + ", arguments: "
             + Arrays.toString(args),
         ex);
   } catch (IllegalFormatConversionException ex) {
     m_logger.error(
         "failed to format log message. Format: "
             + format
             + ", arguments: "
             + Arrays.toString(args),
         ex);
   } catch (UnknownFormatConversionException ex) {
     m_logger.error(
         "failed to format log message. Format: "
             + format
             + ", arguments: "
             + Arrays.toString(args),
         ex);
   } finally {
     if (msg == null) {
       msg = "Format: " + format + ", arguments: " + Arrays.toString(args);
     }
   }
   return msg;
 }