Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infra for deprecation logging #11033

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions config/logging.yml
Expand Up @@ -4,6 +4,10 @@ rootLogger: ${es.logger.level}, console, file
logger:
# log action execution errors for easier debugging
action: DEBUG

# deprecation logging, turn to DEBUG to see them
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe be even more explicit that this logger only receives logs at the debug level, so any higher level will not log any message

deprecation: INFO, deprecation_log_file

# reduce the logging for aws, too much is logged under the default INFO
com.amazonaws: WARN
org.apache.http: INFO
Expand All @@ -24,6 +28,7 @@ logger:
additivity:
index.search.slowlog: false
index.indexing.slowlog: false
deprecation: false

appender:
console:
Expand Down Expand Up @@ -51,6 +56,14 @@ appender:
#type: pattern
#conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"

deprecation_log_file:
type: dailyRollingFile
file: ${path.logs}/${cluster.name}_deprecation.log
datePattern: "'.'yyyy-MM-dd"
layout:
type: pattern
conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"

index_search_slow_log_file:
type: dailyRollingFile
file: ${path.logs}/${cluster.name}_index_search_slowlog.log
Expand Down
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.common.component;

import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -29,16 +30,18 @@
public abstract class AbstractComponent {

protected final ESLogger logger;

protected final DeprecationLogger deprecationLogger;
protected final Settings settings;

public AbstractComponent(Settings settings) {
this.logger = Loggers.getLogger(getClass(), settings);
this.deprecationLogger = new DeprecationLogger(logger);
this.settings = settings;
}

public AbstractComponent(Settings settings, Class customClass) {
this.logger = Loggers.getLogger(customClass, settings);
this.deprecationLogger = new DeprecationLogger(logger);
this.settings = settings;
}

Expand Down
@@ -0,0 +1,51 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.elasticsearch.common.logging;

/**
* A logger that logs deprecation notices.
*/
public class DeprecationLogger {

private final ESLogger logger;

/**
* Creates a new deprecation logger based on the parent logger. Automatically
* prefixes the logger name with "deprecation", if it starts with "org.elasticsearch.",
* it replaces "org.elasticsearch" with "org.elasticsearch.deprecation" to maintain
* the "org.elasticsearch" namespace.
*/
public DeprecationLogger(ESLogger parentLogger) {
String name = parentLogger.getName();
if (name.startsWith("org.elasticsearch")) {
name = name.replace("org.elasticsearch.", "org.elasticsearch.deprecation.");
} else {
name = "deprecation." + name;
}
this.logger = ESLoggerFactory.getLogger(parentLogger.getPrefix(), name);
}

/**
* Logs a deprecated message.
*/
public void deprecated(String msg, Object... params) {
logger.debug(msg, params);
}
}
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.index;

import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -30,9 +31,8 @@
public abstract class AbstractIndexComponent implements IndexComponent {

protected final ESLogger logger;

protected final DeprecationLogger deprecationLogger;
protected final Index index;

protected final Settings indexSettings;

/**
Expand All @@ -45,6 +45,7 @@ protected AbstractIndexComponent(Index index, @IndexSettings Settings indexSetti
this.index = index;
this.indexSettings = indexSettings;
this.logger = Loggers.getLogger(getClass(), indexSettings, index);
this.deprecationLogger = new DeprecationLogger(logger);
}

@Override
Expand Down
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.index.shard;

import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -30,15 +31,15 @@
public abstract class AbstractIndexShardComponent implements IndexShardComponent {

protected final ESLogger logger;

protected final DeprecationLogger deprecationLogger;
protected final ShardId shardId;

protected final Settings indexSettings;

protected AbstractIndexShardComponent(ShardId shardId, @IndexSettings Settings indexSettings) {
this.shardId = shardId;
this.indexSettings = indexSettings;
this.logger = Loggers.getLogger(getClass(), indexSettings, shardId);
this.deprecationLogger = new DeprecationLogger(logger);
}

@Override
Expand Down