logs

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 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

Logs indexes

pkg/logs adds an opt-in logs profile to the existing ZedSearch engine, It reuses ZedSearch's WAL, shards, storage backends, mappings, search, authentication and lifecycle settings.

Create

POST /api/index:

{
  "name": "app-logs",
  "storage_type": "disk",
  "settings": { "index_type": "logs" }
}

Alternatively, PUT /es/app-logs with {"settings":{"index_type":"logs"}}. The setting is persisted and returned by GET /api/app-logs/_settings and the corresponding /es endpoint. Omitted/empty index_type means standard; unknown values are rejected. The settings API cannot change the profile of an existing index: create a new index to change profiles.

Default mappings:

Fields Type
@timestamp Indexed, sortable, aggregatable date
message, log Full-text
level, log.level, service.name, host.name, trace_id, span_id, tags Keyword
_timestamp Source-only input alias; use @timestamp for time queries

Other fields are dynamically mapped as usual. Explicit mappings override these presets, except that @timestamp must remain a date. Neither message nor log is required, and neither is renamed or copied into the other. ECS-style objects such as {"log":{"level":"error"},"service":{"name":"api"}} keep their original structure in _source and are searchable through dotted field names.

Ingest

Use existing authenticated endpoints; no additional permissions or routes are needed:

  • POST /api/app-logs/_doc or /es/app-logs/_doc: one JSON object.
  • POST /api/app-logs/_multi: one JSON object per line (NDJSON).
  • POST /api/app-logs/_bulkv2: {"records":[{...},{...}]} (not a bare array).
  • POST /api/_bulk, /api/app-logs/_bulk, /es/_bulk or /es/app-logs/_bulk: Elasticsearch action/document pairs. Include a trailing newline.

Example /es/_bulk payload:

{"index":{"_index":"app-logs"}}
{"@timestamp":"2026-09-21T12:00:00.123456789Z","message":"request failed","level":"error","service":{"name":"api"}}
{"index":{"_index":"app-logs"}}
{"_timestamp":1790006400123456,"log":"request completed","level":"info"}

Event-time precedence is non-null @timestamp, then non-null _timestamp, then UTC ingestion time. Strings default to RFC3339 (offsets and fractional seconds are supported). Each field's own date mapping format/time_zone applies only to that field: a custom @timestamp format does not affect _timestamp, and an explicit _timestamp date mapping applies to the alias. Numeric epochs follow ZedSearch's existing magnitude-based seconds/milliseconds/microseconds/nanoseconds detection. Prefer RFC3339 strings for nanosecond precision in JSON, since JSON numbers are decoded as float64. The logs WAL preserves the normalized instant without a numeric round-trip.

Documentation

Overview

Package logs supplies the logs profile for ZedSearch's WAL-backed indexes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyDefaults

func ApplyDefaults(mappings *meta.Mappings) error

ApplyDefaults adds log search fields without replacing explicit mappings.

func CheckWindow added in v1.3.0

func CheckWindow(event, now time.Time, upto, future time.Duration) error

CheckWindow rejects events older than upto or later than future relative to now, like OpenObserve's ZO_INGEST_ALLOWED_UPTO/ZO_INGEST_ALLOWED_IN_FUTURE. A zero bound is disabled.

func EventTime added in v1.3.0

func EventTime(doc map[string]interface{}, mappings *meta.Mappings, now time.Time) (time.Time, error)

EventTime returns the UTC event time Normalize would write, now when doc has none, without copying doc.

func Normalize

func Normalize(doc map[string]interface{}, mappings *meta.Mappings, now time.Time) (map[string]interface{}, time.Time, error)

Normalize returns a shallow copy with canonical UTC event time. The caller's fields, including message/log and the original _timestamp alias, are preserved. The date format/time_zone of the mapping for the field actually used applies.

func ParseHEC added in v1.3.0

func ParseHEC(body []byte) ([]map[string]interface{}, error)

ParseHEC decodes Splunk HTTP Event Collector events, which may be concatenated or newline-delimited. The per-event `index` is ignored: events go to the index in the request path.

func ParseJSON added in v1.3.0

func ParseJSON(body []byte) ([]map[string]interface{}, error)

ParseJSON decodes an log `_json` body: an array of objects, or one object.

func ParseLoki added in v1.3.0

func ParseLoki(body []byte) ([]map[string]interface{}, error)

ParseLoki decodes a Loki push API JSON body. Labels and structured metadata become fields; entries are [ "<unix ns>", "<line>", {metadata}? ].

func ParseOTLP added in v1.3.0

func ParseOTLP(body []byte) ([]map[string]interface{}, error)

ParseOTLP decodes an OTLP/HTTP JSON logs request. Resource and record attributes keep their dotted keys (e.g. service.name), a string body becomes message and any other body is stored under body.

func SeverityText added in v1.3.0

func SeverityText(number int) string

SeverityText maps an OTLP SeverityNumber to a lowercase level, "" when unset.

func ValidateMappings

func ValidateMappings(mappings *meta.Mappings) error

Types

type IngestResponse added in v1.3.0

type IngestResponse struct {
	Code   int            `json:"code"`
	Status []StreamStatus `json:"status"`
}

IngestResponse mirrors the log `_json`/`_multi` ingestion response.

type StreamStatus added in v1.3.0

type StreamStatus struct {
	Name       string `json:"name"`
	Successful int    `json:"successful"`
	Failed     int    `json:"failed"`
	Error      string `json:"error,omitempty"`
}

StreamStatus mirrors an log ingestion status entry.

Jump to

Keyboard shortcuts

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