Skip to main content

Overview

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

Syscall Code

Code: 0x0C (TN_SYSCALL_CODE_LOG)

C SDK Function

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

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

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 (-29) - Data exceeds maximum log size
  • TN_VM_ERR_SYSCALL_INVALID_ADDRESS (-21) - Invalid virtual address for data

Resource Consumption

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

  • Page usage: No page allocation
  • I/O overhead: Minimal system overhead for stdout operations
  • Buffer management: Uses system stdout buffer

Side Effects

  • Console output: Writes data directly to stdout
  • Buffer flushing: Flushes stdout buffer after writing

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

  • 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

  • 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
The log syscall outputs raw data to stdout. Be careful not to log sensitive information such as private keys, authentication tokens, or user data in production environments.

Example

#include "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);
}