Module log

ballerina/log Ballerina library
Functions
printDebug
function printDebug(string|PrintableRawTemplate msg, error? 'error, StackFrame[]? stackTrace, *KeyValues keyValues)
Prints debug logs.
log:printDebug("debug message", id = 845315)
Parameters
- msg string|PrintableRawTemplate - The message to be logged
- 'error error? (default ()) - The error struct to be logged
- stackTrace StackFrame[]? (default ()) - The error stack trace to be logged
- keyValues *KeyValues - The key-value pairs to be logged
printError
function printError(string|PrintableRawTemplate msg, error? 'error, StackFrame[]? stackTrace, *KeyValues keyValues)
Prints error logs.
error e = error("error occurred"); log:printError("error log with cause", 'error = e, id = 845315);
Parameters
- msg string|PrintableRawTemplate - The message to be logged
- 'error error? (default ()) - The error struct to be logged
- stackTrace StackFrame[]? (default ()) - The error stack trace to be logged
- keyValues *KeyValues - The key-value pairs to be logged
printInfo
function printInfo(string|PrintableRawTemplate msg, error? 'error, StackFrame[]? stackTrace, *KeyValues keyValues)
Prints info logs.
log:printInfo("info message", id = 845315)
Parameters
- msg string|PrintableRawTemplate - The message to be logged
- 'error error? (default ()) - The error struct to be logged
- stackTrace StackFrame[]? (default ()) - The error stack trace to be logged
- keyValues *KeyValues - The key-value pairs to be logged
printWarn
function printWarn(string|PrintableRawTemplate msg, error? 'error, StackFrame[]? stackTrace, *KeyValues keyValues)
Prints warn logs.
log:printWarn("warn message", id = 845315)
Parameters
- msg string|PrintableRawTemplate - The message to be logged
- 'error error? (default ()) - The error struct to be logged
- stackTrace StackFrame[]? (default ()) - The error stack trace to be logged
- keyValues *KeyValues - The key-value pairs to be logged
setOutputFile
function setOutputFile(string path, FileWriteOption option) returns Error?
Set the log output to a file. Note that all the subsequent logs of the entire application will be written to this file.
var result = log:setOutputFile("./resources/myfile.log"); var result = log:setOutputFile("./resources/myfile.log", log:OVERWRITE);
Parameters
- path string - The path of the file
- option FileWriteOption (default APPEND) - To indicate whether to overwrite or append the log output
Return Type
- Error? - A
log:Error
if an invalid file path was provided
Enums
log: FileWriteOption
Represents file opening options for writing.
Members
Configurables
Records
log: KeyValues
Key-Value pairs that needs to be displayed in the log.
Fields
- msg? never - msg which cannot be a key
- 'error? never - 'error which cannot be a key
- stackTrace? never - error stack trace which cannot be a key
- Value... - Rest field
Errors
log: Error
Represents Log module related errors.
Object types
log: PrintableRawTemplate
Represents raw templates for logging.
e.g: The input value is ${val}
Fields
- Fields Included from *RawTemplate
- strings string[] & readonly - String values of the template as an array
- insertions Value[] - Parameterized values/expressions after evaluations as an array
Union types
log: Value
Value
A value of anydata
type or a function pointer or raw template.
Function types
log: Valuer
function() returns (anydata)
Valuer
A function, which returns anydata
type.
Import
import ballerina/log;
Metadata
Released date: 8 days ago
Version: 2.11.0
License: Apache-2.0
Compatibility
Platform: java21
Ballerina version: 2201.11.0
GraalVM compatible: Yes
Pull count
Total: 750880
Current verison: 210
Weekly downloads
Keywords
level
format
Contributors
Dependencies