Documentation
¶
Overview ¶
Package caller provides utilities to extract source code location information (file, line, function, and package) for the current or specified call frame. It is designed for use in logging, error reporting, and debugging with a lightweight and idiomatic API. Caller captures runtime metadata using the Go runtime and formats it in a developer-friendly way.
Example usage:
import "github.com/balinomad/go-caller" func someFunc() { c := caller.Immediate() fmt.Println("Caller location:", c.Location()) fmt.Println("Short:", c.ShortLocation()) fmt.Println("Function:", c.Function()) fmt.Println("Package:", c.PackageName()) data, err := json.Marshal(c) if err != nil { log.Fatal(err) } fmt.Println("JSON:", string(data)) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Caller ¶
type Caller interface { fmt.Stringer json.Marshaler json.Unmarshaler slog.LogValuer // Valid returns true if the caller is usable. Valid() bool // File returns the file name. File() string // Line returns the line number. Line() int // Location returns a formatted string with file:line. Location() string // ShortLocation returns a formatted string with just filename:line. ShortLocation() string // Function returns just the function or method name // without package prefix. Function() string // FullFunction returns the full function name including package. FullFunction() string // Package returns the full import path of the function. Package() string // PackageName returns the name of the package without the directory. PackageName() string }
Caller provides access to source information about the caller.
func Immediate ¶
func Immediate() Caller
Immediate returns a Caller for the immediate caller of the function that calls Immediate(). Returns nil if the caller cannot be determined.
Click to show internal directories.
Click to hide internal directories.