import ballerina/log;function main(string[] args) {
error err = {message: "error occurred"}; log:printDebug("debug log");
log:printError("error log");
log:printErrorCause("error log with cause", err);
log:printInfo("info log");
log:printTrace("trace log");
log:printWarn("warn log");
}
Log APIThe 'ballerina.log' package contains ballerina log handling functions. |
|
import ballerina/log;
|
|
function main(string[] args) {
error err = {message: "error occurred"};
|
|
The Ballerina log API provides functions to log at 5 levels: DEBUG, ERROR, INFO, TRACE and WARN.
By default, all log messages are logged to the console at the INFO level. In addition to these log levels,
there are 2 additional levels: OFF and ALL. OFF turns off logging and ALL allows all log levels.
Log level can be configured through a Ballerina config file or CLI parameters. |
|
log:printDebug("debug log");
log:printError("error log");
log:printErrorCause("error log with cause", err);
log:printInfo("info log");
log:printTrace("trace log");
log:printWarn("warn log");
|
|
To set the log level of the API use the CLI parameter: |
|
}
|
To configure using a config file, place the entry given below in the file: |
$ ballerina run log-api.bal
2017-11-05 21:20:12,313 ERROR [] - error log
2017-11-05 21:20:12,319 ERROR [] - error log with cause : {message:"error occurred", cause:null}
2017-11-05 21:20:12,320 INFO [] - info log
2017-11-05 21:20:12,321 WARN [] - warn log
|
As it can be seen from the output, only Info and higher level logs are logged |
$ ballerina run log-api.bal -e[ballerina.log].level=TRACE
2017-11-05 21:21:35,394 DEBUG [] - debug log
2017-11-05 21:21:35,400 ERROR [] - error log
2017-11-05 21:21:35,402 ERROR [] - error log with cause : {message:"error occurred", cause:null}
2017-11-05 21:21:35,403 INFO [] - info log
2017-11-05 21:21:35,403 TRACE [] - trace log
2017-11-05 21:21:35,404 WARN [] - warn log
|
|