log
Overview
Section titled “Overview”The log syscall outputs data to the console for debugging and diagnostic purposes. It prints the specified data directly to stdout.
Syscall Code
Section titled “Syscall Code”Code: 0x0C (TN_SYSCALL_CODE_LOG)
C SDK Function
Section titled “C SDK Function”ulong tsys_log(void const* data, ulong data_len);Arguments
Section titled “Arguments”data · void const · required*
Pointer to the data to be logged.
data_len · ulong · required
Length of the data to log in bytes. Must not exceed the maximum log data size.
Return Value
Section titled “Return Value”Returns a syscall result code:
Success · ulong
TN_VM_SYSCALL_SUCCESS(0) - Data logged successfully
Error Codes · ulong
TN_VM_ERR_SYSCALL_LOG_DATA_TOO_LARGE(-30) - Data exceeds maximum log sizeTN_VM_ERR_SYSCALL_INVALID_ADDRESS(-22) - Invalid virtual address for data
Resource Consumption
Section titled “Resource Consumption”Compute Units
Section titled “Compute Units”- Base cost: None (log syscalls don’t charge compute units)
- Total cost: 0 units
- Rationale: Logging is considered a debugging aid and is not charged
Memory Pages
Section titled “Memory Pages”- Page usage: No page allocation
- I/O overhead: Minimal system overhead for stdout operations
- Buffer management: Uses system stdout buffer
Side Effects
Section titled “Side Effects”- Console output: Writes data directly to stdout
- Buffer flushing: Flushes stdout buffer after writing
Size Limitations
Section titled “Size Limitations”- Maximum log data size:
TN_VM_LOG_DATA_MAX_SIZE(1024 bytes) - Attempts to log more data will result in an error
- No truncation is performed - the entire operation fails
Output Behavior
Section titled “Output Behavior”- Data is output byte-for-byte to stdout
- No formatting, newlines, or prefixes are added
- Output is immediately flushed to ensure visibility
- Binary data is output as-is (may include non-printable characters)
Usage Notes
Section titled “Usage Notes”- Intended for debugging and diagnostic purposes only
- Should not be used for production data exchange
- Performance impact is minimal but output is synchronous
- Consider the security implications of logging sensitive data
Example
Section titled “Example”#include <thru-sdk/c/tn_sdk_syscall.h>#include <string.h>#include <stdio.h>
// Log a simple debug messagechar debug_msg[] = "Debug: Account balance updated\n";ulong result = tsys_log(debug_msg, strlen(debug_msg));
// Log binary data (e.g., account hash)uchar account_hash[32];get_account_hash(account_hash);result = tsys_log(account_hash, 32);
// Log formatted datachar buffer[256];int len = snprintf(buffer, sizeof(buffer), "Account %lu: balance = %llu\n", account_id, balance);if (len > 0 && len < sizeof(buffer)) { result = tsys_log(buffer, len);}