Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Ballerina by example for Logging Ballerina records #5690

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions examples/logging/logging.bal
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import ballerina/log;

public type User record {
string name;
int age;
};

public function main() {
// The Ballerina log API provides functions to log at four levels, which are `DEBUG`, `ERROR`, `INFO`, and `WARN`.
log:printDebug("debug log");
log:printError("error log");
log:printInfo("info log");
log:printWarn("warn log");

User user = {
name: "Harry",
age: 20
};
// You can pass any number of key/value pairs, which need to be displayed in the log message.
// These can be of the `anydata` type including int, string, and boolean.
log:printInfo("info log", id = 845315, name = "foo", successful = true);
// These can be of the `anydata` type including int, string, boolean, records, etc.
log:printInfo("info log", id = 845315, name = "foo", successful = true, user = user);

// Optionally, an error can be passed to the functions.
error e = error("something went wrong!");
Expand Down
10 changes: 5 additions & 5 deletions examples/logging/logging.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$ bal run logging.bal
time=2023-09-04T13:35:12.309+05:30 level=ERROR module="" message="error log"
time=2023-09-04T13:35:12.319+05:30 level=INFO module="" message="info log"
time=2023-09-04T13:35:12.320+05:30 level=WARN module="" message="warn log"
time=2023-09-04T13:35:12.321+05:30 level=INFO module="" message="info log" id=845315 name="foo" successful=true
time=2023-09-04T13:35:12.323+05:30 level=ERROR module="" message="error log with cause" error={"causes":[],"message":"something went wrong!","detail":{},"stackTrace":[{"callableName":"main","moduleName":(),"fileName":"logging.bal","lineNumber":15}]} id=845315 name="foo"
time=2024-09-27T16:11:50.079+05:30 level=ERROR module="" message="error log"
time=2024-09-27T16:11:50.120+05:30 level=INFO module="" message="info log"
time=2024-09-27T16:11:50.122+05:30 level=WARN module="" message="warn log"
time=2024-09-27T16:11:50.134+05:30 level=INFO module="" message="info log" id=845315 name="foo" successful=true user={"name":"Harry","age":20}
time=2024-09-27T16:11:50.157+05:30 level=ERROR module="" message="error log with cause" error={"causes":[],"message":"something went wrong!","detail":{},"stackTrace":[{"callableName":"main","moduleName":(),"fileName":"logging.bal","lineNumber":24}]} id=845315 name="foo"
Loading