apexlog

package
v1.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package apexlog parses Apex debug logs and replays them one statement at a time.

Index

Constants

View Source
const AnonymousKey = "anonymous"

AnonymousKey is the source key of frames that run anonymous Apex.

Variables

This section is empty.

Functions

func HeapDumpIDs

func HeapDumpIDs(log *Log) []string

HeapDumpIDs returns the IDs of the ApexExecutionOverlayResult records named by the log's HEAP_DUMP events, in the order they appear.

Types

type Breakpoint

type Breakpoint struct {
	// Source is AnonymousKey or a 15-character entity ID.
	Source string `json:"source"`
	Line   int    `json:"line"`
}

Breakpoint is a line in a source.

type ErrLogLevel

type ErrLogLevel struct {
	Level string
}

ErrLogLevel is returned when a log was not captured at a level that records statements and variables.

func (ErrLogLevel) Error

func (e ErrLogLevel) Error() string

type Event

type Event struct {
	// LogLine is the 1-based line number of the event in the log.
	LogLine int
	// Nanos is the number of nanoseconds since the start of the request.
	Nanos int64
	// Type is the event type, e.g. "METHOD_ENTRY".
	Type string
	// Fields holds the pipe-separated fields that follow the event type.
	// Lines without a timestamp that follow an event are appended to its
	// last field, separated by newlines.
	Fields []string
	// SourceLine is the Apex line number from a leading "[n]" field, or 0
	// if the event has none.
	SourceLine int
}

Event is one log entry.

type Frame

type Frame struct {
	Kind FrameKind
	// Name is the name shown in the call stack.
	Name string
	// Signature is the last field of the entry event. Exit events are
	// matched against it.
	Signature string
	// EntityID is the 15-character ID of the Apex class or trigger, or ""
	// if the log does not give one (system methods, flows, anonymous Apex).
	EntityID string
	// Anonymous is true for the frame that runs anonymous Apex.
	Anonymous bool
	// Class is the name used to look up the frame's static variables.
	Class string
	// Line is the current line, or 0 before the first statement.
	Line int
	// Locals holds the frame's local variables.
	Locals *Scope
	// This is the reference of the object the frame runs on, if known.
	This string
	// Initializer is true for the frame that initializes a class's static
	// variables before the class is first used. Stepping does not stop in
	// it; breakpoints do.
	Initializer bool
	// contains filtered or unexported fields
}

Frame is one entry in the replayed call stack.

func (*Frame) SourceKey

func (f *Frame) SourceKey() string

SourceKey returns the key used to look up the frame's source and breakpoints: AnonymousKey for anonymous Apex, the entity ID for classes and triggers, and "" for frames without source.

type FrameKind

type FrameKind int

FrameKind identifies the event that created a frame.

const (
	CodeUnitFrame FrameKind = iota
	MethodFrame
	ConstructorFrame
	// VisualforceFrame is a call from a Visualforce page into its
	// controller (VF_APEX_CALL_START).
	VisualforceFrame
)
type Header struct {
	// APIVersion is the API version the log was written with, e.g. "62.0".
	APIVersion string
	// Levels maps each log category, e.g. "APEX_CODE", to its level, e.g.
	// "FINEST".
	Levels map[string]string
	// AnonymousSource holds the anonymous Apex that was executed, one entry
	// per source line, taken from the "Execute Anonymous:" header lines.
	AnonymousSource []string
}

Header holds the lines that precede the first event in a log.

func (Header) Level

func (h Header) Level(category string) string

Level returns the level recorded for a log category, or "" if the category is not in the header.

type HeapDump

type HeapDump struct {
	ClassName string       `json:"className"`
	Namespace string       `json:"namespace"`
	Extents   []HeapExtent `json:"extents"`
}

HeapDump is the state of the heap that Salesforce saves when execution reaches a checkpoint (ApexExecutionOverlayAction with IsDumpingHeap). It is the HeapDump field of an ApexExecutionOverlayResult record. The log marks where it was taken with a HEAP_DUMP event that gives the record's ID.

func ParseHeapDump

func ParseHeapDump(raw []byte) (*HeapDump, error)

ParseHeapDump parses the HeapDump field of an ApexExecutionOverlayResult.

type HeapEntry

type HeapEntry struct {
	Key   string    `json:"keyDisplayValue"`
	Value HeapValue `json:"value"`
}

type HeapExtent

type HeapExtent struct {
	TypeName       string       `json:"typeName"`
	CollectionType *string      `json:"collectionType"`
	Extent         []HeapObject `json:"extent"`
}

HeapExtent holds the objects of one type.

type HeapObject

type HeapObject struct {
	Address  string    `json:"address"`
	IsStatic bool      `json:"isStatic"`
	Symbols  []string  `json:"symbols"`
	Value    HeapValue `json:"value"`
}

HeapObject is one object in the heap. Symbols are the names of the variables that refer to it: local variable names, and Class.name for static variables.

type HeapValue

type HeapValue struct {
	Value json.RawMessage `json:"value"`
	Entry []HeapEntry     `json:"entry"`
}

HeapValue is either a value (a scalar, an object address, or a list of HeapValues) or a list of named entries (the fields of an object or the entries of a map).

type Log

type Log struct {
	Header Header
	Events []Event
}

Log is a parsed debug log.

func Parse

func Parse(r io.Reader) (*Log, error)

Parse reads a debug log.

type Output

type Output struct {
	LogLine int
	// Kind is "DEBUG", "EXCEPTION" or "FATAL_ERROR".
	Kind string
	// Level is the logging level of a debug statement.
	Level      string
	SourceLine int
	Message    string
}

Output is a line of program output: a debug statement or an exception.

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope is an ordered set of variables.

func (*Scope) Get

func (s *Scope) Get(name string) (*Variable, bool)

Get returns the variable with the given name.

func (*Scope) Len

func (s *Scope) Len() int

Len returns the number of variables.

func (*Scope) Variables

func (s *Scope) Variables() []*Variable

Variables returns the variables in the order they were declared.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session replays a log.

func NewSession

func NewSession(log *Log) (*Session, error)

NewSession returns a session positioned before the first event. It returns ErrLogLevel if the log was not captured with APEX_CODE at FINEST.

func (*Session) AddHeapDump

func (s *Session) AddHeapDump(id string, dump *HeapDump)

AddHeapDump makes a heap dump available to the replay. When the replay reaches the dump's HEAP_DUMP event, the variables and objects in the dump replace the values reconstructed from the log, including the contents of collections, which the log does not record when they change.

func (*Session) AtHeapDump

func (s *Session) AtHeapDump() bool

AtHeapDump reports whether a heap dump was taken before the current statement, so that its variables show the dump's contents.

func (*Session) Breakpoints

func (s *Session) Breakpoints() []Breakpoint

Breakpoints returns the breakpoints that are set.

func (*Session) Children

func (s *Session) Children(v *Variable) []*Variable

Children returns the members of a variable's value: the fields recorded for its object reference, or else the entries of its JSON value.

func (*Session) Done

func (s *Session) Done() bool

Done reports whether the session has reached the end of the log.

func (*Session) Executed

func (s *Session) Executed(source string, line int) bool

Executed reports whether a statement on a line of a source ran in the log. A breakpoint on a line that did not run is never reached.

func (*Session) Frames

func (s *Session) Frames() []*Frame

Frames returns the call stack, outermost frame first.

func (*Session) HasBreakpoint

func (s *Session) HasBreakpoint(b Breakpoint) bool

HasBreakpoint reports whether a breakpoint is set.

func (*Session) HasChildren

func (s *Session) HasChildren(v *Variable) bool

HasChildren reports whether Children returns any members.

func (*Session) HeapDumpCount

func (s *Session) HeapDumpCount() int

HeapDumpCount returns the number of heap dumps added to the replay.

func (*Session) Log

func (s *Session) Log() *Log

Log returns the log being replayed.

func (*Session) Object

func (s *Session) Object(ref string) *Scope

Object returns the fields recorded for an object reference.

func (*Session) ObjectType

func (s *Session) ObjectType(ref string) string

ObjectType returns the type of an object from a heap dump, or "" if the object is not from a heap dump.

func (*Session) Output

func (s *Session) Output() []Output

Output returns the program output written up to the current position.

func (*Session) Restart

func (s *Session) Restart()

Restart moves the session back to the start of the log. Breakpoints are kept.

func (*Session) Resume

func (s *Session) Resume(kind StepKind) StopReason

Resume replays events until the step is complete, a breakpoint is reached, or the log ends.

func (*Session) SetBreakpoint

func (s *Session) SetBreakpoint(b Breakpoint, enabled bool)

SetBreakpoint adds or removes a breakpoint.

func (*Session) Sources

func (s *Session) Sources() []SourceRef

Sources returns the classes and triggers that have frames in the log, with names taken from the log, sorted by name. Anonymous Apex is listed first when the log has any.

func (*Session) Statement

func (s *Session) Statement() int

Statement returns the number of the current statement, counting from 1 at the first statement in the log.

func (*Session) Statics

func (s *Session) Statics(f *Frame) *Scope

Statics returns the static variables of a frame's class.

func (*Session) StepBack

func (s *Session) StepBack() StopReason

StepBack is the reverse of StepOver: it returns to the most recent earlier statement in the current frame or a caller, skipping the statements of methods the current frame called. At the first statement of a method, that is the caller's statement. If the log has ended, it returns to the last statement. The log is replayed from the beginning up to that statement, so variables and output are as they were then.

func (*Session) Top

func (s *Session) Top() *Frame

Top returns the innermost frame, or nil if the stack is empty.

type SourceRef

type SourceRef struct {
	Key  string
	Name string
}

SourceRef identifies an Apex class or trigger that ran in the log.

type StepKind

type StepKind int

StepKind is how far Resume runs.

const (
	// StepIn stops at the next statement.
	StepIn StepKind = iota
	// StepOver stops at the next statement in the current frame or a
	// caller.
	StepOver
	// StepOut stops at the next statement in a caller.
	StepOut
	// Continue stops only at a breakpoint.
	Continue
)

type StopReason

type StopReason int

StopReason is why Resume stopped.

const (
	StoppedOnStep StopReason = iota
	StoppedOnBreakpoint
	// StoppedAtEnd means the log has no more statements.
	StoppedAtEnd
	// StoppedAtStart means StepBack was called at the first statement.
	StoppedAtStart
)

type Variable

type Variable struct {
	Name string
	Type string
	// Value is the value as written in the log. Strings are shown in
	// single quotes. Objects and collections are JSON.
	Value string
	// Ref is the reference of the object the variable holds, if the log
	// gave one.
	Ref string
	// Line is the line of the variable's last assignment in the log, or 0
	// if the log has not assigned it.
	Line int
}

Variable is a named value.

func (*Variable) Collection

func (v *Variable) Collection() bool

Collection reports whether the variable holds a list, set, or map. The log records a collection's contents only when the variable is assigned; changes made by methods such as add or put are not logged, so the value is the contents as of the last assignment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL