Configure Grafana Loki logging using mazza-base library for Python/Flask applications with CA certificate (Mazza-specific). Use when setting up Loki logging for Mazza projects or configuring centralized logging.
/plugin marketplace add jmazzahacks/byteforge-claude-skills/plugin install byteforge-skills@byteforge-claude-skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
This skill helps you integrate Grafana Loki logging using the mazza-base utility library, which handles structured JSON logging and Loki shipping.
Use this skill when:
IMPORTANT: Before making changes, ask the user these questions:
"What is your application tag/name?" (e.g., "materia-server", "trading-api")
"What is your main application file?" (e.g., "app.py", "server.py", "materia_server.py")
"Do you have the mazza.vc_CA.pem certificate file?"
"Do you have a CR_PAT environment variable set?" (GitHub Personal Access Token)
Add this line to requirements.txt:
# Logging configuration with Loki support
mazza-base @ git+https://${CR_PAT}@github.com/mazza-vc/python-mazza-base.git@main
NOTE: The CR_PAT environment variable must be set when running pip install:
export CR_PAT="your_github_personal_access_token"
pip install -r requirements.txt
Ensure mazza.vc_CA.pem file is in your project root:
{project_root}/
├── mazza.vc_CA.pem # CA certificate for secure Loki connection
├── requirements.txt
├── Dockerfile
└── {app_file}.py
If you don't have this file, contact the Mazza infrastructure team.
Add the CA certificate to your Dockerfile. Place this before installing requirements:
FROM python:3.11-alpine
ARG CR_PAT
ENV CR_PAT=${CR_PAT}
WORKDIR /app
# Copy CA certificate
COPY mazza.vc_CA.pem .
# Copy requirements and install
COPY requirements.txt .
RUN pip install -r requirements.txt
# ... rest of Dockerfile
CRITICAL: The COPY line must appear before pip install -r requirements.txt
The certificate will be available at /app/mazza.vc_CA.pem in the container.
Add to the top of your main application file (e.g., {app_file}.py):
import os
from mazza_base import configure_logging
# Configure logging with mazza_base
# Use debug_local=True for local development, False for production with Loki
debug_mode = os.environ.get('DEBUG_LOCAL', 'true').lower() == 'true'
log_level = os.environ.get('LOG_LEVEL', 'INFO')
configure_logging(
application_tag='{application_tag}',
debug_local=debug_mode,
local_level=log_level
)
CRITICAL: Replace:
{app_file} → Your main application filename (e.g., "materia_server"){application_tag} → Your service name (e.g., "materia-server")Place this before creating your Flask app or any other initialization.
Add to README.md or .env.example:
Logging Configuration (Local Development):
DEBUG_LOCAL - Set to 'true' for local development (console logs), 'false' for production (Loki)
LOG_LEVEL - Logging level: DEBUG, INFO, WARNING, ERROR, CRITICAL
Loki Configuration (Production Only - required when DEBUG_LOCAL=false):
MZ_LOKI_ENDPOINT - Loki server URL (e.g., https://loki.mazza.vc:8443/loki/api/v1/push)MZ_LOKI_USER - Loki username for authenticationMZ_LOKI_PASSWORD - Loki password for authenticationMZ_LOKI_CA_BUNDLE_PATH - Path to CA certificate (e.g., /app/mazza.vc_CA.pem)GitHub Access (for pip install):
CR_PAT - GitHub Personal Access Token with repo access
Local Development (DEBUG_LOCAL=true):
Production (DEBUG_LOCAL=false):
# In .env or shell
export DEBUG_LOCAL=true
export LOG_LEVEL=DEBUG
export CR_PAT=your_github_token
pip install -r requirements.txt
python {app_file}.py
Docker Compose example:
services:
{app_name}:
build:
context: .
args:
- CR_PAT=${CR_PAT}
environment:
- DEBUG_LOCAL=false
- LOG_LEVEL=INFO
- MZ_LOKI_ENDPOINT=${MZ_LOKI_ENDPOINT}
- MZ_LOKI_USER=${MZ_LOKI_USER}
- MZ_LOKI_PASSWORD=${MZ_LOKI_PASSWORD}
- MZ_LOKI_CA_BUNDLE_PATH=/app/mazza.vc_CA.pem
NOTE: Set these in your .env file:
MZ_LOKI_ENDPOINT=https://loki.mazza.vc:8443/loki/api/v1/push
MZ_LOKI_USER=your_loki_user
MZ_LOKI_PASSWORD=your_loki_password
The mazza-base library provides:
You don't need to:
Just call configure_logging() and you're done!
If using flask-smorest-api skill, add logging before creating Flask app:
import os
from flask import Flask
from mazza_base import configure_logging
# Configure logging FIRST
debug_mode = os.environ.get('DEBUG_LOCAL', 'true').lower() == 'true'
configure_logging(application_tag='my-api', debug_local=debug_mode)
# Then create Flask app
app = Flask(__name__)
# ... rest of setup
In your Dockerfile:
ARG CR_PAT
ENV CR_PAT=${CR_PAT}
COPY mazza.vc_CA.pem .
COPY requirements.txt .
RUN pip install -r requirements.txt
Cannot install mazza-base:
CR_PAT environment variable is setmazza-vc/python-mazza-baseMissing CA certificate error:
mazza.vc_CA.pem is in project rootCOPY mazza.vc_CA.pem .Runtime error: Missing required environment variables:
DEBUG_LOCAL=falseLogs not appearing in Loki (production):
DEBUG_LOCAL=false is setImport error for mazza_base:
pip install -r requirements.txt with CR_PAT setpip list | grep mazza-baseSee the materia-server project for a reference implementation:
# materia_server.py
import os
from mazza_base import configure_logging
debug_mode = os.environ.get('DEBUG_LOCAL', 'true').lower() == 'true'
log_level = os.environ.get('LOG_LEVEL', 'INFO')
configure_logging(
application_tag='materia-server',
debug_local=debug_mode,
local_level=log_level
)
# ... rest of Flask app setup
# Dockerfile
FROM python:3.11-alpine
ARG CR_PAT
ENV CR_PAT=${CR_PAT}
WORKDIR /app
COPY mazza.vc_CA.pem .
COPY requirements.txt .
RUN pip install -r requirements.txt
# ... rest of Dockerfile
# docker-compose.yaml
services:
materia-server:
environment:
- MZ_LOKI_USER=${MZ_LOKI_USER}
- MZ_LOKI_ENDPOINT=${MZ_LOKI_ENDPOINT}
- MZ_LOKI_PASSWORD=${MZ_LOKI_PASSWORD}
- MZ_LOKI_CA_BUNDLE_PATH=/app/mazza.vc_CA.pem
This provides structured logging locally during development and automatic Loki shipping in production with secure encrypted connections.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.