/** * Logs a deprecated message to the deprecation log, as well as to the local {@link ThreadContext}. * * @param threadContexts The node's {@link ThreadContext} (outside of concurrent tests, this should only ever have one context). * @param message The deprecation message. * @param params The parameters used to fill in the message, if any exist. */ void deprecated(final Set<ThreadContext> threadContexts, final String message, final Object... params) { deprecated(threadContexts, message, true, params); }
protected AbstractIndexShardComponent(ShardId shardId, IndexSettings indexSettings) { this.shardId = shardId; this.indexSettings = indexSettings; this.logger = Loggers.getLogger(getClass(), shardId); this.deprecationLogger = new DeprecationLogger(logger); }
/** * Standard constructor. */ public Dates(SortedNumericDocValues in) { this(in, (key, message) -> deprecationLogger.deprecatedAndMaybeLog(key, message)); }
@SuppressLoggerChecks(reason = "safely delegates to logger") void deprecated(final Set<ThreadContext> threadContexts, final String message, final boolean log, final Object... params) { final Iterator<ThreadContext> iterator = threadContexts.iterator(); if (iterator.hasNext()) { final String formattedMessage = LoggerMessageFormat.format(message, params); final String warningHeaderValue = formatWarning(formattedMessage); assert WARNING_HEADER_PATTERN.matcher(warningHeaderValue).matches(); assert extractWarningValueFromWarningHeader(warningHeaderValue).equals(escapeAndEncode(formattedMessage)); while (iterator.hasNext()) { try { final ThreadContext next = iterator.next(); next.addResponseHeader("Warning", warningHeaderValue, DeprecationLogger::extractWarningValueFromWarningHeader); } catch (final IllegalStateException e) { // ignored; it should be removed shortly } } } if (log) { logger.warn(message, params); } }
analyzerProviders = new HashMap<>(analyzerProviders); Logger logger = LogManager.getLogger(getClass()); DeprecationLogger deprecationLogger = new DeprecationLogger(logger); Map<String, NamedAnalyzer> analyzerAliases = new HashMap<>(); Map<String, NamedAnalyzer> analyzers = new HashMap<>(); "[index.analysis.analyzer.default] instead for index [" + index.getName() + "]"); } else { deprecationLogger.deprecated("setting [index.analysis.analyzer.default_index] is deprecated, use " + "[index.analysis.analyzer.default] instead for index [{}]", index.getName());
DeprecationLogger dLogger = new DeprecationLogger(logger); dLogger.deprecated("[{}] has been set, but will be removed in Elasticsearch 6.0.0", JsonXContent.JSON_ALLOW_UNQUOTED_FIELD_NAMES); resourcesToClose.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS)); DeprecationLogger.setThreadContext(threadPool.getThreadContext()); resourcesToClose.add(() -> DeprecationLogger.removeThreadContext(threadPool.getThreadContext()));
resourcesToClose.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS)); DeprecationLogger.setThreadContext(threadPool.getThreadContext()); resourcesToClose.add(() -> DeprecationLogger.removeThreadContext(threadPool.getThreadContext()));
/** * Format a warning string in the proper warning format by prepending a warn code, warn agent, wrapping the warning string in quotes, * and appending the RFC 7231 date. * * @param s the warning string to format * @return a warning value formatted according to RFC 7234 */ public static String formatWarning(final String s) { return String.format(Locale.ROOT, WARNING_FORMAT, escapeAndEncode(s), RFC_7231_DATE_TIME.format(ZonedDateTime.now(GMT))); }
final int penultimateQuote = s.lastIndexOf('\"', lastQuote - 1); final String warningValue = s.substring(firstQuote + 1, penultimateQuote - 2); assert assertWarningValue(s, warningValue); return warningValue;
@Before public final void before() { logger.info("[{}]: before test", getTestName()); assertNull("Thread context initialized twice", threadContext); if (enableWarningsCheck()) { this.threadContext = new ThreadContext(Settings.EMPTY); DeprecationLogger.setThreadContext(threadContext); } }
private void logDeprecation() { if (deprecationEmitted == false) { Logger logger = Loggers.getLogger(getClass()); DeprecationLogger deprecationLogger = new DeprecationLogger(logger); deprecationLogger.deprecated("Using _index is deprecated. Create a custom ScriptEngine to access index internals."); deprecationEmitted = true; } }
/** * Reset the deprecation logger by removing the current thread context, and setting a new thread context if {@code setNewThreadContext} * is set to {@code true} and otherwise clearing the current thread context. * * @param setNewThreadContext whether or not to attach a new thread context to the deprecation logger */ private void resetDeprecationLogger(final boolean setNewThreadContext) { // "clear" current warning headers by setting a new ThreadContext DeprecationLogger.removeThreadContext(this.threadContext); try { this.threadContext.close(); // catch IOException to avoid that call sites have to deal with it. It is only declared because this class implements Closeable // but it is impossible that this implementation will ever throw an IOException. } catch (IOException ex) { throw new AssertionError("IOException thrown while closing deprecation logger's thread context", ex); } if (setNewThreadContext) { this.threadContext = new ThreadContext(Settings.EMPTY); DeprecationLogger.setThreadContext(this.threadContext); } else { this.threadContext = null; } }
@SuppressLoggerChecks(reason = "safely delegates to logger") void deprecated(final Set<ThreadContext> threadContexts, final String message, final boolean log, final Object... params) { final Iterator<ThreadContext> iterator = threadContexts.iterator(); if (iterator.hasNext()) { final String formattedMessage = LoggerMessageFormat.format(message, params); final String warningHeaderValue = formatWarning(formattedMessage); assert WARNING_HEADER_PATTERN.matcher(warningHeaderValue).matches(); assert extractWarningValueFromWarningHeader(warningHeaderValue).equals(escapeAndEncode(formattedMessage)); while (iterator.hasNext()) { try { final ThreadContext next = iterator.next(); next.addResponseHeader("Warning", warningHeaderValue, DeprecationLogger::extractWarningValueFromWarningHeader); } catch (final IllegalStateException e) { // ignored; it should be removed shortly } } } if (log) { logger.warn(message, params); } }
/** * Format a warning string in the proper warning format by prepending a warn code, warn agent, wrapping the warning string in quotes, * and appending the RFC 7231 date. * * @param s the warning string to format * @return a warning value formatted according to RFC 7234 */ public static String formatWarning(final String s) { return String.format(Locale.ROOT, WARNING_FORMAT, escapeAndEncode(s), RFC_7231_DATE_TIME.format(ZonedDateTime.now(GMT))); }
final int penultimateQuote = s.lastIndexOf('\"', lastQuote - 1); final String warningValue = s.substring(firstQuote + 1, penultimateQuote - 2); assert assertWarningValue(s, warningValue); return warningValue;
/** * Logs a deprecation message, adding a formatted warning message as a response header on the thread context. */ public void deprecated(String msg, Object... params) { deprecated(THREAD_CONTEXT, msg, params); }
static void checkConfigExtension(String extension) { if (".yaml".equals(extension) || ".json".equals(extension)) { final DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(Bootstrap.class)); deprecationLogger.deprecated("elasticsearch{} is deprecated; rename your configuration file to elasticsearch.yml", extension); } }
/** * Standard constructor. */ public Longs(SortedNumericDocValues in) { this(in, (key, message) -> deprecationLogger.deprecatedAndMaybeLog(key, message)); }
/** * Constructs a new index component, with the index name and its settings. */ protected AbstractIndexComponent(IndexSettings indexSettings) { this.logger = Loggers.getLogger(getClass(), indexSettings.getIndex()); this.deprecationLogger = new DeprecationLogger(logger); this.indexSettings = indexSettings; }
resourcesToClose.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS)); DeprecationLogger.setThreadContext(threadPool.getThreadContext()); resourcesToClose.add(() -> DeprecationLogger.removeThreadContext(threadPool.getThreadContext()));