Documentation
¶
Overview ¶
Package logify sends your Go application's logs and panics to dlogify (https://dlogify.com), where errors are grouped, classified and turned into tickets.
Import it as dlogify.com/sdk/go; the package name is logify:
import logify "dlogify.com/sdk/go"
func main() {
logify.Init(logify.Options{Service: "checkout"})
defer logify.Shutdown(2 * time.Second)
defer logify.Recover()
slog.SetDefault(slog.New(logify.NewSlogHandler(slog.NewJSONHandler(os.Stdout, nil))))
}
The configuration comes from Options and the LOGIFY_* environment variables (LOGIFY_API_KEY is required). Records are sent in the background over OTLP/HTTP; no function of this package blocks the caller on the network, panics or returns an error.
Init installs no capture by itself: install the slog handler, call CaptureStdLog for the standard log package, use one of the adapters (dlogify.com/sdk/go/zap, …/zerolog, …/logrus), and defer Recover in main and in goroutines (or start them with Go). Go has no exit hook: defer Shutdown in main so queued records are sent before the process ends.
Index ¶
- Constants
- func CaptureError(err error, attrs ...slog.Attr)
- func CaptureStdLog()
- func Debug(msg string, attrs ...slog.Attr)
- func Error(msg string, attrs ...slog.Attr)
- func Fatal(msg string, attrs ...slog.Attr)
- func Flush(timeout time.Duration) bool
- func Go(fn func())
- func Info(msg string, attrs ...slog.Attr)
- func Init(opts Options)
- func Log(level Level, msg string, attrs ...slog.Attr)
- func Middleware(next http.Handler) http.Handler
- func NewSlogHandler(next slog.Handler) slog.Handler
- func Recover()
- func Shutdown(timeout time.Duration)
- func Trace(msg string, attrs ...slog.Attr)
- func Warn(msg string, attrs ...slog.Attr)
- type Client
- func (c *Client) CaptureError(err error, attrs ...slog.Attr)
- func (c *Client) CaptureStdLog()
- func (c *Client) Debug(msg string, attrs ...slog.Attr)
- func (c *Client) Emit(e Entry)
- func (c *Client) Enabled(level Level) bool
- func (c *Client) Error(msg string, attrs ...slog.Attr)
- func (c *Client) Fatal(msg string, attrs ...slog.Attr)
- func (c *Client) Flush(timeout time.Duration) bool
- func (c *Client) Go(fn func())
- func (c *Client) Info(msg string, attrs ...slog.Attr)
- func (c *Client) Log(level Level, msg string, attrs ...slog.Attr)
- func (c *Client) Middleware(next http.Handler) http.Handler
- func (c *Client) NewSlogHandler(next slog.Handler) slog.Handler
- func (c *Client) Recover()
- func (c *Client) Shutdown(timeout time.Duration)
- func (c *Client) Trace(msg string, attrs ...slog.Attr)
- func (c *Client) Warn(msg string, attrs ...slog.Attr)
- type Entry
- type Event
- type Level
- type Options
- type RedactPattern
Constants ¶
const Version = version.Version
Version is the version of this module.
Variables ¶
This section is empty.
Functions ¶
func CaptureError ¶
func CaptureStdLog ¶
func CaptureStdLog()
CaptureStdLog sends what the standard library's default logger writes (log.Print*, log.Fatal*, log.Panic*) to dlogify through the client created by Init, keeping its output. Shutdown undoes it. When the application called slog.SetDefault, the log package already goes through slog: install NewSlogHandler instead.
func Init ¶
func Init(opts Options)
Init creates the client the package functions use. A second call is ignored. Call it early in main, then defer Shutdown.
func Middleware ¶
Middleware records a panic in an HTTP handler at level error (the server keeps running) and panics again, so net/http handles it as usual. http.ErrAbortHandler is not recorded.
func NewSlogHandler ¶
NewSlogHandler returns a handler that passes every record to next unchanged (when next is not nil) and sends it to dlogify through the client created by Init. Install it with slog.SetDefault(slog.New(logify.NewSlogHandler(h))).
func Recover ¶
func Recover()
Recover records a panic, flushes for at most 2 s and panics again with the same value, so the program ends as it would have without dlogify. Defer it directly (recover only works in the deferred function itself), after Shutdown so it runs first:
defer logify.Shutdown(2 * time.Second) defer logify.Recover()
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client sends records to dlogify. The zero value is not usable; create one with New, or use the package functions after Init.
func Default ¶
func Default() *Client
Default returns the client created by Init, or a client that drops everything when Init has not been called.
func New ¶
New creates an independent client from opts and the environment. It never fails: with a broken configuration the client is a no-op and says why on stderr.
func (*Client) CaptureError ¶
CaptureError records err at level error with the message "<type>: <message>".
func (*Client) CaptureStdLog ¶
func (c *Client) CaptureStdLog()
CaptureStdLog is CaptureStdLog for this client.
func (*Client) Log ¶
Log records msg at level (an unknown level logs at info). The first attribute whose value is an error becomes the record's exception, with the stack of this call.
func (*Client) Middleware ¶
Middleware is Middleware for this client.
func (*Client) NewSlogHandler ¶
NewSlogHandler is NewSlogHandler for this client.
func (*Client) Recover ¶
func (c *Client) Recover()
Recover is Recover for this client: defer c.Recover().
type Entry ¶
type Entry struct {
// Scope names the source, for example "zap"; default "logify".
Scope string
// Level; the zero value means info.
Level Level
// Time of the call; the zero value means now.
Time time.Time
Message string
Attrs []slog.Attr
// Err becomes exception.*; when nil, the first error value in Attrs does.
Err error
// ErrText is used when the library only has the error's text: it becomes
// exception.message, with no exception.type.
ErrText string
// Skip lists package path prefixes of the logging library, removed from
// the top of the captured stack (for example "go.uber.org/zap").
Skip []string
}
Entry is a record handed over by a logging library adapter (dlogify.com/sdk/go/zap, …/zerolog, …/logrus). Applications use the Log methods instead.
type Event ¶
type Event struct {
Level Level
Message string
Attributes map[string]any
Scope string
Time time.Time
}
Event is what BeforeSend sees and returns. Changes to Level, Scope and Time are ignored.
type Level ¶
type Level int
Level is a record's level. Its values are the OTLP severity numbers; the zero value means "not set".
type Options ¶
type Options struct {
// APIKey (LOGIFY_API_KEY) is required; without it the client does nothing.
APIKey string
// Endpoint (LOGIFY_ENDPOINT), default https://api.dlogify.com.
Endpoint string
// Service (LOGIFY_SERVICE), default OTEL_SERVICE_NAME, then the main
// module's last path element, then the executable name.
Service string
// Environment (LOGIFY_ENVIRONMENT), default "default".
Environment string
// Release (LOGIFY_RELEASE) becomes service.version.
Release string
// MinLevel (LOGIFY_MIN_LEVEL), default LevelInfo.
MinLevel Level
// Attributes are added to every record's resource.
Attributes map[string]any
// MaxQueueSize is the number of records kept in memory, default 2000.
MaxQueueSize int
// Disabled (LOGIFY_DISABLED) turns the client into a no-op.
Disabled bool
// Debug (LOGIFY_DEBUG) prints the client's diagnostics to stderr.
Debug bool
// RedactDefaults (LOGIFY_REDACT_DEFAULTS) applies the engine's PII rules
// before records leave the process.
RedactDefaults bool
// RedactKeys (LOGIFY_REDACT_KEYS, comma-separated) are attribute keys whose
// values become "<redacted>", compared ignoring ASCII case.
RedactKeys []string
// RedactKeyPatterns redact the values of attributes whose key matches.
RedactKeyPatterns []*regexp.Regexp
// RedactPatterns run in order on the body and string attribute values.
RedactPatterns []RedactPattern
// BeforeSend sees every record last and returns it (changed or not), or
// nil to drop it. It must not block. A panic drops the record.
BeforeSend func(*Event) *Event
}
Options configure a client. Each field falls back to its LOGIFY_* environment variable, then to its default (docs.dlogify.com/send-logs/go). A boolean set to true turns the setting on; false leaves the environment variable in charge.
type RedactPattern ¶
RedactPattern replaces every match of Pattern in the body and in string attributes with Replacement (inserted literally; "<redacted>" when empty).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
logify
command
Command logify runs a command and sends its output to dlogify:
|
Command logify runs a command and sends its output to dlogify: |
|
internal
|
|
|
bridge
Package bridge connects internal/run to the root package without adding to the public API: the root package sets NewRunClient in its init, and cmd/logify imports the root package for that side effect.
|
Package bridge connects internal/run to the root package without adding to the public API: the root package sets NewRunClient in its init, and cmd/logify imports the root package for that side effect. |
|
conformance
Package conformance locates the language-neutral fixtures in clients/conformance for the tests of this module.
|
Package conformance locates the language-neutral fixtures in clients/conformance for the tests of this module. |
|
diag
Package diag writes the client's own messages straight to os.Stderr, never through log or slog, so a capture can never see them (docs/12 §4, guarantee 3).
|
Package diag writes the client's own messages straight to os.Stderr, never through log or slog, so a capture can never see them (docs/12 §4, guarantee 3). |
|
encode
Package encode writes records as OTLP/JSON (docs/12 §2–3).
|
Package encode writes records as OTLP/JSON (docs/12 §2–3). |
|
export
Package export queues encoded records and sends them in the background (docs/12 §4): one goroutine per exporter, one request in flight, retries with backoff, and failures that never reach the application.
|
Package export queues encoded records and sends them in the background (docs/12 §4): one goroutine per exporter, one request in flight, retries with backoff, and failures that never reach the application. |
|
goid
Package goid reads the current goroutine's id from the header of its stack trace ("goroutine 123 [running]:").
|
Package goid reads the current goroutine's id from the header of its stack trace ("goroutine 123 [running]:"). |
|
ingesttest
Package ingesttest is a fake OTLP/HTTP ingest for the adapters' tests.
|
Package ingesttest is a fake OTLP/HTTP ingest for the adapters' tests. |
|
ojson
Package ojson parses JSON keeping each object's key order and writes it back compact, the way JavaScript's JSON.stringify does.
|
Package ojson parses JSON keeping each object's key order and writes it back compact, the way JavaScript's JSON.stringify does. |
|
parse
Package parse implements docs/12 §5: log lines from a process's stdout and stderr become records (JSON lines, multiline text events, levels and exceptions).
|
Package parse implements docs/12 §5: log lines from a process's stdout and stderr become records (JSON lines, multiline text events, levels and exceptions). |
|
record
Package record holds the client's log record and the value rules of docs/12 §2–3: typed attribute values, normalization of arbitrary Go values, and the size cuts applied before a record is queued.
|
Package record holds the client's log record and the value rules of docs/12 §2–3: typed attribute values, normalization of arbitrary Go values, and the size cuts applied before a record is queued. |
|
redact
Package redact ports the engine's PII rules (services/engine/src/pipeline/ redact.rs, docs/04 PII redaction) for client-side redaction (docs/12 §3.1 step 3): same patterns, order and placeholders.
|
Package redact ports the engine's PII rules (services/engine/src/pipeline/ redact.rs, docs/04 PII redaction) for client-side redaction (docs/12 §3.1 step 3): same patterns, order and placeholders. |
|
run
Package run implements logify run (docs/12 §5.7): it runs a command with its output passed through unchanged, parses a copy (docs/12 §5) and sends the records.
|
Package run implements logify run (docs/12 §5.7): it runs a command with its output passed through unchanged, parses a copy (docs/12 §5) and sends the records. |
|
version
Package version holds the module version, shared by the root package and the internal packages (which cannot import the root package).
|
Package version holds the module version, shared by the root package and the internal packages (which cannot import the root package). |
|
logrus
module
|
|
|
zap
module
|
|
|
zerolog
module
|