Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
71bbd11
Add Java APIs for runtime log level modification
daneshk Feb 3, 2026
c66cf92
Add testcases
daneshk Feb 3, 2026
52fe9b5
Fix SpotBugs violations in LogConfigManager
daneshk Feb 3, 2026
b5a573a
[Automated] Update the native jar versions
daneshk Feb 3, 2026
ade8867
[Automated] Update the native jar versions
daneshk Feb 3, 2026
e343523
fix test failures
daneshk Feb 4, 2026
c326f30
update the api accessability
daneshk Feb 4, 2026
d2aede8
update the spec and changelog
daneshk Feb 4, 2026
7a99fb3
Merge branch 'master' into master
daneshk Feb 4, 2026
8288a61
remove perf test file
daneshk Feb 4, 2026
244b11a
Update native/src/main/java/io/ballerina/stdlib/log/LogConfigManager.…
daneshk Feb 4, 2026
e0ba702
Apply suggestions from code review
daneshk Feb 4, 2026
e31d08c
Update native/src/main/java/io/ballerina/stdlib/log/LogConfigManager.…
daneshk Feb 4, 2026
8ba0983
Apply suggestions from code review
daneshk Feb 4, 2026
69c7ac4
[Automated] Update the native jar versions
daneshk Feb 4, 2026
af2532c
bump to next minor version
daneshk Feb 4, 2026
ffa8726
Apply suggestions from code review
daneshk Feb 4, 2026
4ddac8f
Merge branch 'master' into master
daneshk Feb 5, 2026
d580f25
change the get config response format
daneshk Feb 5, 2026
c6bad4e
Apply suggestion from @TharmiganK
daneshk Feb 5, 2026
d036069
Apply suggestion from @TharmiganK
daneshk Feb 5, 2026
e613b01
Add dynamic log level change support
daneshk Feb 17, 2026
cbc7b32
Add code review suggestions
daneshk Feb 18, 2026
470d149
revert version change in Ballerina.toml
daneshk Feb 18, 2026
8b58d64
[Automated] Update the native jar versions
daneshk Feb 18, 2026
a0832d0
Remove LogConfigManager java class as it is redundent
daneshk Feb 18, 2026
b8b738d
Apply suggestion from @daneshk
daneshk Feb 18, 2026
b4c9cf9
Merge branch 'master' into dynamic_log_config
daneshk Feb 18, 2026
3305709
fix the test failure
daneshk Feb 18, 2026
71501ef
fix test failures
daneshk Feb 18, 2026
ca4cc16
fix review suggestions
daneshk Feb 20, 2026
ef8156f
fix the review comments
daneshk Feb 20, 2026
561753e
Update native/src/main/java/io/ballerina/stdlib/log/LogConfigManager.…
daneshk Feb 20, 2026
3898ca6
fix the review comments
daneshk Feb 20, 2026
9089649
Update ballerina/tests/log_config_test.bal
daneshk Feb 20, 2026
57c95fd
[Automated] Update the native jar versions
daneshk Feb 20, 2026
2d18965
fix review comments
daneshk Feb 20, 2026
88a7a20
change the log key value merge order
daneshk Feb 20, 2026
0860f4e
fix build failure
daneshk Feb 20, 2026
28cdfc0
Update ballerina/root_logger.bal
daneshk Feb 20, 2026
b5107ef
Add new testcases to improve coverage
daneshk Feb 20, 2026
09eb012
remove root logger from registry
daneshk Feb 20, 2026
892dac1
update the documentation
daneshk Feb 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "log"
version = "2.16.1"
version = "2.17.0"
authors = ["Ballerina"]
keywords = ["level", "format"]
repository = "https://github.com/ballerina-platform/module-ballerina-log"
Expand All @@ -15,18 +15,18 @@ graalvmCompatible = true
[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "log-native"
version = "2.16.1"
path = "../native/build/libs/log-native-2.16.1.jar"
version = "2.17.0"
path = "../native/build/libs/log-native-2.17.0-SNAPSHOT.jar"

[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "log-compiler-plugin"
version = "2.16.1"
path = "../compiler-plugin/build/libs/log-compiler-plugin-2.16.1.jar"
version = "2.17.0"
path = "../compiler-plugin/build/libs/log-compiler-plugin-2.17.0-SNAPSHOT.jar"

[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "log-test-utils"
version = "2.16.1"
path = "../test-utils/build/libs/log-test-utils-2.16.1.jar"
version = "2.17.0"
path = "../test-utils/build/libs/log-test-utils-2.17.0-SNAPSHOT.jar"
scope = "testOnly"
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "log-compiler-plugin"
class = "io.ballerina.stdlib.log.compiler.LogCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/log-compiler-plugin-2.16.1.jar"
path = "../compiler-plugin/build/libs/log-compiler-plugin-2.17.0-SNAPSHOT.jar"
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ modules = [
[[package]]
org = "ballerina"
name = "log"
version = "2.16.1"
version = "2.17.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down
17 changes: 17 additions & 0 deletions ballerina/init.bal
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ function init() returns error? {
rootLogger = new RootLogger();
check validateDestinations(destinations);
setModule();

// Register the global root logger in the registry
lock {
loggerRegistry["root"] = rootLogger;
}

// Register each configured module as a Logger in the Ballerina-side registry
// Module loggers use the module name as their ID
foreach Module mod in modules {
ConfigInternal moduleConfig = {
level: mod.level
};
RootLogger moduleLogger = new RootLogger(moduleConfig, mod.name);
lock {
loggerRegistry[mod.name] = moduleLogger;
}
}
}

isolated function validateDestinations(OutputDestination[] destinations) returns Error? {
Expand Down
16 changes: 16 additions & 0 deletions ballerina/logger.bal
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,20 @@ public type Logger isolated object {
# + keyValues - The key-value pairs to be added to the logger context
# + return - A new Logger instance with the given key-values added to its context
public isolated function withContext(*KeyValues keyValues) returns Logger|error;

# Returns the effective log level of this logger.
# For root and custom loggers, returns the explicitly set level.
# For child loggers (created via `withContext`), returns the inherited level from the parent logger.
#
# + return - The effective log level
public isolated function getLevel() returns Level;

# Sets the log level of this logger at runtime.
# This is supported on root loggers, module loggers, and loggers created via `fromConfig`.
# Child loggers (created via `withContext`) do not support this operation and will return an error.
# To change a child logger's effective level, set the level on its parent logger instead.
#
# + level - The new log level to set
# + return - An error if the operation is not supported, nil on success
public isolated function setLevel(Level level) returns error?;
};
26 changes: 18 additions & 8 deletions ballerina/natives.bal
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,17 @@ isolated function replaceString(handle receiver, handle target, handle replaceme
paramTypes: ["java.lang.CharSequence", "java.lang.CharSequence"]
} external;

isolated function isLogLevelEnabled(string loggerLogLevel, string logLevel, string moduleName) returns boolean {
string moduleLogLevel = loggerLogLevel;
if modules.length() > 0 {
if modules.hasKey(moduleName) {
moduleLogLevel = modules.get(moduleName).level;
}
}
return logLevelWeight.get(logLevel) >= logLevelWeight.get(moduleLogLevel);
final readonly & map<int> LOG_LEVEL_WEIGHT = {
"ERROR": 1000,
"WARN": 900,
"INFO": 800,
"DEBUG": 700
};

isolated function isLevelEnabled(string effectiveLevel, string logLevel) returns boolean {
int requestedWeight = LOG_LEVEL_WEIGHT[logLevel] ?: 0;
int effectiveWeight = LOG_LEVEL_WEIGHT[effectiveLevel] ?: 800;
return requestedWeight >= effectiveWeight;
}

isolated function getModuleName(KeyValues keyValues, int offset = 2) returns string {
Expand All @@ -492,3 +495,10 @@ isolated function getCurrentFileSize(string filePath) returns int = @java:Method
isolated function getTimeSinceLastRotation(string filePath, string policy, int maxFileSize, int maxAgeInMillis, int maxBackupFiles) returns int = @java:Method {'class: "io.ballerina.stdlib.log.Utils"} external;

isolated function rotateLog(string filePath, string policy, int maxFileSize, int maxAgeInMillis, int maxBackupFiles) returns error? = @java:Method {'class: "io.ballerina.stdlib.log.Utils"} external;

// ========== Internal native function declarations for runtime log configuration ==========

isolated function generateLoggerIdNative(int stackOffset) returns string = @java:Method {
'class: "io.ballerina.stdlib.log.LogConfigManager",
name: "generateLoggerId"
} external;
Loading