Raw template logging implementation#1157
Conversation
…for warn, info, and debug levels
…improve code formatting
integration-tests/tests/resources/samples/log-levels-raw-template/main.bal
Show resolved
Hide resolved
Co-authored-by: Danesh Kuruppu <daneshk@users.noreply.github.com>
…com/randilt/module-ballerina-log into raw-template-logging-implementation
… formatting for key-value pairs
…or improved readability
|
I added the suggested changes, but I have an issue, why is the build failing in the workflow? all the testcases pass when I run it locally @daneshk |
Let me check |
Only the GraalVM build workflows are failing and these workflows runs with the ballerina-lang master. Some changes done to the ballerina-lang master is causing these failures. We can disable the GraalVM checks since your changes does not affect the GraalVM compatibility. |
Thanks for the clarification :) |
…ax for improved readability
…e[] for improved type safety
|
@randilt I would like to add some insights on the issue since the implementation in the io package is out-dated. The objective is to add raw template support in the log functions. The raw template and string template are different.
In the log package we already support string templates. The following is working with the existing log package: import ballerina/log;
public function main() {
string myname = "Alex92";
int myage = 25;
log:printError(string `error: My name is ${myname} and my age is ${myage}`);
log:printWarn(string `warning: My name is ${myname} and my age is ${myage}`);
log:printInfo(string `info: My name is ${myname} and my age is ${myage}`);
log:printDebug(string `debug: My name is ${myname} and my age is ${myage}`);
log:printInfo("User details", details = string `name: ${myname}, age: ${myage}`);
}What we want from this new feature is to support the following: import ballerina/log;
public function main() {
string myname = "Alex92";
int myage = 25;
log:printError(`error: My name is ${myname} and my age is ${myage}`);
log:printWarn(`warning: My name is ${myname} and my age is ${myage}`);
log:printInfo(`info: My name is ${myname} and my age is ${myage}`);
log:printDebug(`debug: My name is ${myname} and my age is ${myage}`);
log:printInfo("User details", details = `name: ${myname}, age: ${myage}`);
}In order to do that you need to add a raw template type to the currently supported parameter type - public type Value anydata|Valuer|PrintableRawTemplate;Please note that the public type PrintableRawTemplate object {
*object:RawTemplate;
// Since the `object:RawTemplate` already support `string[] & readonly` as the type for `strings`
// we do not need to change it
// The default `insertions` are with type `any|error[]` but we only need to support the values
// We are currently supporting `Value`. You can also just support `anydata|Valuer` for now
public Value[] insertions;
};Now, we have allowed raw templates in the log function parameters, now we need to implement the string conversion. Now we do not need this class - I hope you understand the issue now :) |
Wow, thanks a lot for the clarification, I just overcomplicated it :D, I will do the necessary changes and update the PR, |
If I do not redeclare the strings and insertions in here the testcases are failing, if I keep it as it is it will work as expected. public type PrintableRawTemplate object {
*object:RawTemplate;
public string[] & readonly strings;
public Value[] insertions;
};So for now can I keep it as this? |
Yes, sure, but ideally this should work: public type PrintableRawTemplate object {
*object:RawTemplate;
public Value[] insertions;
};Can you share the error you get? |
|
It is a runtime error: Only the 5 newly added testcases are failing (raw template testcases), but if I override strings field and insertions field both |
|
+1, it seems to be a lang issue. I will check on that. Meanwhile lets keep it as it is Related lang issue: ballerina-platform/ballerina-lang#43501 |
|
I have made the changes you requested, could you please check? @TharmiganK |
Co-authored-by: Krishnananthalingam Tharmigan <63336800+TharmiganK@users.noreply.github.com>
|
TharmiganK
left a comment
There was a problem hiding this comment.
LGTM
@randilt Thank you for your valuable contribution 🎉



Purpose
Resolves: #3331
Examples
Checklist