Skip to content
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

add json logging to tomcat 7 with java 8 #203

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tomcat-base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ subprojects {
implementation "org.apache.tomcat:tomcat-jasper:${tomcatVersion}"
implementation "org.apache.tomcat:tomcat-jasper-el:${tomcatVersion}"
implementation "org.apache.tomcat:tomcat-jsp-api:${tomcatVersion}"
// implementation "eu.xenit.logging:json-logging:${jsonLoggingVersion}"
implementation "eu.xenit.logging:json-logging-java-8:${jsonLoggingVersion}"
implementation "com.fasterxml.jackson.core:jackson-databind:2.15.2"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.0"
testImplementation("org.junit-pioneer:junit-pioneer:1.9.1")
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.0"
// sharedLibs("eu.xenit.logging:json-logging:${jsonLoggingVersion}") {
// transitive = false
// }
sharedLibs("eu.xenit.logging:json-logging-java-8:${jsonLoggingVersion}") {
transitive = false
}
}

boolean isRelease = ci.branch?.equals("master")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/bin/bash

currentDate=$(date +%s)
if [ -z "${BUILD_DATE}" ]
then
1>&2 echo "$(tput -Txterm setaf 3)"'{ "timestamp" : '"$(date -d @$currentDate +"%s")"' ,"severity" : "WARN", "type" : "application","component" : "docker-entrypoint" ,"fullMessage" : "Unable to determine image age: BUILD_DATE is not set"}'"$(tput -Txterm sgr0)"
if [ -z "${BUILD_DATE}" ]; then
echo '{ "timestamp" : '"$(date -d @$currentDate +"%s")"' ,"severity" : "WARN", "type" : "application","component" : "docker-entrypoint" ,"fullMessage" : "Unable to determine image age: BUILD_DATE is not set"}'
else
printf -v buildDate "%.0f\n" "$BUILD_DATE"
timeelapsed=`expr ${currentDate} - ${buildDate}`
if [ $timeelapsed -ge 2592000 ] # 30 days
then
1>&2 echo "$(tput -Txterm setaf 3)"'{ "timestamp" : '"$(date -d @$currentDate +"%s")"' ,"severity" : "WARN", "type" : "application","component" : "docker-entrypoint" , "fullMessage" : "This is an old image: BUILD_DATE='"$(date -d @$BUILD_DATE +"%Y-%m-%d %H:%M:%S")"' and currentDate='"$(date -d @$currentDate +"%Y-%m-%d %H:%M:%S")"'"}'"$(tput -Txterm sgr0)"
fi
printf -v buildDate "%.0f\n" "$BUILD_DATE"
timeelapsed=$(expr ${currentDate} - ${buildDate})
if [ $timeelapsed -ge 2592000 ]; then # 30 days
echo '{ "timestamp" : '"$(date -d @$currentDate +"%s")"' ,"severity" : "WARN", "type" : "application","component" : "docker-entrypoint" , "fullMessage" : "This is an old image: BUILD_DATE='"$(date -d @$BUILD_DATE +"%Y-%m-%d %H:%M:%S")"' and currentDate='"$(date -d @$currentDate +"%Y-%m-%d %H:%M:%S")"'"}'
fi
fi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package eu.xenit.alfresco.tomcat.embedded;

import eu.xenit.alfresco.tomcat.embedded.alfresco.tomcat.AlfrescoTomcatCustomizer;
import eu.xenit.alfresco.tomcat.embedded.config.TomcatConfiguration;
import eu.xenit.alfresco.tomcat.embedded.config.DefaultConfigurationProvider;
import eu.xenit.alfresco.tomcat.embedded.config.EnvironmentVariableConfigurationProvider;
import eu.xenit.alfresco.tomcat.embedded.config.TomcatConfiguration;
import eu.xenit.alfresco.tomcat.embedded.share.tomcat.ShareTomcatCustomizer;
import eu.xenit.alfresco.tomcat.embedded.tomcat.TomcatFactory;
//import eu.xenit.logging.json.jul.JsonFormatter;
import eu.xenit.logging.json.jul.JsonFormatter;
import org.apache.catalina.startup.Tomcat;

import java.nio.file.Files;
Expand Down Expand Up @@ -67,14 +67,14 @@ public static void configureLoggerToJSONStdOut(Logger logger, String component,
}
};

// if (json) {
// JsonFormatter formatter = new JsonFormatter();
// formatter.setType("application");
// formatter.setComponent(component);
// formatter.setExtractStackTrace("true");
// formatter.setFilterStackTrace(true);
// customHandler.setFormatter(formatter);
// }
if (json) {
JsonFormatter formatter = new JsonFormatter();
formatter.setType("application");
formatter.setComponent(component);
formatter.setExtractStackTrace("true");
formatter.setFilterStackTrace(true);
customHandler.setFormatter(formatter);
}

logger.addHandler(customHandler);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
package eu.xenit.alfresco.tomcat.embedded.healthcheck;

import eu.xenit.alfresco.tomcat.embedded.config.TomcatConfiguration;
import eu.xenit.alfresco.tomcat.embedded.config.DefaultConfigurationProvider;
import eu.xenit.alfresco.tomcat.embedded.config.EnvironmentVariableConfigurationProvider;
import eu.xenit.alfresco.tomcat.embedded.config.TomcatConfiguration;

import java.io.IOException;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.http.HttpClient;
import java.net.http.HttpClient.Version;
import java.net.http.HttpConnectTimeoutException;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse.BodyHandlers;
import java.time.Duration;
import java.util.Objects;

public class HealthCheck {
public static final String ALFRESCO_DEFAULT_LIVE_PROBE = "http://localhost:8080/alfresco";
Expand Down Expand Up @@ -44,7 +36,7 @@ public static void main(String[] args) throws IOException, InterruptedException
private static int healthCheck(String endpoint, int statusCode, String[] args) throws IOException, InterruptedException {
HealthCheckSpec spec = HealthCheck.setupHealthCheck(endpoint, statusCode, args);
int exitCode = doHealthCheck(spec);
if(exitCode != 0) {
if (exitCode != 0) {
System.exit(exitCode);
}
return exitCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
package eu.xenit.alfresco.tomcat.embedded.tomcat;

import static eu.xenit.alfresco.tomcat.embedded.utils.Utils.redirectLog4j;

import eu.xenit.alfresco.tomcat.embedded.config.TomcatConfiguration;
//import eu.xenit.logging.json.valve.JsonAccessLogValve;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
import eu.xenit.logging.json.valve.JsonAccessLogValve;
import org.apache.catalina.Host;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
Expand All @@ -19,10 +10,19 @@
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.loader.WebappLoader;
import org.apache.catalina.startup.Tomcat;
import org.apache.coyote.http11.Http11NioProtocol;
import org.apache.coyote.http11.Http11Protocol;
import org.apache.naming.resources.VirtualDirContext;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

import static eu.xenit.alfresco.tomcat.embedded.utils.Utils.redirectLog4j;

public class TomcatFactory {

private final TomcatConfiguration configuration;
Expand Down Expand Up @@ -118,11 +118,11 @@ private void addWebapp(Tomcat tomcat, Path path) {
};
ctx.addLifecycleListener(lifecycleListener);

// if (getConfiguration().isAccessLogging()) {
// JsonAccessLogValve valve = new JsonAccessLogValve();
// ctx.addValve(valve);
// ctx.getAccessLog();
// }
if (getConfiguration().isAccessLogging()) {
JsonAccessLogValve valve = new JsonAccessLogValve();
ctx.addValve(valve);
ctx.getAccessLog();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package eu.xenit.alfresco.tomcat.embedded.alfresco.tomcat;

import static org.junit.jupiter.api.Assertions.assertEquals;

import eu.xenit.alfresco.tomcat.embedded.alfresco.config.AlfrescoConfiguration;
import eu.xenit.alfresco.tomcat.embedded.alfresco.config.DefaultAlfrescoConfigurationProvider;
import eu.xenit.alfresco.tomcat.embedded.config.ConfigurationProvider;
import eu.xenit.alfresco.tomcat.embedded.config.DefaultConfigurationProvider;
import eu.xenit.alfresco.tomcat.embedded.config.TomcatConfiguration;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;


class AlfrescoTomcatFactoryHelperTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package eu.xenit.alfresco.tomcat.embedded.share.tomcat;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

import eu.xenit.alfresco.tomcat.embedded.config.DefaultConfigurationProvider;
import eu.xenit.alfresco.tomcat.embedded.config.TomcatConfiguration;
import eu.xenit.alfresco.tomcat.embedded.share.config.DefaultShareConfigurationProvider;
import eu.xenit.alfresco.tomcat.embedded.share.config.ShareConfiguration;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetEnvironmentVariable;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
Expand All @@ -15,8 +15,9 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetEnvironmentVariable;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;


class ShareTomcatFactoryHelperTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package eu.xenit.alfresco.tomcat.embedded.utils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class UtilsTest {

Expand Down