Mooncore.MCP.Watcher (mooncore v0.2.4)

Copy Markdown

In-memory log collector for development observability.

Stores temporary logs in a ring buffer (configurable max size). AI agents or the dev UI can add watchers, read logs, and filter by tag.

Only active when mooncore_dev_tools is enabled:

config :mooncore, mooncore_dev_tools: true

Usage

# Log an event (from anywhere in the app)
Mooncore.MCP.Watcher.log(:lifecycle, %{action: "task.create", phase: :start})
Mooncore.MCP.Watcher.log(:custom, %{message: "something happened"})

# Read all logs
Mooncore.MCP.Watcher.read()

# Read logs filtered by tag
Mooncore.MCP.Watcher.read(:lifecycle)

# Add a watcher — subscribe a PID to receive logs in real-time
Mooncore.MCP.Watcher.add_watcher(self(), :lifecycle)

# Clear logs
Mooncore.MCP.Watcher.clear()

Summary

Functions

Add a watcher PID. It will receive {:mooncore_log, tag, entry} messages.

Returns a specification to start this module under a supervisor.

Clear all logs.

Callback implementation for GenServer.init/1.

Log an event with a tag. Only stores if mooncore_dev_tools is on.

Read all logs, optionally filtered by tag. Returns newest first.

Read logs since a given entry id.

Remove a watcher PID.

Get watcher count.

Functions

add_watcher(pid, tag_filter \\ nil)

Add a watcher PID. It will receive {:mooncore_log, tag, entry} messages.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear()

Clear all logs.

init(opts)

Callback implementation for GenServer.init/1.

log(tag, data)

Log an event with a tag. Only stores if mooncore_dev_tools is on.

read(tag \\ nil)

Read all logs, optionally filtered by tag. Returns newest first.

read_since(since_id)

Read logs since a given entry id.

remove_watcher(pid)

Remove a watcher PID.

start_link(opts \\ [])

watcher_count()

Get watcher count.