logger

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 6 Imported by: 0

README

Cryptographic Logging Dispatcher (logger)

The logger package provides a high-throughput, tamper-evident structured logging framework designed for zero-trust systems to have verifiable cryptographic state contracts managed by the Secure Data Format (SDF) protocol engine.


1. Architectural Blueprint

The logger is split into a non-blocking asynchronous dispatch pipeline and an emergency synchronous fallback pathway:

  • Asynchronous Queue Fast-Path: In normal operations, log requests enter an active memory channel queue. A background processor handles the execution stream, pulling records, compiling them via the SdfEngine, and transmitting the fully signed token payloads to registered external destinations (such as SIEM platforms or upstream RPC logging sinks).
  • Emergency Backpressure Fallback: If the asynchronous channel buffer fills completely or blocks due to external downstream exporter delays, the dispatcher triggers an automated synchronous fallback block. This bypasses the memory queue, forcing the compiling thread to write the ledger and index state updates directly into storage without losing tracking continuity.

2. Core Interfaces & Structures

The Log Item Descriptor

Stores the uncompiled log schema domain fields alongside the resulting token footprint.

type LogItem struct {
	Timestamp int64  `json:"timestamp"`
	Level     string `json:"level"`
	Message   string `json:"message"`
	Service   string `json:"service"`
	Actor     string `json:"actor,omitempty"`
	Action    string `json:"action,omitempty"`
	Token     string `json:"token,omitempty"` // Cryptographic SDF signature envelope
}

The Exporter Interface

Allows you to attach custom output targets to pipe the finalized, token-enriched records straight into external SIEM tools or localized files.

type Exporter interface {
	Export(item LogItem) error
}


3. Configuration & Usage

Initializing the Logging Fabric
import (
	"github.com/0TrustCloud/logger"
	"github.com/0TrustCloud/secure_data_format"
)

// Initialize the dispatcher with your service context and active SDF compiler engine
logDispatcher, err := logger.NewLogDispatcher("vault-service-pod", 1024, sdfEngineInstance)
if err != nil {
	panic(err)
}

// Register any external monitoring exporters
logDispatcher.RegisterExporter(myCustomSIEMExporter)

Standard Telemetry Mappings
// Standard application operational telemetry
logDispatcher.Info("Cryptographic key rotation interval began cleanly")
logDispatcher.Debug("Cache ring buffer validation passed")
logDispatcher.Error("Connection pool dropped connection socket 0x04")

// Strict structural compliance auditing
logDispatcher.Audit(
	"operator-greg", 
	"REVOKE_DEVICE", 
	"Blacklisted hardware posture certificate mapping",
)


4. Under the Hood: SDF Invocations

When an event triggers compilation, the dispatcher coordinates an internal state creation routine targeting ProfileStructuredLog. It passes unique nanosecond timestamps as order nonces to maintain strict ledger sequences:

script := `log:event(status("emitted"))`
targetAddress := "log:vault-service-pod:1774831200000000000"

tx := secure_data_format.DataInvocation{
	TargetAddress: targetAddress,
	Caller:        "vault-service-pod",
	Nonce:         1774831200000000000,
	Method:        "EMIT",
	Profile:       secure_data_format.ProfileStructuredLog,
	Args: map[string]interface{}{
		"level":   "AUDIT",
		"message": "Blacklisted hardware posture certificate mapping",
		"actor":   "operator-greg",
		"action":  "REVOKE_DEVICE",
	},
}

This compilation generates a standard tamper-evident token payload, which is assigned back onto the Token property of your LogItem statement before being handed off to external exporters.


5. Security & Protection Matrix

Threat Vector Mitigation Strategy
Log Cleansing / Deletion Attacks Logs are appended directly onto the immutable SDF transaction_ledger. Malicious actors or compromised root administrators cannot go back and rewrite historic hash chains.
Out-of-Order Log Injection Incremental nanosecond timestamp assignments double as cryptographic transaction nonces, preventing retroactive back-dating or log-injection spoofing.
Backpressure Log Loss If the async processing pipeline overflows, the dispatcher shifts to immediate synchronous compilation to guarantee transactional persistence before return.

6. Local Testing Workflow

The package contains an in-memory mock framework to cleanly verify that logs are processing, self-signing, and routing correctly across different logging levels.

Run the local logging test suite using the standard Go toolchain:

go test -v ./...

Documentation

Index

Constants

View Source
const TopicAll = "all"

TopicAll receives every log event.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exporter

type Exporter interface {
	Export(item LogItem) error
}

Exporter defines the interface for custom log targets (SIEM, RPC, etc.)

type LogDispatcher

type LogDispatcher struct {
	// contains filtered or unexported fields
}

LogDispatcher manages the async pub/sub pipeline and cryptographic compilation engine.

func NewLogDispatcher

func NewLogDispatcher(serviceName string, bufferSize int, sdf *secure_data_format.SecureDataEngine) (*LogDispatcher, error)

NewLogDispatcher initializes the pub/sub logging system backed by the SDF compiler core.

func (*LogDispatcher) Audit

func (ld *LogDispatcher) Audit(actor, action, message string)

func (*LogDispatcher) Close

func (ld *LogDispatcher) Close()

func (*LogDispatcher) Debug

func (ld *LogDispatcher) Debug(message string)

func (*LogDispatcher) Emit added in v1.0.3

func (ld *LogDispatcher) Emit(item LogItem)

Emit records a fully specified log item. Service is preserved when set, otherwise the dispatcher's default service name is used.

func (*LogDispatcher) Error

func (ld *LogDispatcher) Error(message string)

func (*LogDispatcher) Info

func (ld *LogDispatcher) Info(message string)

func (*LogDispatcher) RegisterExporter

func (ld *LogDispatcher) RegisterExporter(e Exporter)

RegisterExporter adds a new destination (e.g., SIEM, RPC) to the dispatcher.

func (*LogDispatcher) Subscribe added in v1.0.3

func (ld *LogDispatcher) Subscribe(topic string, fn Subscriber)

type LogItem

type LogItem struct {
	Timestamp int64  `json:"timestamp"`
	Level     string `json:"level"`
	Message   string `json:"message"`
	Service   string `json:"service"`
	Actor     string `json:"actor,omitempty"`
	Action    string `json:"action,omitempty"`
	Token     string `json:"token,omitempty"` // Cryptographic SDF signature token envelope
}

LogItem represents a cryptographically wrapped structured log entry.

type Subscriber added in v1.0.3

type Subscriber func(LogItem)

Subscriber receives published log items for a topic.

Jump to

Keyboard shortcuts

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