No description
#1 Reviewed-on: #3 Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com> Reviewed-on: #4 |
||
|---|---|---|
| .github | ||
| src | ||
| .env.example | ||
| .gitignore | ||
| package-lock.json | ||
| package.json | ||
| pm2.sh | ||
| README.md | ||
| tsconfig.json | ||
| yarn.lock | ||
server-logger
Simple Express-based logging server with optional Discord log forwarding and optional Forgejo issue creation.
Features
- Accepts webhook-style log events on
/info,/warn, and/error - Writes logs to rotating files (
winston-daily-rotate-file) - Mirrors logs to console
- Sends logs to Discord webhook
- Optionally creates a Forgejo issue from
req.body.git
Requirements
- Node.js 18+ (Node 20+ recommended)
- npm
Setup
- Install dependencies:
npm install
- Create your env file from the example and set values:
cp .env.example .env
- Build:
npm run build
- Run:
npm start
Environment Variables
EXPRESS_PORT: Port for the HTTP serverLOG_DIR: Directory where rotating log files are writtenLOG_DISCORD_WEBHOOK: Discord webhook URL for log transportFORGEJO_ISSUE_WEBHOOK: Webhook URL used to create Forgejo issuesFORGEJO_TOKEN: Forgejo API token for authenticated issue creation
FORGEJO_ISSUE_WEBHOOK behavior
- If empty, Git issue creation is skipped.
- If it contains
{owner}and/or{repo}, values are read fromreq.body.git.ownerandreq.body.git.repoand injected into those tokens. - If it does not contain
{owner}or{repo}, the exact URL is used for all requests. FORGEJO_TOKENis sent in theAuthorizationheader (default format:token <TOKEN>).
API
Endpoints
POST /infoPOST /warnPOST /error
Base JSON body
{
"service": "my-service",
"message": "Something happened"
}
Optional Git issue payload
Include git only when you want to create a Forgejo issue:
{
"service": "my-service",
"message": "Unhandled error in worker",
"git": {
"owner": "my-user",
"repo": "my-repo",
"title": "Worker crashed while processing queue",
"description": "Stack trace and context here",
"labels": ["bug", "backend"],
"assignees": ["my-user"]
}
}
git validation rules
owner: required, non-empty stringrepo: required, non-empty stringtitle: required, non-empty stringdescription: required, non-empty stringlabels: optional, array of non-empty stringsassignees: optional, array of non-empty strings
If git is missing, normal logging still works and no issue is created.