Cycle

The Scriptorium

Smart Assembly code templates and tools for on-chain development in Eve Frontier.

← Back to Example Code

Event Logger

Utility

A lightweight on-chain event logger for debugging and auditing Smart Assembly interactions. Records timestamped entries with caller address and payload. Useful during development and testing.

utilityloggingdebuggingevents
event-logger.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/**
 * @title EventLogger
 * @notice On-chain event logger for Smart Assembly debugging.
 *         Records timestamped log entries that can be queried off-chain.
 */
contract EventLogger {
    address public owner;
    uint256 public entryCount;

    struct LogEntry {
        address caller;
        string message;
        bytes data;
        uint256 timestamp;
    }

    mapping(uint256 => LogEntry) public entries;

    event LogRecorded(
        uint256 indexed id,
        address indexed caller,
        string message,
        uint256 timestamp
    );

    constructor() {
        owner = msg.sender;
    }

    /// @notice Record a log entry
    function log(string calldata _message) external {
        _record(msg.sender, _message, "");
    }

    /// @notice Record a log entry with arbitrary data payload
    function logWithData(
        string calldata _message,
        bytes calldata _data
    ) external {
        _record(msg.sender, _message, _data);
    }

    function _record(
        address _caller,
        string calldata _message,
        bytes memory _data
    ) internal {
        uint256 id = entryCount++;
        entries[id] = LogEntry({
            caller: _caller,
            message: _message,
            data: _data,
            timestamp: block.timestamp
        });
        emit LogRecorded(id, _caller, _message, block.timestamp);
    }

    /// @notice Get the most recent N entries (off-chain helper)
    function getRecentCount() external view returns (uint256) {
        return entryCount;
    }

    /// @notice Clear all entries (owner only, for dev/test)
    function clear() external {
        require(msg.sender == owner, "Not owner");
        entryCount = 0;
    }
}