Note: There is a newer version (2.14.0) of this package available. Click here to view docs for the latest version.
Module log
Declarations
ballerina/log Ballerina library
2.11.0
Functions
printDebug
Isolated Function
function printDebug(string msg, error? 'error, StackFrame[]? stackTrace, *KeyValues keyValues)Prints debug logs.
log:printDebug("debug message", id = 845315)
Parameters
- msg string - 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
Isolated Function
function printError(string 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 - 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
Isolated Function
function printInfo(string msg, error? 'error, StackFrame[]? stackTrace, *KeyValues keyValues)Prints info logs.
log:printInfo("info message", id = 845315)
Parameters
- msg string - 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
Isolated Function
function printWarn(string msg, error? 'error, StackFrame[]? stackTrace, *KeyValues keyValues)Prints warn logs.
log:printWarn("warn message", id = 845315)
Parameters
- msg string - 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
Isolated Function
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:Errorif an invalid file path was provided
Enums
log: FileWriteOption
Represents file opening options for writing.
Members
OVERWRITE - Overwrite(truncate the existing content)
APPEND - Append to the existing content
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
Distinct
Represents Log module related errors.
Union types
log: Value
Value
A value of anydata type or a function pointer.
Function types
log: Valuer
function() returns (anydata)Valuer
A function, which returns anydata type.
Import
import ballerina/log;Metadata
Released date: 11 months ago
Version: 2.11.0
License: Apache-2.0
Compatibility
Platform: java21
Ballerina version: 2201.11.0-20241209-162400-0c015833
GraalVM compatible: Yes
Pull count
Total: 63619
Current verison: 0
Weekly downloads
Keywords
level
format
Contributors
Dependencies