@tinyhttp/logger
Advanced tools
@@ -1,2 +0,2 @@ | ||
| import { accessSync, writeFileSync, createWriteStream, mkdirSync } from 'node:fs'; | ||
| import { accessSync, createWriteStream, mkdirSync, writeFileSync } from 'node:fs'; | ||
| import { dirname as directoryname } from 'node:path'; | ||
@@ -40,3 +40,3 @@ export class FileLogger { | ||
| toFile(stringToLog) { | ||
| this.writableStream.write(stringToLog + '\n'); | ||
| this.writableStream.write(`${stringToLog}\n`); | ||
| } | ||
@@ -43,0 +43,0 @@ #_endStream() { |
+9
-8
@@ -1,2 +0,2 @@ | ||
| import { ServerResponse as Response, IncomingMessage as Request } from 'node:http'; | ||
| import { type IncomingMessage as Request, type ServerResponse as Response } from 'node:http'; | ||
| export declare enum LogLevel { | ||
@@ -9,5 +9,5 @@ error = "error", | ||
| } | ||
| export interface LoggerOptions { | ||
| methods?: string[]; | ||
| output?: { | ||
| export type LoggerOptions = Partial<{ | ||
| methods: string[]; | ||
| output: { | ||
| color: boolean; | ||
@@ -18,8 +18,9 @@ filename?: string; | ||
| }; | ||
| timestamp?: boolean | { | ||
| timestamp: boolean | { | ||
| format?: string; | ||
| }; | ||
| emoji?: boolean; | ||
| ip?: boolean; | ||
| } | ||
| emoji: boolean; | ||
| ip: boolean; | ||
| ignore: string[]; | ||
| }>; | ||
| export declare const logger: (options?: LoggerOptions) => (req: Request, res: Response, next?: () => void) => void; |
+8
-8
@@ -1,5 +0,5 @@ | ||
| import { cyan, red, magenta, bold } from 'colorette'; | ||
| import { METHODS } from 'node:http'; | ||
| import { bold, cyan, magenta, red } from 'colorette'; | ||
| import dayjs from 'dayjs'; | ||
| import statusEmoji from 'http-status-emojis'; | ||
| import dayjs from 'dayjs'; | ||
| import { METHODS } from 'node:http'; | ||
| import { FileLogger } from './filelogger.js'; | ||
@@ -21,5 +21,5 @@ export var LogLevel; | ||
| const emojiEnabled = options.emoji; | ||
| const level = options.output && options.output.level ? options.output.level : null; | ||
| const level = options.output?.level ? options.output.level : null; | ||
| if (level) | ||
| args.push('[' + level.toUpperCase() + ']'); | ||
| args.push(`[${level.toUpperCase()}]`); | ||
| if (methods.includes(method) && timestamp) { | ||
@@ -41,5 +41,6 @@ args.push(`${dayjs() | ||
| 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 && options.output.filename) { | ||
| if (options.output?.filename) { | ||
| filelogger = new FileLogger(options.output.filename); | ||
@@ -50,4 +51,3 @@ } | ||
| const args = []; | ||
| // every time | ||
| if (methods.includes(req.method)) { | ||
| if (methods.includes(req.method) && !ignore.some((url) => req.url.startsWith(url))) { | ||
| const s = res.statusCode.toString(); | ||
@@ -54,0 +54,0 @@ let stringToLog = ''; |
+22
-38
| { | ||
| "name": "@tinyhttp/logger", | ||
| "version": "2.0.0", | ||
| "version": "2.1.0", | ||
| "type": "module", | ||
@@ -26,47 +26,31 @@ "description": "Minimal and flexible HTTP logger.", | ||
| }, | ||
| "keywords": [ | ||
| "tinyhttp", | ||
| "node.js", | ||
| "web framework", | ||
| "web", | ||
| "backend" | ||
| ], | ||
| "keywords": ["tinyhttp", "node.js", "web framework", "web", "backend"], | ||
| "author": "v1rtl", | ||
| "license": "MIT", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "files": ["dist"], | ||
| "dependencies": { | ||
| "colorette": "^2.0.20", | ||
| "dayjs": "^1.11.10", | ||
| "dayjs": "^1.11.13", | ||
| "http-status-emojis": "^2.2.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@commitlint/cli": "^18.2.0", | ||
| "@commitlint/config-conventional": "^18.1.0", | ||
| "@tinyhttp/app": "^2.2.0", | ||
| "@types/node": "^20.8.9", | ||
| "@typescript-eslint/eslint-plugin": "^6.9.0", | ||
| "@typescript-eslint/parser": "^6.9.0", | ||
| "bun-types": "^1.0.7", | ||
| "c8": "^8.0.1", | ||
| "eslint": "^8.52.0", | ||
| "eslint-config-prettier": "^9.0.0", | ||
| "eslint-plugin-prettier": "^5.0.1", | ||
| "expect": "^29.7.0", | ||
| "husky": "^8.0.3", | ||
| "prettier": "^3.0.3", | ||
| "supertest-fetch": "^1.5.0", | ||
| "tsx": "^3.14.0", | ||
| "typescript": "^5.2.2" | ||
| }, | ||
| "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", | ||
| "lint": "eslint . --ext=ts", | ||
| "format": "prettier --check \"./**/*.{ts,md}\"", | ||
| "format:fix": "prettier --write \"./**/*.{ts,md}\"" | ||
| "test": "vitest run --dir tests", | ||
| "test:coverage": "vitest run --dir tests --coverage", | ||
| "check": "biome check", | ||
| "check:fix": "biome check --write", | ||
| "prepare": "bunx 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", | ||
| "@vitest/coverage-v8": "^3.0.7", | ||
| "husky": "^9.1.7", | ||
| "supertest-fetch": "^2.0.0", | ||
| "typescript": "^5.8.2", | ||
| "vitest": "^3.0.7" | ||
| } | ||
| } | ||
| } |
+0
-1
@@ -94,3 +94,2 @@ <div align="center"> | ||
| - [@tinyhttp/logger](/mw/logger) - Simple HTTP logger for tinyhttp | ||
| - [Pino HTTP](https://github.com/pinojs/pino-http) - high-speed HTTP logger for Node.js | ||
@@ -97,0 +96,0 @@ - [chrona](https://github.com/xambassador/chrona) - Simple HTTP request logger middleware for express.js inspired from koa-logger, written in typescript. |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
10
-41.18%170
0.59%11468
-3.15%103
-0.96%Updated