From d616148b6de559aff7f593db352c9d912ab1fbd5 Mon Sep 17 00:00:00 2001 From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com> Date: Tue, 7 Dec 2021 14:32:45 +0200 Subject: [PATCH] Release 1.0.0: Initial release --- .gitignore | 5 + conf/log4j.xml | 19 ++ conf/log4j2.xml | 89 +++++ conf/logback.xml | 85 +++++ conf/logging.properties | 5 + pom.xml | 314 ++++++++++++++++++ .../jla_02/JavaUtilLoggingLogger.java | 47 +++ src/main/com/teragrep/jla_02/Log4j.java | 26 ++ src/main/com/teragrep/jla_02/Log4j2.java | 40 +++ src/main/com/teragrep/jla_02/Logback.java | 36 ++ src/main/com/teragrep/jla_02/Main.java | 116 +++++++ src/main/com/teragrep/jla_02/Tinylog.java | 17 + 12 files changed, 799 insertions(+) create mode 100644 .gitignore create mode 100644 conf/log4j.xml create mode 100644 conf/log4j2.xml create mode 100644 conf/logback.xml create mode 100644 conf/logging.properties create mode 100644 pom.xml create mode 100644 src/main/com/teragrep/jla_02/JavaUtilLoggingLogger.java create mode 100644 src/main/com/teragrep/jla_02/Log4j.java create mode 100644 src/main/com/teragrep/jla_02/Log4j2.java create mode 100644 src/main/com/teragrep/jla_02/Logback.java create mode 100644 src/main/com/teragrep/jla_02/Main.java create mode 100644 src/main/com/teragrep/jla_02/Tinylog.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f020bd1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.idea/ +dependency-reduced-pom.xml +target/ +jla_02.iml +.flattened-pom.xml diff --git a/conf/log4j.xml b/conf/log4j.xml new file mode 100644 index 0000000..8a943c7 --- /dev/null +++ b/conf/log4j.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + diff --git a/conf/log4j2.xml b/conf/log4j2.xml new file mode 100644 index 0000000..718d923 --- /dev/null +++ b/conf/log4j2.xml @@ -0,0 +1,89 @@ + + + + log4j2-daily + log4j2-audit + log4j2-metric + jla_02 + localhost + 01 + + + + + + DENY + ACCEPT + + + + %d{dd.MM.yyyy HH:mm:ss.SSS} [%level] %logger [instanceId=${INSTANCE_ID}, thread=%thread, userId=%X{security.user.id}, sessionId=%X{session.id}, requestId=%X{security.request.id}, SUBJECT=%X{audit.subject}, VERB=%X{audit.verb}, OBJECT=%X{audit.object}, OUTCOME=%X{audit.outcome}, message=%msg]%ex{0}%n + + + + + + DENY + ACCEPT + + + + %d{dd.MM.yyyy HH:mm:ss.SSS} [%level] %logger [instanceId=${INSTANCE_ID}, thread=%thread, userId=%X{security.user.id}, sessionId=%X{session.id}, requestId=%X{security.request.id}, SUBJECT=%X{audit.subject}, VERB=%X{audit.verb}, OBJECT=%X{audit.object}, OUTCOME=%X{audit.outcome}, message=%msg]%ex{0}%n + + + + + + DENY + ACCEPT + + + + %d{dd.MM.yyyy HH:mm:ss.SSS} [%level] %logger [instanceId=${INSTANCE_ID}, thread=%thread, userId=%X{security.user.id}, sessionId=%X{session.id}, requestId=%X{security.request.id}, SUBJECT=%X{audit.subject}, VERB=%X{audit.verb}, OBJECT=%X{audit.object}, OUTCOME=%X{audit.outcome}, message=%msg]%ex{0}%n + + + + + + + + + + + diff --git a/conf/logback.xml b/conf/logback.xml new file mode 100644 index 0000000..ed950c8 --- /dev/null +++ b/conf/logback.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + %d{dd.MM.yyyy HH:mm:ss.SSS} [%level] %logger [thread=%thread, message=%msg]%n + + + + + + + localhost + 1666 + true + logback-daily + javalogger-example + 5000 + 2000 + 15000 + + %-4relative %X{requestId} [%thread] %-5level %logger{35} Daily - %msg + + + + DAILY + + DENY + ACCEPT + + + + + localhost + 1666 + true + logback-metric + javalogger-example + 5000 + 2000 + 15000 + + %-4relative %X{requestId} [%thread] %-5level %logger{35} Metric - %msg + + + + METRIC + + DENY + ACCEPT + + + + + localhost + 1666 + true + logback-audit + javalogger-example + 5000 + 2000 + 15000 + + %-4relative %X{requestId} [%thread] %-5level %logger{35} Audit - %msg + + + + AUDIT + + DENY + ACCEPT + + + + + + + + + diff --git a/conf/logging.properties b/conf/logging.properties new file mode 100644 index 0000000..b084103 --- /dev/null +++ b/conf/logging.properties @@ -0,0 +1,5 @@ +java.util.logging.RelpHandler.default.server.address=127.0.0.1 +java.util.logging.RelpHandler.default.server.port=1666 +java.util.logging.RelpHandler.default.appname=jla_04 +java.util.logging.RelpHandler.default.hostname=javalogger-example +java.util.logging.SimpleFormatter.format=[%4$s]: %5$s [%1$tc] diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..140759c --- /dev/null +++ b/pom.xml @@ -0,0 +1,314 @@ + + jar + 4.0.0 + com.teragrep + jla_02 + ${revision}${sha1}${changelist} + + UTF-8 + UTF-8 + 0.0.1 + -SNAPSHOT + + 1.8 + 1.8 + 1.8 + + + + Apache License 2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + Esa Hiltunen + 9@teragrep.com + Teragrep + https://teragrep.com + + + + scm:git:https://github.com/teragrep/jla_02.git + scm:git:git@github.com:teragrep/jla_02.git + https://github.com/teragrep/jla_02/tree/master + + + + + maven-shade-plugin + 3.2.4 + + + package + + shade + + + + + com.teragrep.jla_02.Main + + + + + + * + + module-info.class + META-INF/*.MF + META-INF/DEPENDENCIES + META-INF/LICENSE + META-INF/NOTICE + + **/Log4j2Plugins.dat + + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + 8 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + all + true + 10 + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.0.0-M5 + + + + integration-test + verify + + + + + + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + false + + + + org.codehaus.mojo + flatten-maven-plugin + 1.1.0 + + true + resolveCiFriendliesOnly + + + + flatten + process-resources + + flatten + + + + flatten.clean + clean + + clean + + + + + + + + + com.teragrep + rlp_01 + 1.0.8 + + + com.cloudbees + syslog-java-client + 1.1.7 + + + com.teragrep + jla_01 + 1.3.8 + + + com.teragrep + jla_04 + 1.2.1 + + + com.teragrep + jla_05 + 1.0.0 + + + com.teragrep + jla_06 + 1.0.2 + + + org.tinylog + tinylog + 1.3.5 + + + ch.qos.logback + logback-core + 1.2.3 + + + org.slf4j + slf4j-api + 1.7.25 + + + ch.qos.logback + logback-classic + 1.2.3 + + + org.apache.logging.log4j + log4j-api + 2.14.1 + + + org.apache.logging.log4j + log4j-core + 2.14.1 + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.14.1 + runtime + + + org.apache.logging.log4j + log4j-web + 2.14.1 + runtime + + + log4j + log4j + 1.2.17 + + + + + publish-maven-central + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + Central Repository OSSRH + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + publish-github-packages + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + + + + + + github + GitHub Packages + https://maven.pkg.github.com/teragrep/jla_02 + + + + + diff --git a/src/main/com/teragrep/jla_02/JavaUtilLoggingLogger.java b/src/main/com/teragrep/jla_02/JavaUtilLoggingLogger.java new file mode 100644 index 0000000..a215aae --- /dev/null +++ b/src/main/com/teragrep/jla_02/JavaUtilLoggingLogger.java @@ -0,0 +1,47 @@ +package com.teragrep.jla_02; + +import com.teragrep.jla_04.*; + +import java.io.*; +import java.util.concurrent.TimeoutException; +import java.util.logging.*; + +public class JavaUtilLoggingLogger { + static { + } + static Logger logger = Logger.getLogger(JavaUtilLoggingLogger.class.getName()); + public JavaUtilLoggingLogger() { + InputStream inputStream = null; + try { + inputStream = new FileInputStream(System.getProperty("user.dir") + "/conf/logging.properties"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + try { + LogManager.getLogManager().readConfiguration(inputStream); + } + catch (IOException e) { + System.out.println("Can't read conf/logging.properties: " + e.getMessage()); + } + RelpHandler handler = null; + try { + handler = new RelpHandler(); + } catch (NoSuchFieldException | IOException | TimeoutException | ClassNotFoundException | InstantiationException | IllegalAccessException e) { + e.printStackTrace(); + } + LogManager.getLogManager().reset(); + logger.addHandler(handler); + } + + public void Log() { + try { + logger.info("JavaUtilLoggingLogger info says hi"); + logger.warning("JavaUtilLoggingLogger warning says hi"); + logger.severe("JavaUtilLoggingLogger severe says hi"); + } + catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } +} diff --git a/src/main/com/teragrep/jla_02/Log4j.java b/src/main/com/teragrep/jla_02/Log4j.java new file mode 100644 index 0000000..e42eb10 --- /dev/null +++ b/src/main/com/teragrep/jla_02/Log4j.java @@ -0,0 +1,26 @@ +package com.teragrep.jla_02; + +import org.apache.log4j.Logger; +import org.apache.log4j.xml.DOMConfigurator; + +public class Log4j { + + private static Logger logger; + + public Log4j() { + DOMConfigurator.configure("conf/log4j.xml"); + logger = Logger.getLogger(Log4j.class); + } + + public void Log() { + try { + logger.info("Log4j info says hi!"); + logger.warn("Log4j warn says hi!"); + logger.error("Log4j error says hi!"); + } + catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } +} diff --git a/src/main/com/teragrep/jla_02/Log4j2.java b/src/main/com/teragrep/jla_02/Log4j2.java new file mode 100644 index 0000000..44dec5e --- /dev/null +++ b/src/main/com/teragrep/jla_02/Log4j2.java @@ -0,0 +1,40 @@ +package com.teragrep.jla_02; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; +import org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory; +import org.apache.logging.log4j.LogManager; + +public class Log4j2 { + private static Logger logger; + private static Marker LOG_AUDIT; + private static Marker LOG_DAILY; + private static Marker LOG_METRIC; + + public Log4j2() { + System.setProperty(XmlConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "conf/log4j2.xml"); + logger = LogManager.getLogger(Log4j2.class); + LOG_AUDIT = MarkerManager.getMarker("AUDIT"); + LOG_DAILY = MarkerManager.getMarker("DAILY"); + LOG_METRIC = MarkerManager.getMarker("METRIC"); + } + + public void Log() { + try { + logger.info(LOG_AUDIT, "Log4j2 info audit says hi!"); + logger.info(LOG_DAILY, "Log4j2 info daily says hi!"); + logger.info(LOG_METRIC, "Log4j2 info metric says hi!"); + logger.warn(LOG_AUDIT, "Log4j2 warn audit says hi!"); + logger.warn(LOG_DAILY, "Log4j2 warn daily says hi!"); + logger.warn(LOG_METRIC, "Log4j2 warn metric says hi!"); + logger.error(LOG_AUDIT, "Log4j2 error audit says hi!"); + logger.error(LOG_DAILY, "Log4j2 error daily says hi!"); + logger.error(LOG_METRIC, "Log4j2 error metric says hi!"); + } + catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } +} diff --git a/src/main/com/teragrep/jla_02/Logback.java b/src/main/com/teragrep/jla_02/Logback.java new file mode 100644 index 0000000..aa667e6 --- /dev/null +++ b/src/main/com/teragrep/jla_02/Logback.java @@ -0,0 +1,36 @@ +package com.teragrep.jla_02; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Marker; +import org.slf4j.MarkerFactory; +import ch.qos.logback.classic.util.ContextInitializer; + +public class Logback { + private static Logger logger; + private static Marker LOG_AUDIT = MarkerFactory.getMarker("AUDIT"); + private static Marker LOG_DAILY = MarkerFactory.getMarker("DAILY"); + private static Marker LOG_METRIC = MarkerFactory.getMarker("METRIC"); + private int counter; + + public Logback() { + System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, "conf/logback.xml"); + logger = LoggerFactory.getLogger(Logback.class); + LOG_AUDIT = MarkerFactory.getMarker("AUDIT"); + LOG_DAILY = MarkerFactory.getMarker("DAILY"); + LOG_METRIC = MarkerFactory.getMarker("METRIC"); + + } + + public void Log() { + try { + logger.info(LOG_AUDIT, "Logback-audit says hi."); + logger.info(LOG_DAILY, "Logback-daily says hi."); + logger.info(LOG_METRIC, "Logback-metric says hi."); + } + catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } +} diff --git a/src/main/com/teragrep/jla_02/Main.java b/src/main/com/teragrep/jla_02/Main.java new file mode 100644 index 0000000..28ac838 --- /dev/null +++ b/src/main/com/teragrep/jla_02/Main.java @@ -0,0 +1,116 @@ +package com.teragrep.jla_02; + +import java.text.SimpleDateFormat; + +public class Main { + public static void main(String[] args) { + final int sleep_duration = (System.getenv("SLEEP_DURATION") == null) ? 5 : Integer.parseInt(System.getenv("SLEEP_DURATION")); + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + Thread Log4j2 = new Thread( + new Runnable(){ + public void run(){ + System.out.println("Starting Log4j2"); + Log4j2 log4j2 = new Log4j2(); + while(true) { + try { + log4j2.Log(); + Thread.sleep(sleep_duration * 1000); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } + } + } + } + ); + //Log4j2.start(); + + Thread Log4j = new Thread( + new Runnable(){ + public void run(){ + System.out.println("Starting Log4j"); + Log4j log4j = new Log4j(); + while(true) { + try { + log4j.Log(); + Thread.sleep(sleep_duration * 1000); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } + } + } + } + ); + //Log4j.start(); + + Thread JavaUtilLoggingLogger = new Thread( + new Runnable(){ + public void run(){ + System.out.println("Starting JavaUtilLoggingLogger"); + JavaUtilLoggingLogger javautillogginglogger = new JavaUtilLoggingLogger(); + while(true) { + try { + javautillogginglogger.Log(); + Thread.sleep(sleep_duration * 1000); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } + } + } + } + ); + JavaUtilLoggingLogger.start(); + + Thread Logback = new Thread( + new Runnable(){ + public void run(){ + System.out.println("Starting Logback"); + Logback logback = new Logback(); + while(true) { + try { + logback.Log(); + Thread.sleep(sleep_duration * 1000); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } + } + + } + } + ); + //Logback.start(); + + Thread Tinylog = new Thread( + new Runnable() { + public void run() { + System.out.println("Starting Tinylog"); + Tinylog tinylog = new Tinylog(); + while (true) { + try { + tinylog.Log(); + Thread.sleep(sleep_duration * 1000); + } catch (InterruptedException e) { + e.printStackTrace(); + System.exit(1); + } + } + } + } + ); + // Tinylog.start(); // WIP + + while(true) { + try { + Thread.sleep(1000000); + } + catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + } +} diff --git a/src/main/com/teragrep/jla_02/Tinylog.java b/src/main/com/teragrep/jla_02/Tinylog.java new file mode 100644 index 0000000..cc16a09 --- /dev/null +++ b/src/main/com/teragrep/jla_02/Tinylog.java @@ -0,0 +1,17 @@ +package com.teragrep.jla_02; + +import org.pmw.tinylog.Logger; + +public class Tinylog { + public void Log() { + try { + Logger.info("Tinylog info says hi!"); + Logger.warn("Tinylog warn says hi!"); + Logger.error("Tinylog error says hi!"); + } + catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } +}