Skip to content

Ignore feature #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ jobs:
bun-version: latest
- run: bun install
- run: bun test:coverage
- run: bun test:report
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./lcov.info
path-to-lcov: ./coverage/lcov.info
build:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 0 additions & 3 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

bunx commitlint --config commitlint.config.mjs --edit "$1"
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

bun check && bun run build && bun run test
201 changes: 120 additions & 81 deletions bun.lock

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,22 @@
},
"scripts": {
"build": "tsc",
"test": "tsx tests/index.test.ts",
"test:coverage": "c8 tsx --test tests/index.test.ts",
"test:report": "c8 report --reporter=text-lcov > lcov.info",
"test": "vitest run --dir tests",
"test:coverage": "vitest run --dir tests --coverage",
"check": "biome check",
"check:fix": "biome check --write",
"prepare": "husky install"
"prepare": "husky"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@commitlint/cli": "^19.7.1",
"@commitlint/config-conventional": "^19.7.1",
"@tinyhttp/app": "^2.5.2",
"@types/node": "^20.17.22",
"c8": "^10.1.3",
"expect": "^29.7.0",
"@vitest/coverage-v8": "^3.0.7",
"husky": "^9.1.7",
"supertest-fetch": "^2.0.0",
"tsx": "^4.19.3",
"typescript": "^5.8.2"
"typescript": "^5.8.2",
"vitest": "^3.0.7"
}
}
19 changes: 10 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ export enum LogLevel {
log = 'log'
}

export interface LoggerOptions {
methods?: string[]
output?: {
export type LoggerOptions = Partial<{
methods: string[]
output: {
color: boolean
filename?: string
callback: (string: string) => void
level?: LogLevel
}
timestamp?: boolean | { format?: string }
emoji?: boolean
ip?: boolean
}
timestamp: boolean | { format?: string }
emoji: boolean
ip: boolean
ignore: string[]
}>

const compileArgs = (
args: (string | number)[],
Expand Down Expand Up @@ -63,6 +64,7 @@ const compileArgs = (

export const logger = (options: LoggerOptions = {}) => {
const methods = options.methods ?? METHODS
const ignore = options.ignore ?? []
const output = options.output ?? { callback: console.log, color: true, level: null }
let filelogger = null
if (options.output?.filename) {
Expand All @@ -71,8 +73,7 @@ export const logger = (options: LoggerOptions = {}) => {
return (req: Request, res: Response, next?: () => void) => {
res.on('finish', () => {
const args: (string | number)[] = []
// every time
if (methods.includes(req.method)) {
if (methods.includes(req.method) && !ignore.some((url) => req.url.startsWith(url))) {
const s = res.statusCode.toString()
let stringToLog = ''
if (!output.color) {
Expand Down
Loading