Skip to content

NIFI-16572 Enable per Process Group logging in MiNiFi Java - #11912

Merged
exceptionfactory merged 3 commits into
apache:mainfrom
Vinz2168:NIFI-16572
Nov 21, 2026
Merged

exceptionfactory merged 3 commits into
apache:mainfrom
Vinz2168:NIFI-16572

Conversation

@Vinz2168

Copy link
Copy Markdown
Contributor

Summary

NIFI-16572

MiNiFi Java already contains the framework side of per Process Group logging (NIFI-3065): StandardProcessGroup keeps the logFileSuffix from the flow and StandardComponentLog attaches it as a key/value pair to every component log event. The distribution, however, does not ship the routing pieces, so a logFileSuffix set in flow.json currently has no effect.

This PR:

  • adds nifi-per-process-group-logging (containing NifiDiscriminator) to minifi-assembly and includes it in lib/ through both dependencies.xml and dependencies-windows-service.xml. The bootstrap classpath already includes lib/* on both minifi.sh and the Windows scripts, so the bootstrap can also resolve the discriminator when it reads the shared logback.xml;
  • adds a DEDICATED_LOGGING SiftingAppender to the default MiNiFi conf/logback.xml, referenced by <root>. Files are named ${app.file.name}-<suffix>.${app.file.extension} (by default minifi-app-<suffix>.log) and use the same rolling limits as APP_FILE (10MB / 10 files / 100MB, gzip).

As in NiFi, only messages emitted through the component getLogger() are routed; events without a suffix are ignored by the discriminator.

Manual verification on a built assembly: a flow with a child Process Group with "logFileSuffix": "foo" (GenerateFlowFile -> LogMessage) and a control GenerateFlowFile -> LogMessage in the root group. logs/minifi-app-foo.log contained only the child group messages, logs/minifi-app.log contained both, and no logback configuration errors were reported by bootstrap or runtime.

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000
  • Pull request contains commits signed with a registered key indicating Verified status

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using ./mvnw clean install -P contrib-check
    • JDK 21
    • JDK 25

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

🤖 Generated with Claude Code

@exceptionfactory exceptionfactory left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for proposing this addition @Vinz2168.

The approach follows the implementation in the main NiFi project, but it raises a question about the value of the feature for MiNiFi.

The general design focus of MiNiFi is a smaller footprint, and more focused flow design. This raises the question about the necessity of having more than one application log, and breaking it out at the Process Group level.

Can you provide some additional details around the proposed use case?

As the Jira issue describes, it is possible to do this with manual configuration, which is not as convenient, but this raises the question about the applicability of per-process-group logging as a general default for MiNiFi.

@pvillard31 pvillard31 added the minifi Pull requests that updates minifi/c2 codes label Nov 16, 2026
@Vinz2168

Copy link
Copy Markdown
Contributor Author

Thanks for the review @exceptionfactory, that's a fair point, so let me clarify the scope of the change and the use case.

What the change actually involves

The PR does not touch any MiNiFi code. It only:

  1. adds the existing nifi-per-process-group-logging jar (~8 KB, a single Discriminator class depending only on slf4j/logback, which are already in lib/) to the MiNiFi assembly, and
  2. adds a SiftingAppender definition to the default logback.xml.

The framework side is already present in MiNiFi today: StandardComponentLog already resolves the Process Group log file suffix and attaches it to the logging event. The only missing piece is the discriminator class on the classpath. That's why the manual workaround needs both copying the jar into lib/ and editing logback.xml, and the jar step has to be repeated on every upgrade.

Footprint / default behavior

I agree that per-PG logging shouldn't be a default for MiNiFi, so I've added a commit to the PR that makes it opt-in:

  • the jar is shipped in lib/;
  • the DEDICATED_LOGGING appender and its appender-ref are included in logback.xml but commented out, with a short note on how to enable them.

With the block commented out, logback never instantiates the appender and the class is never loaded, so the runtime behavior and the processing overhead are exactly the same as today. Users who need the feature uncomment one block, and nothing has to be copied into the installation.

For reference, with the appender enabled (logback 1.6.6, 1M INFO events to file) the overhead I measured is about 1–1.5%, dominated by file I/O.

Use case

The concrete need is traceability of the processing activity of a specific flow. The flow uses LogMessage (and component log messages in general) inside a Process Group to record what was processed, e.g. which files/records were handled and their outcome. That trail has to be kept for a longer period than the operational logs.

Today the only option is to increase the retention of minifi-app.log (maxHistory / totalSizeCap). That means keeping a much larger amount of framework and component noise just to preserve a small number of relevant messages, which on an edge device directly translates into more disk usage.

With per-PG logging, the messages of that Process Group are also written to a dedicated minifi-app-<suffix>.log, which has its own rolling policy. The dedicated file can then have a long retention while being small (it contains only that PG's messages), and minifi-app.log keeps its current, short retention.

It also helps with troubleshooting on a running agent: when several Process Groups are active, isolating the messages of the one under investigation from minifi-app.log currently requires manual filtering, while a dedicated file gives that view directly.

In that sense the feature actually helps keep the overall footprint smaller than the alternative.

Side note

While testing I found that NifiDiscriminator throws a NullPointerException for every event without key/value pairs, and logback swallows it. A plain null check is not a valid fix, because the SiftingAppender would then route all those events to a ...-logFileSuffix_IS_UNDEFINED.log file. The proper fix is a small Filter that denies events without the suffix. Since it affects NiFi as well, I'll open a separate Jira for it rather than expanding the scope of this PR.

Let me know if the opt-in approach works for you.

@exceptionfactory

Copy link
Copy Markdown
Contributor

Thanks for the substantive reply @Vinz2168, that provides some helpful background. The opt-in strategy seems like the best one. Although the commented XML is used in some other configurations, I think it is best to leave it out of the default configuration. With that approach, the JAR can be added to the assembly, but would then require customization of the logback.xml to enable. How does that sound?

@Vinz2168

Copy link
Copy Markdown
Contributor Author

Thanks @exceptionfactory, that sounds good. I removed the commented configuration from the default logback.xml, so the assembly now only includes the JAR. To make the feature discoverable, I added a "Per Process Group Logging" section to the MiNiFi System Administrator's Guide. It describes how to set logFileSuffix on a Process Group and how to add the SiftingAppender to logback.xml, following the existing StatusLogger example in the same guide. I also rebased the branch onto the latest main.

Vinz2168 and others added 3 commits November 19, 2026 08:42
- Added nifi-per-process-group-logging to minifi-assembly and to the lib
  directory of both assembly descriptors
- Added DEDICATED_LOGGING SiftingAppender with NifiDiscriminator to the
  default MiNiFi logback.xml, writing to minifi-app-<suffix>.log with the
  same rolling limits as APP_FILE

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Commented out the DEDICATED_LOGGING appender and its appender-ref so the
  default logging behavior and overhead are unchanged
- Documented how to enable it and that its rolling policy can be tuned
  independently from APP_FILE

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Guide

Remove the commented DEDICATED_LOGGING appender from the default
logback.xml and describe how to enable the feature in the MiNiFi
System Administrator's Guide instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Vinz2168

Copy link
Copy Markdown
Contributor Author

Now that #11940 is merged, I rebased onto main and updated the logback.xml example in the guide to include the LogFileSuffixFilter, matching the default NiFi configuration.

@exceptionfactory exceptionfactory left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working through the feedback @Vinz2168, the latest approach with the documented example looks good!

@exceptionfactory
exceptionfactory merged commit 5b60b2b into apache:main Nov 21, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minifi Pull requests that updates minifi/c2 codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants