Documentation
¶
Index ¶
- Variables
- func Callers() []runtime.Frame
- func DumpProfile(profile, pathPrefix string)
- func DumpStackToFile(path, preStack, additionalInfo string)
- func DumpToFile(addr, out string)
- func Error(err error) bool
- func ErrorFn(fn func() error) bool
- func ErrorFnV[T any](t T, fn func(T) error) bool
- func Errorf(err error, format string, args ...any) bool
- func Get(ctx context.Context, url string) (*http.Response, error)
- func Head(ctx context.Context, url string) (*http.Response, error)
- func IgnoreError(err error)
- func Log(msg string)
- func LogCallers()
- func LogChanged(msg string)
- func Logf(format string, args ...any)
- func LogfChanged(format string, args ...any)
- func Panic(err error)
- func PanicFn(fn func() error)
- func Panicf(message string, err error)
- func PanicfFn(msg string, fn func() error)
- func Post(ctx context.Context, url, contentType string, body io.Reader) (*http.Response, error)
- func Stack() string
- func StartProfileServer(profile string) (string, func())
- func StartProfileServerAndStall(profile string)
- func UnusedPort() int
- func WithLabels(ctx context.Context, fn func(context.Context), labelPairs ...any)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Marker is the prefix used for log messages going to stdout. Marker = "###>" // EnableLogs allows to globally enable or disable logging. EnableLogs = true // LogToFile is the path to a file where logs will be written. // Mostly useful if the application being debugged is very noisy and // the interesting parts should be separated. LogToFile = "" )
var DumpProfileTraceSeconds = "10"
DumpProfileTraceSeconds is the default number of seconds to collect when collecting the trace profile.
Functions ¶
func Callers ¶
Callers returns all frames from the call this function as collected by runtime.Callers and runtime.CallersFrames as a slice.
func DumpProfile ¶
func DumpProfile(profile, pathPrefix string)
DumpToFile starts the pprof server, fetches the given profile and dumps it to the specified file.
func DumpStackToFile ¶
func DumpStackToFile(path, preStack, additionalInfo string)
DumpStackToFile dumps the current stack trace to a file at the specified path.
preStack can be left empty. If it is not empty it will be dumped to the file before the current stack trace. Useful when tracing origins and uses of a private function or callback.
additionalInfo can be left empty. If it is not empty it will be written between the preStack and the current stack trace.
func DumpToFile ¶
func DumpToFile(addr, out string)
DumpToFile fetches the content from the given address and writes it to the specified file.
func Errorf ¶
Errorf returns false if the error is nil, otherwise it logs the provided format and arguments with the error appended and returns true.
func IgnoreError ¶
func IgnoreError(err error)
IgnoreError configures which errors should be ignored.
func LogCallers ¶
func LogCallers()
LogCallers logs all frames from the call of this function as collected by runtime.Callers and runtime.CallersFrames using Log.
func LogChanged ¶
func LogChanged(msg string)
LogChanged logs a message if the content has changed since the last invocation from the same source.
Example ¶
// only prints one "first msg"
logger("first msg")
logger("first msg")
logger("first msg")
// prints "second msg"
logger("second msg")
// prints "first msg" again
logger("first msg")
Output: ###> first msg ###> second msg ###> first msg
func LogfChanged ¶
LogfChanged logs a formatted message if the content has changed since the last invocation from the same source.
func Panic ¶
func Panic(err error)
Panic does nothing if the error is nil, otherwise it logs the error and panics.
func PanicFn ¶
func PanicFn(fn func() error)
PanicFn executes the provided function and passes its error result to Panic.
func PanicfFn ¶
PanicfFn executes the provided function and passes its error result with the message to Panicf.
func StartProfileServer ¶
StartProfileServer starts the pprof server on an unused port and returns the address and a function to stop the server.
func StartProfileServerAndStall ¶
func StartProfileServerAndStall(profile string)
StartProfileServerAndStall calls StartProfileServer, logs the address and stalls indefinitely.
func WithLabels ¶
WithLabels is a convenience wrapper around pprof.Do, converting the label pairs to string, adding them to the context and executing the function.
If context is nil it defaults to context.Background().
The label pairs should be key-value pairs:
WithLabels(ctx, fn, "key1", "value1", "key2", "value2")
Types ¶
This section is empty.