Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
otherguy committed Nov 22, 2023
0 parents commit d39e05f
Show file tree
Hide file tree
Showing 38 changed files with 1,500 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .depfu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
update_strategy: security
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
27 changes: 27 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"parserOptions": {
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/strict-boolean-expressions": "warn",
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"no-console": "warn"
},
"env": {
"node": true
}
}
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* text=auto
*.js eol=lf
*.json eol=lf
*.proto eol=lf
*.md eol=lf
*.ts eol=lf
*.tsx eol=lf
*.yml eol=lf
*.7z filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# GitHub Code Owners

* @otherguy
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
15 changes: 15 additions & 0 deletions .github/workflows/autoupdate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: autoupdate
on:
push:
branches:
- main
jobs:
autoupdate:
name: autoupdate
runs-on: ubuntu-latest
steps:
- uses: docker://chinthakagodawita/autoupdate-action:v1
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
MERGE_CONFLICT_ACTION: "ignore"
MERGE_MSG: "🔀 Update branch"
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: ci
on:
pull_request:
push:
branches:
- main
jobs:
test:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: oven-sh/setup-bun@v1
with:
bun-version: 1.0.13
- run: bun install
- run: bun lint
- run: bun test:coverage
- uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageLocations: |
reports/lcov.info:lcov
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
63 changes: 63 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: publish
on:
push:
tags:
- '\d+\.\d+\.\d+'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
# Checkout project repository
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: "0"
# Setup Bun environment
- uses: oven-sh/setup-bun@v1
with:
bun-version: 1.0.13
# Setup Node environment and install yarn
- uses: actions/setup-node@v4
# Install dependencies
- run: bun install
# Build project
- name: Bump version and configure NPM
run: |
cat <<< $(jq --raw-output --arg version ${GITHUB_REF_NAME} '{version: $version} + .' package.json) > package.json
sudo tee .npmrc > /dev/null <<EOT
//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
EOT
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to NPM
run: yarn publish --registry https://registry.npmjs.org/ --access=public --tag ${GITHUB_REF_NAME}
- name: Publish to GitHub
run: yarn publish --registry https://npm.pkg.github.com --access=public --tag ${GITHUB_REF_NAME}
# Update CHANGELOG.md section with new version
- name: Update CHANGELOG.md and edit GitHub release
run: |
npm install github-release-notes -g
gren release --tags "${GITHUB_REF_NAME}" --override --token ${GITHUB_TOKEN} --username ${GITHUB_REPOSITORY_OWNER} --repo ${GITHUB_REPOSITORY#*/}
gren changelog --override --changelog-filename CHANGELOG.md --token ${GITHUB_TOKEN} --username ${GITHUB_REPOSITORY_OWNER} --repo ${GITHUB_REPOSITORY#*/}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Configure Git and commit changes
# See https://github.com/orgs/community/discussions/26560
- name: Push CHANGELOG.md
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
git checkout main
git add CHANGELOG.md
git commit -m "📝 Update CHANGELOG.md for ${GITHUB_REF_NAME}" -m "[skip ci]"
git push origin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Coverage directory used by tools like istanbul
coverage
*.lcov

# Dependency directories
node_modules/

# Optional eslint cache
.eslintcache

# dotenv environment variable files
.env
.env.*.local
.env.local

# Bun build directory
build/*
!build/.gitkeep

# Jest coverage directory
reports/*
!reports/.gitkeep

# Proto build directory
src/proto/*
!src/proto/.gitkeep

.yarn-error.log
19 changes: 19 additions & 0 deletions .grenrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"dataSource": "prs",
"prefix": "",
"onlyMilestones": false,
"groupBy": {
"🚀 Enhancements:": ["enhancement", "feature"],
"🐞 Bugfixes:": ["bug", "fix"],
"🔧 Changes:": ["closed", "documentation"],
"🚨 Security": ["🚨 security", "security"],
"🔀 Dependencies": ["dependencies", "depfu"]
},
"template": {
"noLabel": "closed",
"changelogTitle": "# Changelog\n\n",
"release": "## {{release}} ({{date}})\n{{body}}",
"issue": "- {{name}} [{{text}}]({{url}})"
},
"changelogFilename": "CHANGELOG.md"
}
16 changes: 16 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.git
.gitignore
.gitattributes
.github
bun.lockb
node_modules
tsconfig.json
examples
spec
CHANGELOG.md
sonar-project.properties
bunfig.toml
.npmrc
.grenrc.json
.editorconfig
.vscode
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bun 1.0.13
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
25 changes: 25 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The MIT License (MIT)
=====================

Copyright © 2023–2024 [Alexander Graf](https://github.com/otherguy/)

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# @otherguy/elysia-logging

An advanced logging plugin designed for [Elysia.js](https://elysiajs.com), prioritizing structured logging tailored for production environments.

<p align="center">

[![npm version](https://img.shields.io/npm/v/%40otherguy/elysia-logging?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@otherguy/elysia-logging)
[![npm downloads](https://img.shields.io/npm/dm/%40otherguy/elysia-logging?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@otherguy/elysia-logging)
[![Snyk Monitored](https://img.shields.io/badge/Snyk-Monitored-8A2BE2?style=for-the-badge&logo=snyk)](https://snyk.io/test/github/otherguy/elysia-logging)
[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/otherguy/elysia-logging/ci.yml?event=push&style=for-the-badge&logo=github)](https://github.com/otherguy/elysia-logging/actions/workflows/ci.yml)
[![GitHub License](https://img.shields.io/github/license/otherguy/elysia-logging?style=for-the-badge)](https://github.com/otherguy/elysia-logging/blob/main/LICENSE.md)
[![Code Climate Coverage](https://img.shields.io/codeclimate/coverage/otherguy/elysia-logging?style=for-the-badge&logo=codeclimate)](https://codeclimate.com/github/otherguy/elysia-logging)
[![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/otherguy/elysia-logging?style=for-the-badge&logo=codefactor)](https://www.codefactor.io/repository/github/otherguy/elysia-logging/)
[![Sonar CodeSmells](https://img.shields.io/sonar/violations/elysia-logging/main?server=https%3A%2F%2Fsonarcloud.io&style=for-the-badge&logo=sonarcloud&label=Code%20Smells)](https://sonarcloud.io/project/overview?id=elysia-logging)

</p>

---
Binary file added bun.lockb
Binary file not shown.
7 changes: 7 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[install]
optional = true
dev = true
peer = false
production = false
frozenLockfile = false
dryRun = false
28 changes: 28 additions & 0 deletions examples/basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Elysia } from "elysia";
import { ElysiaLogging } from "../src/elysiaLogging";

// Use console for logging
const logger = console;

// Create ElysiaLogging instance
const elysiaLogging = ElysiaLogging(logger, {
format: "short",
});

// Create Elysia app
const app = new Elysia()
.use(elysiaLogging)
.get("/", () => {
if (Math.random() < 0.75) {
return new Response("Welcome to Bun!");
}
throw new Error("Whoops!");
})
.listen({
port: Bun.env.PORT ?? 3000,
maxRequestBodySize: Number.MAX_SAFE_INTEGER,
});

logger.info(
`🦊 API is running at http://${app.server?.hostname}:${app.server?.port}`
);
28 changes: 28 additions & 0 deletions examples/custom-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Elysia } from "elysia";
import { ElysiaLogging } from "../src/elysiaLogging";

// Use console for logging
const logger = console;

// Create ElysiaLogging instance
const elysiaLogging = ElysiaLogging(logger, {
format: (log) => `${log.request.method} ${log.request.url.path} ${log.response.status_code}`
});

// Create Elysia app
const app = new Elysia()
.use(elysiaLogging)
.get("/", () => {
if (Math.random() < 0.75) {
return new Response("Welcome to Bun!");
}
throw { message: 'Whoops!', name: 'CustomError' };
})
.listen({
port: Bun.env.PORT ?? 3000,
maxRequestBodySize: Number.MAX_SAFE_INTEGER,
});

logger.info(
`🦊 API is running at http://${app.server?.hostname}:${app.server?.port}`
);
Loading

0 comments on commit d39e05f

Please sign in to comment.