npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sologger_log_context

v0.2.0

Published

Provides functionality to turn raw logs output by Solana RPCs into structured logs for specified program IDs

Downloads

5

Readme

sologger-log-context

Overview

This library provides functionality to turn raw logs output by Solana RPCs into structured logs for specified program IDs.

Usage

    //Provide the ProgramSelector with the Program IDs for which you want to parse logs.
    //If you want to parse logs for all programs, use ProgramsSelector::new(&["*".to_string()])
    let programs_selector = ProgramsSelector::new(&["9RX7oz3WN5VRTqekBBHBvEJFVMNRnrCmVy7S6B6S5oU7".to_string()]);
    //Provide the raw logs, transfer error, programs selector, slot, and signature to the LogContext::parse_logs function.
    let log_contexts = LogContext::parse_logs(&logs, "".to_string(), &programs_selector, 1, "12345".to_string());

These json schema for the log context can be found here: LogContext-schema

For example, if we have a list of raw logs retrieved from the Solana RPC, we can parse them into structured logs using the LogContext::parse_logs function. The first parameter is the raw logs, the second parameter is the program ID, the third parameter is the programs selector, the fourth parameter is the slot, and the fifth parameter is the signature.

The LogContext::parse_logs function returns a vector of LogContexts. Each LogContext contains a vector of LogMessages. Each LogMessage contains a vector of LogFields. Each LogField contains a key and a value.

Here is an example of raw logs retrieved from the Solana RPC:

Program 9RX7oz3WN5VRTqekBBHBvEJFVMNRnrCmVy7S6B6S5oU7 invoke [1]
Program log: Instruction: Initialize
Program 11111111111111111111111111111111 invoke [2]
Program 11111111111111111111111111111111 success
Program log: Initialized new event. Current value
Program 9RX7oz3WN5VRTqekBBHBvEJFVMNRnrCmVy7S6B6S5oU7 consumed 59783 of 200000 compute units
Program 9RX7oz3WN5VRTqekBBHBvEJFVMNRnrCmVy7S6B6S5oU7 success
Program AbcdefGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]
Program log: Create
Program AbcdefGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 5475 of 200000 compute units
Program failed to complete: Invoked an instruction with data that is too large (12178014311288245306 > 10240)
Program AbcdefGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: Program failed to complete

Here is an example of the structured logs that are returned from the LogContext::parse_logs function:

{
  "log_messages":[
    "Instruction: Initialize",
    "Initialized new event. Current value"
  ],
  "data_logs":[

  ],
  "raw_logs":[
    "Program 9RX7oz3WN5VRTqekBBHBvEJFVMNRnrCmVy7S6B6S5oU7 invoke [1]",
    "Program log: Instruction: Initialize",
    "Program log: Initialized new event. Current value",
    "Program 9RX7oz3WN5VRTqekBBHBvEJFVMNRnrCmVy7S6B6S5oU7 consumed 59783 of 200000 compute units",
    "Program 9RX7oz3WN5VRTqekBBHBvEJFVMNRnrCmVy7S6B6S5oU7 success"
  ],
  "errors":[

  ],
  "transaction_error":"",
  "program_id":"9RX7oz3WN5VRTqekBBHBvEJFVMNRnrCmVy7S6B6S5oU7",
  "parent_program_id":"",
  "depth":1,
  "id":0,
  "instruction_index":0,
  "invoke_result":"",
  "slot":1,
  "signature":"12345"
}
{
  "log_messages":[

  ],
  "data_logs":[

  ],
  "raw_logs":[
    "Program 11111111111111111111111111111111 invoke [2]",
    "Program 11111111111111111111111111111111 success"
  ],
  "errors":[

  ],
  "transaction_error":"",
  "program_id":"11111111111111111111111111111111",
  "parent_program_id":"9RX7oz3WN5VRTqekBBHBvEJFVMNRnrCmVy7S6B6S5oU7",
  "depth":2,
  "id":1,
  "instruction_index":0,
  "invoke_result":"",
  "slot":1,
  "signature":"12345"
}
{
  "log_messages":[
    "Create"
  ],
  "data_logs":[

  ],
  "raw_logs":[
    "Program AbcdefGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]",
    "Program log: Create",
    "Program AbcdefGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 5475 of 200000 compute units",
    "Program failed to complete: Invoked an instruction with data that is too large (12178014311288245306 > 10240)",
    "Program AbcdefGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL failed: Program failed to complete"
  ],
  "errors":[
    "Invoked an instruction with data that is too large (12178014311288245306 > 10240)",
    "Program failed to complete"
  ],
  "transaction_error":"",
  "program_id":"AbcdefGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
  "parent_program_id":"",
  "depth":1,
  "id":2,
  "instruction_index":1,
  "invoke_result":"",
  "slot":1,
  "signature":"12345"
}

Additional Usage

The LogContext also provides utility to retrieve specific information from a log line.

  • get_program_data: Returns the data mentioned in the provided log (for logs prefixed with "Program data: ")
  • parse_logs_from_string: Parses the provided payload and returns a vector of LogContexts. The payload in this case is the raw JSON response as a string from the Solana RPC log_subscription endpoint.
  • has_errors: Returns true if the log contains a program error

Technical Details

The parsing of the raw logs is done using a regular expression. The regular expression is defined in the LogContext::get_log_regex function. The regular expression is defined as follows:

regex-vis

(?<programInvoke>^Program (?<invokeProgramId>[1-9A-HJ-NP-Za-km-z]{32,}) invoke \[(?<level>\d+)\]$)|(?<programSuccessResult>^Program (?<successResultProgramId>[1-9A-HJ-NP-Za-km-z]{32,}) success$)|(?<programFailedResult>^Program (?<failedResultProgramId>[1-9A-HJ-NP-Za-km-z]{32,}) failed: (?<failedResultErr>.*)$)|(?<programCompleteFailedResult>^Program failed to complete: (?<failedCompleteError>.*)$)|(?<programLog>^^Program log: (?<logMessage>.*)$)|(?<programData>^Program data: (?<data>.*)$)|(?<programConsumed>^Program (?<consumedProgramId>[1-9A-HJ-NP-Za-km-z]{32,}) consumed (?<consumedComputeUnits>\d*) of (?<allComputedUnits>\d*) compute units$)|(?<programConsumption>^^Program consumption: (?<computeUnitsRemaining>.*)$)|(?<logTruncated>^Log truncated$)|(?<programReturn>^Program return: (?<returnProgramId>[1-9A-HJ-NP-Za-km-z]{32,}) (?<returnMessage>.*)$)

The LogContext attempts to loop through the raw logs returned from the Solana websocket log subscription frames, or groups of logs retrieved from a specific transaction or block. If logs are provided that are out of order or not from a contained unit such as a block, transaction or websocket frame, then the LogContext will most likely fail.