Create AuditService as Spring Boot app
diff --git a/audit-service/pom.xml b/audit-service/pom.xml
new file mode 100644
index 0000000..cefc067
--- /dev/null
+++ b/audit-service/pom.xml
@@ -0,0 +1,183 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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/xsd/maven-4.0.0.xsd">
+ <!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF 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.
+ -->
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>audit-sample-parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>audit-service</artifactId>
+ <packaging>jar</packaging>
+
+ <description>Audit Logging Service</description>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring.boot.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-catalog-api</artifactId>
+ <version>${log4j-audit.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>audit-service-war</artifactId>
+ <type>war</type>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-thymeleaf</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-devtools</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-log4j2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-actuator</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-tomcat</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.data</groupId>
+ <artifactId>spring-data-rest-webmvc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.data</groupId>
+ <artifactId>spring-data-jpa</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.modelmapper</groupId>
+ <artifactId>modelmapper</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.modelmapper.extensions</groupId>
+ <artifactId>modelmapper-spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.modelmapper.extensions</groupId>
+ <artifactId>modelmapper-jackson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.plugin</groupId>
+ <artifactId>spring-plugin-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.plugin</groupId>
+ <artifactId>spring-plugin-metadata</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>3.0.1</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>3.1.0</version>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ <overlays>
+ <overlay>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>audit-service-war</artifactId>
+ <excludes>
+ <exclude>WEB-INF/lib/spring-*.jar</exclude>
+ </excludes>
+ </overlay>
+ </overlays>
+ </configuration>
+ <executions>
+ <execution>
+ <id>default-war</id>
+ <goals>
+ <goal>war</goal>
+ </goals>
+ <phase>package</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring.boot.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/audit-service/src/main/java/org/apache/logging/log4j/audit/AuditService.java b/audit-service/src/main/java/org/apache/logging/log4j/audit/AuditService.java
new file mode 100644
index 0000000..faa7096
--- /dev/null
+++ b/audit-service/src/main/java/org/apache/logging/log4j/audit/AuditService.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.apache.logging.log4j.audit;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.logging.log4j.catalog.api.util.ProfileUtil;
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.support.SpringBootServletInitializer;
+
+/**
+ *
+ */
+@SpringBootApplication
+public class AuditService extends SpringBootServletInitializer {
+ private static final String SPRING_PROFILE = "spring.profiles.active";
+
+ public static void main(String[] args) {
+ SpringApplicationBuilder builder = new SpringApplicationBuilder().profiles(getActiveProfile())
+ .sources(AuditService.class);
+ builder.run(args);
+ }
+
+ /**
+ * Get the active profile if none has been specified.
+ */
+ public static String getActiveProfile() {
+ String springProfile = System.getProperty(SPRING_PROFILE);
+ if (springProfile == null) {
+ springProfile = System.getenv(SPRING_PROFILE);
+ }
+ if (springProfile == null) {
+ Properties props = loadProperties();
+ springProfile = props.getProperty(SPRING_PROFILE);
+ if (springProfile == null) {
+ springProfile = "eclipseLink";
+ }
+ }
+ return springProfile;
+ }
+
+ private static Properties loadProperties() {
+ Properties props = new Properties();
+ String env = System.getProperty("env");
+ if (env == null) {
+ env = System.getenv("env");
+ }
+ StringBuilder sb = new StringBuilder("catalog-");
+ if (env != null) {
+ sb.append(env);
+ }
+ sb.append("config.properties");
+ InputStream is = ProfileUtil.class.getClassLoader().getResourceAsStream(sb.toString());
+ if (is != null) {
+ try {
+ props.load(is);
+ } catch (IOException ioe) {
+ //Ignore the error.
+ }
+ }
+ return props;
+ }
+
+}
diff --git a/audit-service/src/main/resources/log4j2.xml b/audit-service/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..e342766
--- /dev/null
+++ b/audit-service/src/main/resources/log4j2.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+~ Licensed to the Apache Software Foundation (ASF) under one or more
+~ contributor license agreements. See the NOTICE file distributed with
+~ this work for additional information regarding copyright ownership.
+~ The ASF 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.
+-->
+<Configuration status="ERROR">
+ <properties>
+ <property name="LOG_DIR">logs/AuditService</property>
+ </properties>
+ <MarkerFilter marker="Audit" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
+ <Appenders>
+ <RollingFile name="log4j" fileName="${LOG_DIR}/log4j.txt" filePattern="${LOG_DIR}/archive/log4j.txt.%d{yyyyMMdd_HHmmss}-%i">
+ <PatternLayout>
+ <MarkerPatternSelector defaultPattern="%d [%t] %-5p %X{loginId, userId, ipAddress, corpAcctNumber} %C{1.}.%M:%L - %m%n">
+ <PatternMatch key="FLOW" pattern="%d [%t] %-5p %X{loginId, userId, ipAddress, corpAcctNumber} -------- %C{1.}.%M:%L %msg --------%n"/>
+ </MarkerPatternSelector>
+ </PatternLayout>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="30 MB"/>
+ </Policies>
+ <!-- A max of 20 will allow 20 files per second with the date pattern specified on the RollingFile declaration.
+ Hopefully that is a ridiculous value -->
+ <DefaultRolloverStrategy min="1" max="20">
+ <Delete basePath="${LOG_DIR}/archive">
+ <!-- Nested conditions: the inner condition is only evaluated on files for which the outer conditions are true. -->
+ <IfFileName glob="log4j.txt.*">
+ <!-- Only allow 1 GB of files to accumulate -->
+ <IfAccumulatedFileSize exceeds="1 GB"/>
+ </IfFileName>
+ </Delete>
+ </DefaultRolloverStrategy>
+ </RollingFile>
+ <RollingFile name="audit" fileName="${LOG_DIR}/audit.log" filePattern="${LOG_DIR}/archive/audit.log.%d{yyyyMMdd_HHmmss}-%i">
+ <RFC5424Layout enterpriseNumber="50177" includeMDC="true" mdcId="RequestContext" appName="Platform"
+ mdcPrefix=""/>
+ <Policies>
+ <SizeBasedTriggeringPolicy size="30 MB"/>
+ </Policies>
+ <!-- A max of 20 will allow 20 files per second with the date pattern specified on the RollingFile declaration.
+ Hopefully that is a ridiculous value -->
+ <DefaultRolloverStrategy min="1" max="20">
+ <Delete basePath="${LOG_DIR}/archive">
+ <!-- Nested conditions: the inner condition is only evaluated on files for which the outer conditions are true. -->
+ <IfFileName glob="audit.log.*">
+ <!-- Only allow 1 GB of files to accumulate -->
+ <IfAccumulatedFileSize exceeds="1 GB"/>
+ </IfFileName>
+ </Delete>
+ </DefaultRolloverStrategy>
+ </RollingFile>
+ </Appenders>
+ <Loggers>
+ <Logger name="org.apache.logging.log4j.audit" level="info" additivity="false">
+ <AppenderRef ref="log4j"/>
+ </Logger>
+ <Logger name="AuditLogger" level="trace" additivity="false">
+ <AppenderRef ref="audit"/>
+ </Logger>
+ <Root level="DEBUG">
+ <AppenderRef ref="log4j" />
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index cc9b420..5849f86 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,6 +38,7 @@
<log4j-audit.version>1.0.0-SNAPSHOT</log4j-audit.version>
<slf4j.version>1.6.2</slf4j.version>
<spring.version>4.3.3.RELEASE</spring.version>
+ <spring.boot.version>1.5.10.RELEASE</spring.boot.version>
</properties>
<dependencyManagement>
<dependencies>
@@ -78,6 +79,11 @@
<version>${log4j.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <version>${log4j.version}</version>
+ </dependency>
+ <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
@@ -172,6 +178,21 @@
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.modelmapper</groupId>
+ <artifactId>modelmapper</artifactId>
+ <version>0.7.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.modelmapper.extensions</groupId>
+ <artifactId>modelmapper-spring</artifactId>
+ <version>0.7.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.modelmapper.extensions</groupId>
+ <artifactId>modelmapper-jackson</artifactId>
+ <version>0.7.5</version>
+ </dependency>
</dependencies>
</dependencyManagement>
@@ -407,6 +428,7 @@
<modules>
<module>audit-service-war</module>
<module>audit-service-api</module>
+ <module>audit-service</module>
<module>sample-app</module>
</modules>
</project>