Skip to content

Comments

Add native apis to change the log level via ICP#1439

Closed
daneshk wants to merge 22 commits intoballerina-platform:masterfrom
daneshk:master
Closed

Add native apis to change the log level via ICP#1439
daneshk wants to merge 22 commits intoballerina-platform:masterfrom
daneshk:master

Conversation

@daneshk
Copy link
Member

@daneshk daneshk commented Feb 3, 2026

Purpose

Fixes: ballerina-platform/ballerina-library#6213
This PR introduces Java APIs in LogConfigManager to support runtime log level modification via ICP. It also adds an optional id parameter to the fromConfig API to enable runtime log level changes for custom loggers.

Changes

  1. New Java APIs (LogConfigManager.java)
  • getLogConfig() - Get current log configuration (root level, modules)
  • setGlobalLogLevel() / getGlobalLogLevel() - Modify/get root log level at runtime
  • setModuleLevel() / removeModuleLevel() - Add/remove module-specific log levels at runtime
  • setLoggerLevel() - Change log level of existing custom loggers (registered by the app)
  • checkLogLevelEnabled() / checkCustomLoggerLogLevelEnabled() - Check if a log level is enabled
  1. Optional id parameter in fromConfig API (root_logger.bal)
  • Added an optional id field to the Config record
  • Loggers created with an id can have their log level modified at runtime via ICP
  • Loggers without an id cannot be modified at runtime
  1. Bug fixes
  • Fixed type cast error in tests by using TypeCreator.createMapType(PredefinedTypes.TYPE_ANYDATA) for proper Ballerina map type constraints
  • Added missing check before withContext() call in test
  1. Documentation updates
  • Updated spec.md with the new optional id parameter in the Config type
  • Updated changelog.md with the new feature
  1. Version bump
  • Updated version from 2.16.2 to 2.17.0

Examples

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests
  • Updated the spec
  • Checked native-image compatibility

daneshk and others added 8 commits February 3, 2026 22:34
This change introduces Java APIs for the ICP agent to modify log levels
at runtime without application restart.

New features:
- LogConfigManager.java: Singleton class providing Java APIs for ICP
- getLogConfig(): Retrieve current log configuration
- setGlobalLogLevel()/getGlobalLogLevel(): Root log level management
- setModuleLevel()/removeModuleLevel(): Module-level configuration
- setLoggerLevel(): Modify custom logger levels (user-named only)

Custom logger identification:
- Added optional 'id' field to Config record
- Loggers with user-provided ID are visible to ICP and configurable
- Loggers without ID get internal IDs and are not exposed to ICP

Closes ballerina-platform/ballerina-library#6213

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds Java APIs to enable runtime log level modification via the ICP (Integrated Control Panel) agent. The implementation introduces a new LogConfigManager singleton class that manages log configuration state and provides thread-safe operations for dynamic log level changes. Custom loggers can now be assigned optional unique IDs to make them configurable at runtime through ICP.

Changes:

  • Added LogConfigManager Java class for runtime log configuration management with thread-safe operations
  • Introduced optional id field to Config record for creating ICP-visible custom loggers
  • Added test utilities and comprehensive test coverage for log configuration management APIs

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
native/src/main/java/io/ballerina/stdlib/log/LogConfigManager.java Core implementation of singleton manager for runtime log level configuration with Java APIs for ICP integration
test-utils/src/main/java/io/ballerina/stdlib/log/testutils/nativeimpl/LogConfigTestUtils.java Test utilities wrapper that exposes LogConfigManager APIs for testing purposes
ballerina/root_logger.bal Updated logger implementation to support optional ID field and register loggers with LogConfigManager
ballerina/natives.bal Added native function declarations for LogConfigManager interop
ballerina/init.bal Initialize LogConfigManager with configurable values during module initialization
ballerina/tests/log_config_test.bal Comprehensive test coverage for runtime log configuration APIs including global, module, and custom logger level management
integration-tests/tests/test_performance.bal Performance comparison tests for logging with and without rotation
docs/spec/spec.md Updated specification to document the new optional id field for loggers
docs/proposals/runtime_log_level_modification.md Design proposal documenting the feature requirements, motivation, and API design
changelog.md Added changelog entry for the new feature
build-config/spotbugs-exclude.xml SpotBugs exclusions for intentional singleton pattern
ballerina/Ballerina.toml, Dependencies.toml, CompilerPlugin.toml Version updates to 2.16.2

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

daneshk and others added 2 commits February 4, 2026 22:31
…java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 92.91339% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.67%. Comparing base (ab0dc49) to head (3d41cd6).
⚠️ Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
...java/io/ballerina/stdlib/log/LogConfigManager.java 91.58% 5 Missing and 4 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1439      +/-   ##
============================================
+ Coverage     78.22%   80.67%   +2.44%     
- Complexity       97      132      +35     
============================================
  Files             9       10       +1     
  Lines           620      740     +120     
  Branches        116      127      +11     
============================================
+ Hits            485      597     +112     
- Misses          100      104       +4     
- Partials         35       39       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

daneshk and others added 2 commits February 4, 2026 22:45
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@daneshk daneshk marked this pull request as ready for review February 4, 2026 18:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

daneshk and others added 4 commits February 5, 2026 20:47
Co-authored-by: Krishnananthalingam Tharmigan <63336800+TharmiganK@users.noreply.github.com>
Co-authored-by: Krishnananthalingam Tharmigan <63336800+TharmiganK@users.noreply.github.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 6, 2026

@daneshk daneshk closed this Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add native support for modifying the log level programmatically at runtime

2 participants