Skip to content

Commit

Permalink
Move SyslogAppender into separate onprem bundle (#3407)
Browse files Browse the repository at this point in the history
This closes #3401
  • Loading branch information
cziegeler authored Aug 8, 2024
1 parent b9095ac commit b10cfa8
Show file tree
Hide file tree
Showing 12 changed files with 654 additions and 297 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com)

### Changed

- #3401 - Move SyslogAppender into separate bundle for onprem only. SyslogAppender does not work in Cloud Service.
- #3390 - Remove usage of commons collections 3

### Fixed
Expand Down
7 changes: 7 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
<filter>true</filter>
<isAllVersionsFilter>true</isAllVersionsFilter>
</embedded>
<embedded>
<groupId>${project.groupId}</groupId>
<artifactId>acs-aem-commons-bundle-onprem</artifactId>
<target>/apps/acs-commons/install</target>
<filter>true</filter>
<isAllVersionsFilter>true</isAllVersionsFilter>
</embedded>
<embedded>
<groupId>${project.groupId}</groupId>
<artifactId>acs-aem-commons-ui.apps</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions bundle-onprem/.gitignore
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
165 changes: 165 additions & 0 deletions bundle-onprem/pom.xml
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>
<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>
<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>
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;
}
}

}
15 changes: 15 additions & 0 deletions bundle-onprem/src/main/resources/META-INF/COPYRIGHT
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.
Loading

0 comments on commit b10cfa8

Please sign in to comment.