Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-log

Structured event logging for Pudu: message templates, enrichment, filtering, formatting, and sinks

0.1.0Apache-2.01

InstallClose

Memory.md

Markdown77 lines1.7 KB

GitHub ↗

PuduLangLog.Sinks.Memory


type: module path: "@root/src/PuduLangLog/Sinks/Memory.pudu" fidelity: Active grammar: "[[grammar/pudu]]" depth_score: 0.5 depth_status: MEDIUM tags: [module, sink] aliases: [PuduLangLog.Sinks.Memory]


Purpose

Keeps events in memory, for tests of code that logs and for in-process views of recent events.

Interface

Signatures

export type Memory = { events: Sync.Cell[Array[Log.Event]], lock: Sync.Mutex, capacity: Int }

export fn create() -> Memory

export fn bounded(capacity: Int) -> Memory

export fn sink(memory: &Memory) -> Sink.Sink

export fn events(memory: &Memory) -> Array[Log.Event]

export fn messages(memory: &Memory) -> Array[Str]

export fn matching(memory: &Memory, predicate: fn(&Log.Event) -> Bool) -> Array[Log.Event]

export fn withTemplate(memory: &Memory, template: Str) -> Array[Log.Event]

export fn latest(memory: &Memory) -> Option[Log.Event]

export fn clear(memory: &Memory) -> ()

Linkage

  • Requires: [[src/PuduLangLog]], [[src/PuduLangLog/Domain/Display]], [[src/PuduLangLog/Sink]], Std.List, Std.Sync.
  • Consumed by: package users and the suites.

Algorithm

  1. The sink appends each event under the store's lock and keeps at most capacity of the newest.
  2. Queries answer the events, their messages, those a predicate accepts, those from a template, and the latest one.

Negative Logic (Prohibited Paths)

  • The store never holds more than its capacity.

Edge Cases

  • latest of an empty store is none.

Depth

DEPTH 0.5 (MEDIUM). Tested by test/PuduLangLog/Sinks/MemoryTest.

Grill Log

  • Q: Why a capacity? A: An in-process view of recent events must not grow with uptime. _Rejected:_ unbounded only.

Referenced by

[[seams/Sink]] · [[src/PuduLangLog/_MOC]] · [[subsystems/Sinks]]