Back to Examples
- Binding patterns
- Typed binding pattern
- Wildcard binding pattern
- List binding patterns
- Rest binding pattern in list binding pattern
- Mapping binding pattern
- Rest binding pattern in mapping binding pattern
- Error binding pattern
- Rest binding pattern in error binding pattern
- Single use of typed binding patterns
- Single use of typed binding patterns with on fail clause
- Iterative use of typed binding patterns
- List binding pattern in match statement
- Mapping binding pattern in match statement
- Error binding pattern in match statement
- Query expressions
- Sort iterable objects
- Let clause
- Limit clause
- Join iterable objects
- Outer Join clause
- Query tables
- Create tables with a query
- Create maps with a query
- Create streams with a query
- On conflict clause
- Advanced conflict handling
- Iterate over XML with a query
- Nested query expressions
- Destructure records using a query
- Querying streams
- Aggregation
- JSON type
- Access JSON elements
- Access optional JSON elements
- Match statement with maps
- Convert from user-defined type to JSON
- Convert from table and XML to JSON
- Convert from JSON to user-defined type
- Cast JSON to user-defined type
- Resource method typing
- JSON numbers
- JSON to record
- JSON to record with projection
- JSONPath expressions
- Asynchronous function calls
- Named workers
- Sequence diagrams
- Wait for workers
- Strands
- Named worker return values
- Alternate wait
- Multiple wait
- Named workers and futures
- Inter-worker message passing
- Alternate receive
- Multiple receive
- Conditional send
- Inter-worker failure propagation
- Named worker with on fail clause
- Synchronize message passing
- Asynchronize message passing
- Flush
- Fork
Configure logging
The log
library contains the application log handling functions.
For more information on the underlying module, see the log
module.
import ballerina/log;
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");
}
To run this sample use the bal run
command.
$ bal run logging_configuration.baltime=2023-09-04T13:39:47.027+05:30 level=ERROR module="" message="error log"time=2023-09-04T13:39:47.037+05:30 level=INFO module="" message="info log"time=2023-09-04T13:39:47.038+05:30 level=WARN module="" message="warn log"# As shown in the output, only the `INFO` and higher level logs are logged by default.
# The log level can be configured via a Ballerina configuration file.# To set the global log level to `DEBUG`, place the entry given below in the `Config.toml` file and run the sample.# ```# [ballerina.log]# level = "DEBUG"# ```time=2023-09-04T13:42:07.797+05:30 level=DEBUG module="" message="debug log"time=2023-09-04T13:42:07.807+05:30 level=ERROR module="" message="error log"time=2023-09-04T13:42:07.808+05:30 level=INFO module="" message="info log"time=2023-09-04T13:42:07.809+05:30 level=WARN module="" message="warn log"# As shown in the output, now the `DEBUG` and higher level logs are logged.
# Each module can also be assigned its own log level. To assign a# log level to a module, provide the following entry in the `Config.toml` file:## ```# [[ballerina.log.modules]]# name = "[ORG_NAME]/[MODULE_NAME]"# level = "[LOG_LEVEL]"# ```
# By default, log messages are logged to the console in the LogFmt format.# To set the output format to JSON, place the entry given below in the `Config.toml` file and run the sample.# ```# [ballerina.log]# format = "json"# ```{"time":"2023-09-04T13:44:10.529+05:30", "level":"ERROR", "module":"", "message":"error log"}{"time":"2023-09-04T13:44:10.536+05:30", "level":"INFO", "module":"", "message":"info log"}{"time":"2023-09-04T13:44:10.536+05:30", "level":"WARN", "module":"", "message":"warn log"}
PreviousLogging with context
NextEDI to record conversion