Skip to content

Commit

Permalink
Merge pull request #2 from SolaceLabs/updates
Browse files Browse the repository at this point in the history
Long overdue updates
  • Loading branch information
aaron-613 authored Oct 14, 2024
2 parents 4045c3e + 2d47e43 commit 80d04a6
Show file tree
Hide file tree
Showing 9 changed files with 719 additions and 589 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ bin/

# Ignore VSCode settings folder
.vscode/

# Ignore IntelliJ stuff
log4j-solace-appender.iml
log4j-solace-appender.ipr
log4j-solace-appender.iws
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,38 @@
# Solace Appender for log4j 2.14+
# Solace Appender for log4j2

Hello! This is the first cut at an Appender for log4j2. It can use either Direct messaging or Guaranteed (but does not attempt redelivery). And the published **topic is completely dynamic!** E.g.:
This is a Solace PubSub+ Appender for log4j2. It can use either Direct messaging, or Guaranteed (but does not attempt redelivery if a NACK is received). The published **topic is completely dynamic!** E.g.:

```
log4j-log/AaronsThinkPad3-12540/INFO/pub-thread/com/solacesystems/jcsmp/protocol/impl/TcpClientChannel
| | | | |-->
hostname-PID/level/thread-name/class......
hostname-PID/level/thread-name/class......
(or app name)
```

So much better than crappy JMS and Kafka publishers that just publish to a fixed static topic!
So much better than crappy JMS and Kafka publishers that just publish to a fixed static topic, like "logs" or "systemXYZ.logs"! Same with most of the MQTT ones I've found online. The topic structure is currently hard-coded, but perhaps a future version will allow it to be specified, similar to the PatternLayout.

I should make an MQTT version as well, since MQTT also supports awesome dynamic hierarchical topics.
This multi-level topic structure allows you to do things like:

- Subscribe to all WARNs: `log4j*/*/WARN/>`
- Subscribe to logs from Aaron's machines: `log4j*/Aaron*/>`
- Subscribe to any log from the main thread: `log4j*/*/*/main/>`
- Subscribe to any exception: `log4j-exc/>`

I should make a better MQTT version as well, since MQTT also supports awesome dynamic hierarchical topics. Although MQTT doesn't support prefix-wildcards.



## Options

For example, in your log4j2.xml file, specify a `Solace` Appender, something like:
As an example, in your log4j2.xml file, specify a `Solace` Appender, something like:

```
...
<Appenders>
<Solace name="solaceLogger" host="192.168.42.35" vpn="logs" username="test" password="secret">
<Solace name="solaceLogger" host="tcp://192.168.42.35" vpn="logs" username="test" password="secret" appName="${sys:appName:DefaultAppName}">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<!--JSONLayout/-->
</Solace>
</Appenders>
<Loggers>
Expand All @@ -37,10 +43,15 @@ For example, in your log4j2.xml file, specify a `Solace` Appender, something lik
...
```

- `host`: hostname or IP address of the Solace broker (default="`localhost`")
- `host`: hostname or IP address of the Solace broker (default="`tcp://localhost:55555`")
- `vpn`: Message VPN to connect to (default="`default`")
- `username`: Client username to connect with (default="`default`")
- `password`: Password for client connection, if required (default="")
- `direct`: ["true"|"false"] Whether to use Direct or Guaranteed messages (default="`false`")
- `appName`: Custom string to use instead of "hostname+pid" in topic



## Shadow MegaJAR bundle

Has JCSMP 10.22.0 bundled inside, makes importing the Appender into other Solace projects easier. Using 10.22 as there's a bug in the current JCSMP version that breaks something during log4j's static initialization.
28 changes: 25 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ plugins {
// Apply the java-library plugin for API and implementation separation.
id 'java-library'
id 'eclipse'
id 'idea'
id 'com.gradleup.shadow' version '8.3.2' // https://gradleup.com/shadow/
}

repositories {
Expand All @@ -18,15 +20,16 @@ repositories {

dependencies {

implementation group: 'com.solacesystems', name: 'sol-jcsmp', version: '10.+'
//implementation group: 'com.solacesystems', name: 'sol-jcsmp', version: '10.+'
implementation group: 'com.solacesystems', name: 'sol-jcsmp', version: '10.22.+'
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.+'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.+'
annotationProcessor group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.+'
//implementation group: 'org.apache.logging.log4j', name: 'log4j-jcl', version: '2.14.1'


// Use JUnit test framework.
testImplementation 'junit:junit:4.13'
testImplementation 'junit:junit:4.+'

// This dependency is exported to consumers, that is to say found on their compile classpath.
//api 'org.apache.commons:commons-math3:3.6.1'
Expand All @@ -35,11 +38,30 @@ dependencies {
//implementation 'com.google.guava:guava:29.0-jre'
}

sourceSets {
main {
java {
srcDir 'src/main/java'
}
}
}

jar {
archiveVersion = '0.0.2'
archiveVersion = '0.0.4'
manifest {
attributes 'Created-By': 'Aaron @ Solace',
'Implementation-Title': 'log4j2 Solace Appender'
}
}

// Output to build/libs/shadow.jar
tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
//archiveBaseName.set('shadow')
archiveClassifier.set('mega')
archiveVersion.set('0.0.4')
}

task deps(type: Copy) {
from sourceSets.main.runtimeClasspath
into 'build/deps/'
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
17 changes: 9 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -144,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -201,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
*/

rootProject.name = 'log4j-solace-appender'
include('lib')
//include('lib')
Loading

0 comments on commit 80d04a6

Please sign in to comment.