-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6657539
commit c8adc98
Showing
16 changed files
with
844 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright © 2025 Cask Data, Inc. | ||
Licensed 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. | ||
--> | ||
|
||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>cdap</artifactId> | ||
<groupId>io.cdap.cdap</groupId> | ||
<version>6.11.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>cdap-log-publisher-spi</artifactId> | ||
<name>CDAP Log Publisher SPI</name> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<artifactId>logback-classic</artifactId> | ||
<groupId>ch.qos.logback</groupId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
52 changes: 52 additions & 0 deletions
52
cdap-log-publisher-spi/src/main/java/io/cdap/cdap/spi/logs/LogPublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright © 2025 Cask Data, Inc. | ||
* | ||
* Licensed 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 io.cdap.cdap.spi.logs; | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
|
||
/** | ||
* Publishes log events to a destination. | ||
*/ | ||
public interface LogPublisher extends AutoCloseable { | ||
|
||
/** | ||
* Returns the name of the log publisher. | ||
* | ||
* @return the name of the publisher. | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* Publishes a logging event. | ||
* | ||
* @param event the logging event to publish. | ||
*/ | ||
void publish(ILoggingEvent event); | ||
|
||
/** | ||
* Initializes the log publisher with the required context. | ||
* | ||
* @param context the context to initialize the publisher with. | ||
*/ | ||
void initialize(LogPublisherContext context); | ||
|
||
/** | ||
* Closes the log publisher and releases associated resources. | ||
*/ | ||
@Override | ||
void close(); | ||
} |
33 changes: 33 additions & 0 deletions
33
cdap-log-publisher-spi/src/main/java/io/cdap/cdap/spi/logs/LogPublisherContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright © 2025 Cask Data, Inc. | ||
* | ||
* Licensed 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 io.cdap.cdap.spi.logs; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Provides context information for {@link LogPublisher} initialization. | ||
*/ | ||
public interface LogPublisherContext { | ||
|
||
/** | ||
* Properties are derived from the CDAP configuration. Configuration file path will be added as an | ||
* entry in the properties. | ||
* | ||
* @return unmodifiable properties for the log publisher. | ||
*/ | ||
Map<String, String> getProperties(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
cdap-watchdog/src/main/java/io/cdap/cdap/logging/appender/CompositeLogAppender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright © 2025 Cask Data, Inc. | ||
* | ||
* Licensed 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 io.cdap.cdap.logging.appender; | ||
|
||
import ch.qos.logback.core.Context; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
/** | ||
* A log appender that delegates logging events to a list of other log appenders. | ||
*/ | ||
public class CompositeLogAppender extends LogAppender { | ||
|
||
private final List<LogAppender> appenders; | ||
|
||
/** | ||
* Constructs a CompositeLogAppender with the given list of appenders. | ||
* | ||
* @param appenders the list of {@link LogAppender} instances to delegate logging events to | ||
*/ | ||
public CompositeLogAppender(List<LogAppender> appenders) { | ||
if (appenders == null) { | ||
throw new IllegalArgumentException("Appenders list cannot be null"); | ||
} | ||
|
||
// Make the appenders list unmodifiable to ensure thread safety and prevent external | ||
// modifications. | ||
this.appenders = Collections.unmodifiableList(new ArrayList<>(appenders)); | ||
setName(getClass().getName()); | ||
} | ||
|
||
@Override | ||
public void start() { | ||
executeOnAppenders("start", LogAppender::start); | ||
super.start(); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
super.stop(); | ||
executeOnAppenders("stop", LogAppender::stop); | ||
} | ||
|
||
@Override | ||
protected void appendEvent(LogMessage logMessage) { | ||
executeOnAppenders("appendEvent", appender -> appender.appendEvent(logMessage)); | ||
} | ||
|
||
@Override | ||
public void setContext(Context context) { | ||
executeOnAppenders("setContext", appender -> appender.setContext(context)); | ||
super.setContext(context); | ||
} | ||
|
||
/** | ||
* Executes a specified action on all appenders and handles any exceptions. | ||
* | ||
* @param actionName the name of the action being performed (for logging purposes) | ||
* @param action the action to execute on each appender | ||
* @throws RuntimeException if one or more appenders fail to perform the action | ||
*/ | ||
private void executeOnAppenders(String actionName, Consumer<LogAppender> action) { | ||
RuntimeException exceptions = null; | ||
for (LogAppender appender : appenders) { | ||
try { | ||
action.accept(appender); | ||
} catch (Exception e) { | ||
if (exceptions == null) { | ||
exceptions = new RuntimeException("One or more appenders failed to " + actionName); | ||
} | ||
exceptions.addSuppressed(e); | ||
} | ||
} | ||
|
||
if (exceptions != null) { | ||
throw exceptions; | ||
} | ||
} | ||
} |
Oops, something went wrong.