logify

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 28 Imported by: 4 modules, 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.

README

dlogify.com/sdk/go

Send your Go application's logs and panics to dlogify, which groups errors, classifies them with AI and delivers full-context tickets.

go get dlogify.com/sdk/go
import logify "dlogify.com/sdk/go"

func main() {
	logify.Init(logify.Options{Service: "checkout"}) // LOGIFY_API_KEY from the environment
	defer logify.Shutdown(2 * time.Second)
	defer logify.Recover()
	slog.SetDefault(slog.New(logify.NewSlogHandler(slog.NewJSONHandler(os.Stdout, nil))))
}
  • slog: logify.NewSlogHandler(next); the standard log package: logify.CaptureStdLog().
  • Panics: defer logify.Recover(), logify.Go(fn), logify.Middleware(handler).
  • zap, zerolog and logrus: dlogify.com/sdk/go/zap, dlogify.com/sdk/go/zerolog, dlogify.com/sdk/go/logrus.
  • Any process: go install dlogify.com/sdk/go/cmd/logify@latest, then logify run -- ./server.

No dependencies outside the standard library; Go 1.22 or later. Guide: https://docs.dlogify.com/send-logs/go. MIT licence.

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

View Source
const Version = version.Version

Version is the version of this module.

Variables

This section is empty.

Functions

func CaptureError

func CaptureError(err error, attrs ...slog.Attr)

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 Debug

func Debug(msg string, attrs ...slog.Attr)

func Error

func Error(msg string, attrs ...slog.Attr)

func Fatal

func Fatal(msg string, attrs ...slog.Attr)

Fatal records at level fatal; it does not end the process.

func Flush

func Flush(timeout time.Duration) bool

Flush sends everything queued; it returns true when done before the timeout.

func Go

func Go(fn func())

Go runs fn in a new goroutine with Recover deferred.

func Info

func Info(msg string, attrs ...slog.Attr)

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 Log

func Log(level Level, msg string, attrs ...slog.Attr)

func Middleware

func Middleware(next http.Handler) http.Handler

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

func NewSlogHandler(next slog.Handler) slog.Handler

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()

func Shutdown

func Shutdown(timeout time.Duration)

Shutdown flushes for at most timeout and stops the client. Go has no exit hook: defer it in main.

func Trace

func Trace(msg string, attrs ...slog.Attr)

func Warn

func Warn(msg string, attrs ...slog.Attr)

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

func New(opts Options) *Client

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

func (c *Client) CaptureError(err error, attrs ...slog.Attr)

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) Debug

func (c *Client) Debug(msg string, attrs ...slog.Attr)

func (*Client) Emit

func (c *Client) Emit(e Entry)

Emit records an entry from a logging library adapter.

func (*Client) Enabled

func (c *Client) Enabled(level Level) bool

Enabled reports whether a record at this level would be sent.

func (*Client) Error

func (c *Client) Error(msg string, attrs ...slog.Attr)

func (*Client) Fatal

func (c *Client) Fatal(msg string, attrs ...slog.Attr)

Fatal records at level fatal; it does not end the process.

func (*Client) Flush

func (c *Client) Flush(timeout time.Duration) bool

Flush sends everything queued; it returns true when done before the timeout.

func (*Client) Go

func (c *Client) Go(fn func())

Go is Go for this client.

func (*Client) Info

func (c *Client) Info(msg string, attrs ...slog.Attr)

func (*Client) Log

func (c *Client) Log(level Level, msg string, attrs ...slog.Attr)

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

func (c *Client) Middleware(next http.Handler) http.Handler

Middleware is Middleware for this client.

func (*Client) NewSlogHandler

func (c *Client) NewSlogHandler(next slog.Handler) slog.Handler

NewSlogHandler is NewSlogHandler for this client.

func (*Client) Recover

func (c *Client) Recover()

Recover is Recover for this client: defer c.Recover().

func (*Client) Shutdown

func (c *Client) Shutdown(timeout time.Duration)

Shutdown flushes for at most timeout, stops the client and undoes what it installed (CaptureStdLog). Later calls do nothing.

func (*Client) Trace

func (c *Client) Trace(msg string, attrs ...slog.Attr)

func (*Client) Warn

func (c *Client) Warn(msg string, attrs ...slog.Attr)

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".

const (
	LevelTrace Level = 1
	LevelDebug Level = 5
	LevelInfo  Level = 9
	LevelWarn  Level = 13
	LevelError Level = 17
	LevelFatal Level = 21
)

func (Level) String

func (l Level) String() string

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

type RedactPattern struct {
	Pattern     *regexp.Regexp
	Replacement string
}

RedactPattern replaces every match of Pattern in the body and in string attributes with Replacement (inserted literally; "<redacted>" when empty).

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

Jump to

Keyboard shortcuts

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