Skip to content

log

View as Markdown

The log syscall outputs data to the console for debugging and diagnostic purposes. It prints the specified data directly to stdout.

Code: 0x0C (TN_SYSCALL_CODE_LOG)

ulong tsys_log(void const* data, ulong data_len);

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.

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 size
  • TN_VM_ERR_SYSCALL_INVALID_ADDRESS (-22) - Invalid virtual address for data
  • 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
  • Page usage: No page allocation
  • I/O overhead: Minimal system overhead for stdout operations
  • Buffer management: Uses system stdout buffer
  • Console output: Writes data directly to stdout
  • Buffer flushing: Flushes stdout buffer after writing
  • 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
  • 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)
  • 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
#include <thru-sdk/c/tn_sdk_syscall.h>
#include <string.h>
#include <stdio.h>
// Log a simple debug message
char 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 data
char 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);
}