Skip to content

Commit 0ef15b4

Browse files
authored
Stable logging API - the basic use case (#86612)
Introducing a stable logging API under libs/logging. This change covers the most common use cases for logging: fetching a logger with LogManager, emitting a log messages with Logger and Level. It is influenced by log4j2-api, but do not include Marker and LogBuilder methods. Also methods using org.apache.logging.log4j.util.Supplier are replaced with java.util.Supplier The basic implementation is present in server and injected statically in LogConfigurator relates #84478
1 parent b123feb commit 0ef15b4

File tree

18 files changed

+1051
-0
lines changed

18 files changed

+1051
-0
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/InternalDistributionModuleCheckTaskProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class InternalDistributionModuleCheckTaskProvider {
5252
"org.elasticsearch.base",
5353
"org.elasticsearch.cli",
5454
"org.elasticsearch.geo",
55+
"org.elasticsearch.logging",
5556
"org.elasticsearch.lz4",
5657
"org.elasticsearch.pluginclassloader",
5758
"org.elasticsearch.securesm",

docs/changelog/86612.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 86612
2+
summary: Stable logging API - the basic use case
3+
area: Infra/Logging
4+
type: feature
5+
issues: []

libs/logging/build.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import org.elasticsearch.gradle.transform.UnzipTransform
2+
3+
import java.util.stream.Collectors
4+
5+
/*
6+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
7+
* or more contributor license agreements. Licensed under the Elastic License
8+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
9+
* in compliance with, at your election, the Elastic License 2.0 or the Server
10+
* Side Public License, v 1.
11+
*/
12+
13+
apply plugin: 'elasticsearch.publish'
14+
apply plugin: 'elasticsearch.build'
15+
16+
17+
tasks.named("loggerUsageCheck").configure {enabled = false }
18+
19+
dependencies {
20+
testImplementation(project(":test:framework")) {
21+
exclude group: 'org.elasticsearch', module: 'elasticsearch-logging'
22+
}
23+
}
24+
25+
26+
tasks.named('forbiddenApisMain').configure {
27+
// :libs:elasticsearch-logging does not depend on server
28+
replaceSignatureFiles 'jdk-signatures'
29+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
module org.elasticsearch.logging {
10+
exports org.elasticsearch.logging;
11+
exports org.elasticsearch.logging.internal.spi to org.elasticsearch.server;
12+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.logging;
10+
11+
/**
12+
* Levels used for identifying the severity of an event and filtering the logging output.
13+
*/
14+
public enum Level {
15+
16+
/**
17+
* No events will be logged.
18+
*/
19+
OFF,
20+
/**
21+
* A fatal error that will prevent the application from continuing.
22+
*/
23+
FATAL,
24+
/**
25+
* An error in the application, possibly recoverable.
26+
*/
27+
ERROR,
28+
/**
29+
* An event that might lead to an error.
30+
*/
31+
WARN,
32+
/**
33+
* An event for informational purposes.
34+
*/
35+
INFO,
36+
/**
37+
* A general debugging event.
38+
*/
39+
DEBUG,
40+
/**
41+
* A fine-grained debug message, typically capturing the flow through the application.
42+
*/
43+
TRACE,
44+
/**
45+
* All events should be logged.
46+
*/
47+
ALL;
48+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.logging;
10+
11+
import org.elasticsearch.logging.internal.spi.LoggerFactory;
12+
13+
/**
14+
* A Manager of {@code Loggers}. This class consists of factory methods for creating and retrieving Loggers.
15+
*/
16+
public final class LogManager {
17+
18+
/**
19+
* Returns a Logger with the specified name.
20+
*
21+
* @param name The logger name.
22+
* @return The Logger.
23+
*/
24+
public static Logger getLogger(final String name) {
25+
return LoggerFactory.provider().getLogger(name);
26+
}
27+
28+
/**
29+
* Returns a Logger using the fully qualified name of the Class as the Logger name.
30+
*
31+
* @param clazz The Class whose name should be used as the Logger name.
32+
* @return The Logger.
33+
*/
34+
public static Logger getLogger(final Class<?> clazz) {
35+
return LoggerFactory.provider().getLogger(clazz);
36+
}
37+
38+
private LogManager() {}
39+
}

0 commit comments

Comments
 (0)