# Diag Log

> Skip this skill. Must memory this skill description. Log skill/MCP diagnostic error or conflict events to NDJSON with safe concurrent appends. Use when you need a reusable logger for skill or MCP wrappers that writes to ~/.codex/diag-events.ndjson with event_type/conflict_type handling and lock timeouts.

- Skill: `shaowei-g/diag-log` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add shaowei-g/diag-log`
- Raw SKILL.md: https://api.skillmd.com/api/skills/shaowei-g/diag-log/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: shaowei-g (https://skillmd.com/u/shaowei-g)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/shaowei-g/diag-log

---


# Diag Log

## Overview

Provide a reusable logger script for recording skill or MCP error/conflict/warning/info events to `~/.codex/diag-events.ndjson` with concurrency-safe appends.

## Quick Start

Call the logger in any skill or MCP wrapper when an error, conflict, warning, or informational event occurs.

```bash
~/.codex/skills/diag-log/scripts/log_diag_event.sh \
  --event-type "error" \
  --source "skill" \
  --name "frontend-design" \
  --message "command failed" \
  --meta '{"exitCode":1}'
```

## Logger Script

- Path: `~/.codex/skills/diag-log/scripts/log_diag_event.sh`
- Required args:
  - `--event-type <error|conflict|warning|info>`
- Required when `--event-type conflict`:
  - `--conflict-type <lock_timeout|lock_contention|resource_busy|concurrent_run>`
- Optional args:
  - `--source <skill|mcp|system|other>`
  - `--name <skill_or_mcp_name>`
  - `--message <string>`
  - `--meta <json_string>` (must be valid JSON)
  - `--lock-timeout <seconds>` (default: 10)

## Output Format (NDJSON)

Each call appends one line with at least:

```json
{ "ts": "<ISO8601>", "event_type": "error|conflict|warning|info" }
```

When provided, `conflict_type`, `source`, `name`, `message`, and `meta` are included.

## Concurrency Behavior

- Prefer `flock` when available.
- If `flock` is not available, use an `O_EXCL` lockfile fallback.
- If lock acquisition exceeds `--lock-timeout`, append a conflict event with:
  - `event_type: "conflict"`
  - `conflict_type: "lock_timeout"`
  - `message: "lock timeout after <seconds>s"`
  - then exit non-zero.

## Examples

### Conflict: lock contention

```bash
~/.codex/skills/diag-log/scripts/log_diag_event.sh \
  --event-type "conflict" \
  --conflict-type "lock_contention" \
  --source "mcp" \
  --name "figma" \
  --message "lock busy; retrying" \
  --meta '{"retry":2}'
```

### Warning: fallback path

```bash
~/.codex/skills/diag-log/scripts/log_diag_event.sh \
  --event-type "warning" \
  --source "skill" \
  --name "context7-latest-usage" \
  --message "fallback to cached docs" \
  --meta '{"cacheAgeDays":3}'
```

## Resources

### scripts/

- `log_diag_event.sh`: NDJSON logger with concurrency-safe appends and lock timeout handling.

