Documentation
¶
Overview ¶
Package apexlog parses Apex debug logs and replays them one statement at a time.
Index ¶
- Constants
- func HeapDumpIDs(log *Log) []string
- type Breakpoint
- type ErrLogLevel
- type Event
- type Frame
- type FrameKind
- type Header
- type HeapDump
- type HeapEntry
- type HeapExtent
- type HeapObject
- type HeapValue
- type Log
- type Output
- type Scope
- type Session
- func (s *Session) AddHeapDump(id string, dump *HeapDump)
- func (s *Session) AtHeapDump() bool
- func (s *Session) Breakpoints() []Breakpoint
- func (s *Session) Children(v *Variable) []*Variable
- func (s *Session) Done() bool
- func (s *Session) Executed(source string, line int) bool
- func (s *Session) Frames() []*Frame
- func (s *Session) HasBreakpoint(b Breakpoint) bool
- func (s *Session) HasChildren(v *Variable) bool
- func (s *Session) HeapDumpCount() int
- func (s *Session) Log() *Log
- func (s *Session) Object(ref string) *Scope
- func (s *Session) ObjectType(ref string) string
- func (s *Session) Output() []Output
- func (s *Session) Restart()
- func (s *Session) Resume(kind StepKind) StopReason
- func (s *Session) SetBreakpoint(b Breakpoint, enabled bool)
- func (s *Session) Sources() []SourceRef
- func (s *Session) Statement() int
- func (s *Session) Statics(f *Frame) *Scope
- func (s *Session) StepBack() StopReason
- func (s *Session) Top() *Frame
- type SourceRef
- type StepKind
- type StopReason
- type Variable
Constants ¶
const AnonymousKey = "anonymous"
AnonymousKey is the source key of frames that run anonymous Apex.
Variables ¶
This section is empty.
Functions ¶
func HeapDumpIDs ¶
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.
type Header ¶
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.
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 ¶
ParseHeapDump parses the HeapDump field of an ApexExecutionOverlayResult.
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 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.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session replays a log.
func NewSession ¶
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 ¶
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 ¶
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 ¶
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) Executed ¶
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) HasBreakpoint ¶
func (s *Session) HasBreakpoint(b Breakpoint) bool
HasBreakpoint reports whether a breakpoint is set.
func (*Session) HasChildren ¶
HasChildren reports whether Children returns any members.
func (*Session) HeapDumpCount ¶
HeapDumpCount returns the number of heap dumps added to the replay.
func (*Session) ObjectType ¶
ObjectType returns the type of an object from a heap dump, or "" if the object is not from a heap dump.
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 ¶
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 ¶
Statement returns the number of the current statement, counting from 1 at the first statement in the log.
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.
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 ¶
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.