diff --git a/build.gradle b/build.gradle index 4fff21ec..5b6b34e8 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,7 @@ plugins { id 'war' id 'jacoco' id 'org.ajoberstar.grgit' version '4.1.1' + id 'com.github.johnrengelman.shadow' version '8.1.1' } repositories { @@ -94,28 +95,24 @@ task generateTemplateFileList { } } - -task fatTestJar(type: Jar) { +shadowJar { // Be careful when updating jars - you may want to set the duplicates strategy to WARN // to see if any of the jars are shadowing the others when building the fat jar, which // has been the case in the past duplicatesStrategy = DuplicatesStrategy.EXCLUDE dependsOn generateTemplateFileList - archiveAppendix = 'test-fat' - - // include source files + archiveAppendix = 'test-shadow' from sourceSets.test.output + configurations = [project.configurations.testRuntimeClasspath] - // include all jars - from { - configurations.testimpl.collect { it.isDirectory() ? it : zipTree(it) } - } - + enableRelocation true + relocationPrefix 'us.kbase.auth2.shadow' + + mergeServiceFiles() + // Include text files from the "templates" directory from('templates') { into JAR_TEMPLATE_DIR } from("$buildDir/" + TEMPLATE_LIST_FILE_NAME) { into JAR_TEMPLATE_DIR } - - with jar } task generateManageAuthScript { @@ -217,7 +214,6 @@ dependencies { 'syslog4j-0.9.46' ) // needed for syslog4j - implementation 'net.java.dev.jna:jna:3.4.0' implementation 'joda-time:joda-time:2.3' // ### Test ### diff --git a/src/main/java/us/kbase/auth2/kbase/KBaseAuthConfig.java b/src/main/java/us/kbase/auth2/kbase/KBaseAuthConfig.java index 81e709c8..7c403bcc 100644 --- a/src/main/java/us/kbase/auth2/kbase/KBaseAuthConfig.java +++ b/src/main/java/us/kbase/auth2/kbase/KBaseAuthConfig.java @@ -2,6 +2,7 @@ import java.io.File; import java.io.IOException; +import java.io.PrintWriter; import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Path; @@ -15,6 +16,7 @@ import java.util.regex.Pattern; import org.ini4j.Ini; +import org.productivity.java.syslog4j.SyslogIF; import org.slf4j.LoggerFactory; import us.kbase.auth2.lib.identity.IdentityProviderConfig; @@ -25,6 +27,7 @@ import us.kbase.auth2.service.exceptions.AuthConfigurationException; import us.kbase.common.service.JsonServerSyslog; import us.kbase.common.service.JsonServerSyslog.RpcInfo; +import us.kbase.common.service.JsonServerSyslog.SyslogOutput; public class KBaseAuthConfig implements AuthStartupConfig { @@ -85,16 +88,8 @@ public KBaseAuthConfig() throws AuthConfigurationException { public KBaseAuthConfig(final Path filepath, final boolean nullLogger) throws AuthConfigurationException { final Map cfg = getConfig(filepath); - final String ln = getString(KEY_LOG_NAME, cfg); - if (nullLogger) { - logger = new NullLogger(); - } else { - logger = new JsonServerSysLogAutoLogger(new JsonServerSyslog( - ln == null ? DEFAULT_LOG_NAME : ln, - //TODO KBASECOMMON allow null for the fake config prop arg - "thisisafakekeythatshouldntexistihope", - JsonServerSyslog.LOG_LEVEL_INFO, true)); - } + final String logname = getString(KEY_LOG_NAME, cfg); + logger = nullLogger ? new NullLogger() : buildLogger(logname); try { isTestModeEnabled = TRUE.equals(getString(KEY_TEST_MODE_ENABLED, cfg)); templateDir = Paths.get(getString(KEY_TEMPLATE_DIR, cfg, true)); @@ -125,6 +120,44 @@ public KBaseAuthConfig(final Path filepath, final boolean nullLogger) } } + private SLF4JAutoLogger buildLogger(final String logname) { + // Warning - this code is tested manually. Ensure + // logs are making it to stdout after changing + // TODO LOGGING just remove JsonServerSyslog altogether + // and get rid of Syslog4j. Not sure how much work this'd be + JsonServerSyslog.setStaticUseSyslog(false); + final JsonServerSyslog jssl = new JsonServerSyslog( + logname == null ? DEFAULT_LOG_NAME : logname, + null, + JsonServerSyslog.LOG_LEVEL_INFO, + true + ); + jssl.changeOutput(new SyslogOutput() { + + @Override + public void logToSystem( + final SyslogIF log, + final int level, + final String message) { + System.out.println(String.format( + "[Auth2] Lvl: %s Message: %s", level, message)); + } + + @Override + public PrintWriter logToFile( + final File f, + final PrintWriter pw, + final int level, + final String message) { + System.out.println( + "log to file called - this is not supported and not expected"); + return null; + } + + }); + return new JsonServerSysLogAutoLogger(jssl); + } + private static final String INVALID_CHARS_REGEX = "[^A-Z-]+"; private static final Pattern INVALID_CHARS = Pattern.compile(INVALID_CHARS_REGEX); diff --git a/src/test/java/us/kbase/test/auth2/TestConfigurator.java b/src/test/java/us/kbase/test/auth2/TestConfigurator.java index 437ef331..245d4d62 100644 --- a/src/test/java/us/kbase/test/auth2/TestConfigurator.java +++ b/src/test/java/us/kbase/test/auth2/TestConfigurator.java @@ -67,11 +67,13 @@ private static class TestLogger implements SLF4JAutoLogger { private final JsonServerSyslog logger; public TestLogger() { + JsonServerSyslog.setStaticUseSyslog(false); logger = new JsonServerSyslog( "AuthTestLogger", - //TODO CODE update kbase-common and pass null instead - "thisisafakekeythatshouldntexistihope", - JsonServerSyslog.LOG_LEVEL_INFO, true); + null, + JsonServerSyslog.LOG_LEVEL_INFO, + true + ); logger.changeOutput(new SyslogOutput() { @Override