Skip to content

Commit

Permalink
Fix for issue 49 (#50)
Browse files Browse the repository at this point in the history
* Fix for issue 46

Implementation to add a flag to know when the NotificationListener has been registered to prevent further registrations from happening in the future

* Added java doc to start() method and synchronize block to prevent multiple notification listeners from being created due to parallelism

---------

Co-authored-by: Tanner Sherman <tanner.sherman@avioconsulting.com>
  • Loading branch information
tannersherman and tannersherman authored Mar 21, 2023
1 parent c20126c commit 0c894ac
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ One of the reasons for developing this custom module is to feed JSON logs to log
* Tracepoints compatibility to measure request, response times and such.

# Changes
## 2.1.1
* Fixes
- Fixed implementation to only create and register one Notification Listener. Duplicates were being created and registered leading to duplicate flow logs
## 2.1.0
* Added
- Implementation to optionally compress or encrypt the payload within the logger operations
Expand Down Expand Up @@ -108,24 +111,16 @@ To use the timer scope, pull it in from the AVIO Core section of the palette and
After that, check the App Level properties and validate they're what you desire. Now you're good to go!

# Using the Custom Logger Notification Listener
The custom logger notification listener implements an interface that allows it to be notified when flows start and end. It's also able to retrieve
your ```avio-core:config``` global element and match its App Level properties to your custom loggers'. Note that (unless overriden)
all flow start/stop messages will have a category suffix of ```.flow```.
The custom logger notification listener implements an interface that allows it to be notified when flows start and end. It's also able to retrieve your `avio-logger:config` global element and match its App Level properties to your custom loggers'. Note that (unless overriden)
all flow start/stop messages will have a category suffix of `.flow`.

To use the custom logger notification listener, you must instantiate the object inside your Mule runtime. You do this by using the ```<object>```
global element. An example has been included below:
To use the custom logger notification listener navigate to your logger's global configuration and check the box for `Enable Flow Logs`

```xml

<object doc:name="Object" doc:id="4df721fe-16b2-4ce3-819e-878fb4dd53c1"
name="CustomLoggerNotificationListener"
class="com.avioconsulting.mule.logger.internal.listeners.CustomLoggerNotificationListener"/>
```
You can also override the global configuration elements by specifying properties. The available properties are as follows:
* appName
* appVersion
* env
* category - Note, this completely overrides the category, i.e. it does not use the ```baseCategory``` from the global configuration
* category - Note, this completely overrides the category, i.e. it does not use the `baseCategory` from the global configuration
as a prefix.

# How?
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.avioconsulting.mule</groupId>
<artifactId>mule-custom-logger</artifactId>
<name>Mule Custom Logger</name>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1-SNAPSHOT</version>
<packaging>mule-extension</packaging>
<description>Mule Custom Logger module that provides standard structured logging</description>
<url>https://github.com/${project.github.repository}</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public class CustomLoggerConfiguration implements Startable, Initialisable {
private CustomLogger logger;
private CustomLoggerNotificationListener notificationListener;

private static boolean isNotificationListenerRegistered = false;

public String getApplicationName() {
return applicationName;
}
Expand Down Expand Up @@ -170,16 +172,35 @@ public String getEncryptionPassword() {
return encryptionPassword;
}

/**
* This method is invoked by the MuleSoft application when the AVIO Custom
* Logger is invoked to create the connection.
* It creates a CustomLogger object based on the config properties provided by
* configuration provided in MuleSoft application.
* Static variables are used to prevent more than one notification listener is
* created and registered.
* Synchronized utilized to prevent prallelism from creating more than one
* notification listener
*
* @throws MuleException
*
*/
@Override
public void start() throws MuleException {
classLogger.info("Starting CustomerLoggerConfiguration");
this.logger = new CustomLogger();
classLogger.info("Setting config reference on CustomLoggerRegistrationService");
customLoggerRegistrationService.setConfig(this);
if (isEnableFlowLogs()) {
classLogger.info("Flow logs enabled, creating notification listener");
notificationListener = new CustomLoggerNotificationListener(this);
notificationListenerRegistry.registerListener(notificationListener);
classLogger.info("Flow logs enabled");
synchronized (CustomLoggerConfiguration.class) {
if (!isNotificationListenerRegistered) {
classLogger.info("Creating and registering notification listener");
notificationListener = new CustomLoggerNotificationListener(this);
notificationListenerRegistry.registerListener(notificationListener);
isNotificationListenerRegistered = true;
}
}
} else {
classLogger.info("Flow logs disabled");
}
Expand Down

0 comments on commit 0c894ac

Please sign in to comment.