-
Notifications
You must be signed in to change notification settings - Fork 600
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
Move SyslogAppender into separate onprem bundle #3407
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2294b2e
Move SyslogAppender into separate onprem bundle
cziegeler e8d24cc
Move SyslogAppender into separate onprem bundle
cziegeler d588d4e
Update dependencies
cziegeler 2ec11c1
Remove dependencies on sling commons testing
cziegeler beba1c4
Update to junit5
cziegeler a9d157d
Add logback dependency back to make tests pass
cziegeler 887486c
Update changelog
cziegeler 7f47fe6
Fix checkstyle comment warning
cziegeler fbda86e
Fix checkstyle comment errors
cziegeler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,4 @@ | ||
/nb-configuration.xml | ||
*.factorypath | ||
/dependency-reduced-pom.xml | ||
/nbactions-autoInstallBundle.xml |
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,165 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ ACS AEM Commons | ||
~ | ||
~ Copyright (C) 2013 - 2024 Adobe | ||
~ | ||
~ 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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd "> | ||
<modelVersion>4.0.0</modelVersion> | ||
<!-- ====================================================================== --> | ||
<!-- P A R E N T P R O J E C T D E S C R I P T I O N --> | ||
<!-- ====================================================================== --> | ||
<parent> | ||
<groupId>com.adobe.acs</groupId> | ||
<artifactId>acs-aem-commons</artifactId> | ||
<version>6.6.3-SNAPSHOT</version> | ||
</parent> | ||
|
||
<!-- ====================================================================== --> | ||
<!-- P R O J E C T D E S C R I P T I O N --> | ||
<!-- ====================================================================== --> | ||
|
||
<artifactId>acs-aem-commons-bundle-onprem</artifactId> | ||
<name>ACS AEM Commons Bundle - On Prem</name> | ||
<description>Core ACS AEM Commons OSGi Bundle for AEM on prem only</description> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>biz.aQute.bnd</groupId> | ||
<artifactId>bnd-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>biz.aQute.bnd</groupId> | ||
<artifactId>bnd-baseline-maven-plugin</artifactId> | ||
<configuration> | ||
<skip>true</skip><!-- temporarily ignore due to empty interface being exported in 6.3.x --> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.sling</groupId> | ||
<artifactId>sling-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<!-- ======================== --> | ||
<!-- START build dependencies --> | ||
<dependency> | ||
cziegeler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<groupId>org.osgi</groupId> | ||
<artifactId>org.osgi.annotation.versioning</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.osgi</groupId> | ||
<artifactId>org.osgi.annotation.bundle</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.osgi</groupId> | ||
<artifactId>org.osgi.service.component.annotations</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.osgi</groupId> | ||
<artifactId>org.osgi.service.metatype.annotations</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.sling</groupId> | ||
<artifactId>org.apache.sling.servlets.annotations</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains</groupId> | ||
<artifactId>annotations</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- END build dependencies --> | ||
<!-- ======================== --> | ||
<!-- START runtime dependencies not contained in uber-jar --> | ||
<dependency> | ||
<groupId>org.osgi</groupId> | ||
<artifactId>org.osgi.framework</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<!-- END runtime dependencies not contained in uber-jar --> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- End Test dependencies --> | ||
<!-- ======================== --> | ||
<!-- put UberJar last so that more specific artifacts take precedence --> | ||
<dependency> | ||
cziegeler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<groupId>com.adobe.aem</groupId> | ||
<artifactId>uber-jar</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>release</id> | ||
<activation> | ||
<property> | ||
<name>performRelease</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<executions> | ||
<!-- generate empty jar, as long as no javadoc is generated --> | ||
<execution> | ||
<id>javadoc-jar</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
<configuration> | ||
<classesDirectory>${project.build.directory}/invalid</classesDirectory> | ||
<classifier>javadoc</classifier> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
</project> |
136 changes: 136 additions & 0 deletions
136
bundle-onprem/src/main/java/com/adobe/acs/commons/logging/impl/SyslogAppender.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,136 @@ | ||
/* | ||
* #%L | ||
* ACS AEM Commons Bundle | ||
* %% | ||
* Copyright (C) 2013 - 2023 Adobe | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
package com.adobe.acs.commons.logging.impl; | ||
|
||
import java.util.Dictionary; | ||
import java.util.Hashtable; | ||
|
||
import ch.qos.logback.core.net.SyslogAppenderBase; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.ServiceRegistration; | ||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.ConfigurationPolicy; | ||
import org.osgi.service.component.annotations.Deactivate; | ||
import org.osgi.service.metatype.annotations.AttributeDefinition; | ||
import org.osgi.service.metatype.annotations.Designate; | ||
import org.osgi.service.metatype.annotations.ObjectClassDefinition; | ||
|
||
import ch.qos.logback.core.Appender; | ||
|
||
@Component(configurationPolicy = ConfigurationPolicy.REQUIRE, | ||
property = { | ||
"webconsole.configurationFactory.nameHint=Host: {host}, for loggers [{loggers}]" | ||
}) | ||
@Designate(ocd = SyslogAppender.Config.class, factory = true) | ||
public final class SyslogAppender { | ||
|
||
@ObjectClassDefinition(name = "ACS AEM Commons - Syslog Appender", | ||
description = "Logback appender to send messages using Syslog") | ||
public @interface Config { | ||
|
||
@AttributeDefinition(name = "Host", description = "Host of Syslog server") | ||
String host(); | ||
|
||
@AttributeDefinition(name = "Logger Names", description = "List of logger categories (ROOT for all)") | ||
String[] loggers() default {"ROOT"}; | ||
|
||
@AttributeDefinition(name = "Port", description = "Port of Syslog server") | ||
int port() default -1; | ||
|
||
@AttributeDefinition(name = "Suffix Pattern", description = "Logback Pattern defining the message format.") | ||
String suffix_pattern() default "[%thread] %-5level %logger{36} - %msg%n"; | ||
|
||
@AttributeDefinition(name = "Syslog Facility", description = "The Syslog Facility is meant to identify the source of a message, " | ||
+ "separately from any context included in the Suffix Pattern. The facility option must be set to one of the strings " | ||
+ "KERN, USER, MAIL, DAEMON, AUTH, SYSLOG, LPR, NEWS, UUCP, CRON, AUTHPRIV, FTP, NTP, AUDIT, ALERT, CLOCK, LOCAL0, LOCAL1, " | ||
+ "LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7. Case is not important.") | ||
String facility() default "USER"; | ||
|
||
@AttributeDefinition(name = "Stack Trace Pattern", description = "Logback Pattern for customizing the string appearing just before each stack " | ||
+ "trace line. The default value for this property is a single tab character.") | ||
String stack_trace_pattern() default ""; | ||
|
||
@AttributeDefinition(name = "Exclude Throwables", description = "Set to true to cause stack trace data associated with a Throwable to be omitted. " | ||
+ "By default, this is set to false so that stack trace data is sent to the syslog server.") | ||
boolean throwable_excluded() default false; | ||
} | ||
|
||
private ch.qos.logback.classic.net.SyslogAppender appender; | ||
|
||
private ServiceRegistration<Appender> appenderRegistration; | ||
|
||
@Activate | ||
@SuppressWarnings("squid:S1149") | ||
protected void activate(final BundleContext ctx, final Config config) { | ||
this.appender = constructAppender(config); | ||
|
||
final Dictionary<String, Object> props = new Hashtable<>(); | ||
props.put("loggers", config.loggers()); | ||
appenderRegistration = ctx.registerService(Appender.class, appender, props); | ||
} | ||
|
||
static ch.qos.logback.classic.net.SyslogAppender constructAppender(final Config config) { | ||
if (StringUtils.isEmpty(config.host()) || config.port() == -1) { | ||
throw new IllegalArgumentException( | ||
"Syslog Appender not configured correctly. Both host and port need to be provided."); | ||
} | ||
|
||
// throws a descriptive IllegalArgumentException if facility is not valid. | ||
SyslogAppenderBase.facilityStringToint(config.facility()); | ||
|
||
final ch.qos.logback.classic.net.SyslogAppender appender = new ch.qos.logback.classic.net.SyslogAppender(); | ||
|
||
appender.setSyslogHost(config.host()); | ||
appender.setPort(config.port()); | ||
|
||
appender.setFacility(config.facility()); | ||
appender.setSuffixPattern(config.suffix_pattern()); | ||
|
||
if (StringUtils.isNotEmpty(config.stack_trace_pattern())) { | ||
appender.setStackTracePattern(config.stack_trace_pattern()); | ||
} | ||
|
||
appender.setThrowableExcluded(config.throwable_excluded()); | ||
return appender; | ||
} | ||
|
||
|
||
@Deactivate | ||
protected void deactivate() { | ||
if (appender != null) { | ||
if (appender.isStarted()) { | ||
appender.stop(); | ||
} | ||
appender = null; | ||
} | ||
|
||
if (appenderRegistration != null) { | ||
try { | ||
appenderRegistration.unregister(); | ||
} catch (IllegalStateException e) { | ||
// ignore | ||
} | ||
appenderRegistration = null; | ||
} | ||
} | ||
|
||
} |
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,15 @@ | ||
Copyright 2013 Adobe | ||
|
||
Adobe holds the copyright for all the files found in this repository. | ||
|
||
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. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering whether we should make this a fragment of
com.adobe.acs.acs-aem-commons-bundle
similar to the Cloud bundle in order to consume non-exported classes from it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this, too - not sure how likely that use case actually is and therefore decided to go with a plain old bundle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, we can do it later on if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kwin Thanks, is there anything else to be done?