diff --git a/examples/http-access-logs/Config.toml b/examples/http-access-logs/Config.toml index 4065733abe..71fc502ce0 100644 --- a/examples/http-access-logs/Config.toml +++ b/examples/http-access-logs/Config.toml @@ -1,5 +1,9 @@ [ballerina.http.accessLogConfig] # Enable printing access logs on the Console. The default value is `false`. console = true +# Specify the format of access logs. Options are `flat` or `json`. The default value is `flat`. +format = "flat" +# List of attributes to include in the access logs. This field is optional. +attributes = ["ip", "date_time", "request", "status", "response_body_size", "http_referrer", "http_user_agent"] # Specify the file path to save the access logs. This is optional. path = "testAccessLog.txt" diff --git a/examples/http-access-logs/http_access_logs.bal b/examples/http-access-logs/http_access_logs.bal index 653780467e..477c40d735 100644 --- a/examples/http-access-logs/http_access_logs.bal +++ b/examples/http-access-logs/http_access_logs.bal @@ -1,6 +1,6 @@ import ballerina/http; -type Album readonly & record {| +public type Album readonly & record {| string title; string artist; |}; diff --git a/examples/http-access-logs/http_access_logs.md b/examples/http-access-logs/http_access_logs.md index 78823d55ce..1de7c9a570 100644 --- a/examples/http-access-logs/http_access_logs.md +++ b/examples/http-access-logs/http_access_logs.md @@ -1,6 +1,6 @@ # HTTP service - Access logs -Ballerina allows enabling HTTP access logs, which can be used to record the HTTP requests handled by the application. HTTP access logs are disabled by default. Set `console=true` under `ballerina.http.accessLogConfig` in the `Config.toml` file to enable them. Additionally, the `path` field can be used to specify the file path to save the access logs. +Ballerina allows enabling HTTP access logs, which can be used to record the HTTP requests handled by the application. HTTP access logs are disabled by default. Set `console=true` under `ballerina.http.accessLogConfig` in the `Config.toml` file to enable them. Additionally, the `path` field can be used to specify the file path to save the access logs. The log format can be specified as either `flat` or `json` using the optional `format` field (defaults to `flat`). Furthermore, you can customize the logged attributes using the optional `attributes` field. ::: code http_access_logs.bal ::: diff --git a/examples/http-access-logs/http_access_logs.server.out b/examples/http-access-logs/http_access_logs.server.out index 7ead378b63..6a0ad5e8d2 100644 --- a/examples/http-access-logs/http_access_logs.server.out +++ b/examples/http-access-logs/http_access_logs.server.out @@ -1,3 +1,3 @@ $ bal run http_access_logs.bal ballerina: HTTP access log enabled -127.0.0.1 - - [15/Dec/2022:11:39:42 +0530] "GET /albums HTTP/1.1" 200 95 "-" "curl/7.79.1" +127.0.0.1 [11/Jul/2024:13:21:01.620 +0530] "GET /albums HTTP/1.1" 200 95 "-" "curl/8.4.0"