@tinyhttp/logger
Advanced tools
+1
-1
| import { magenta, bold, red, cyan } from 'colorette'; | ||
| import * as statusEmoji from 'http-status-emojis'; | ||
| import statusEmoji from 'http-status-emojis'; | ||
| import dayjs from 'dayjs'; | ||
@@ -4,0 +4,0 @@ import { METHODS } from 'http'; |
+41
-13
| { | ||
| "name": "@tinyhttp/logger", | ||
| "version": "1.3.0", | ||
| "version": "1.3.2", | ||
| "type": "module", | ||
| "description": "simple HTTP logger for tinyhttp", | ||
| "homepage": "https://tinyhttp.v1rtl.site", | ||
| "description": "Minimal and flexible HTTP logger.", | ||
| "homepage": "https://github.com/tinyhttp/logger#readme", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/talentlessguy/tinyhttp.git", | ||
| "directory": "packages/logger" | ||
| "url": "https://github.com/tinyhttp/logger.git" | ||
| }, | ||
| "engines": { | ||
| "node": ">=12.4 || 14.x || >=16" | ||
| }, | ||
| "main": "./dist/index.cjs", | ||
@@ -28,18 +30,44 @@ "types": "./dist/index.d.ts", | ||
| "web", | ||
| "backend", | ||
| "logger" | ||
| "backend" | ||
| ], | ||
| "author": "v1rtl", | ||
| "license": "MIT", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "dependencies": { | ||
| "colorette": "^1.2.2", | ||
| "dayjs": "^1.10.4", | ||
| "colorette": "^2.0.19", | ||
| "dayjs": "^1.11.7", | ||
| "http-status-emojis": "^2.2.0" | ||
| }, | ||
| "engines": { | ||
| "node": ">=12.4.0" | ||
| "devDependencies": { | ||
| "@commitlint/cli": "17.4.4", | ||
| "@commitlint/config-conventional": "17.4.4", | ||
| "@rollup/plugin-typescript": "^11.0.0", | ||
| "@tinyhttp/app": "2.0.29", | ||
| "@types/node": "^18.14.6", | ||
| "@typescript-eslint/eslint-plugin": "^5.54.0", | ||
| "@typescript-eslint/parser": "^5.54.0", | ||
| "c8": "^7.13.0", | ||
| "eslint": "^8.35.0", | ||
| "eslint-config-prettier": "^8.6.0", | ||
| "eslint-plugin-prettier": "^4.2.1", | ||
| "expect": "^29.4.3", | ||
| "husky": "^8.0.3", | ||
| "prettier": "^2.8.4", | ||
| "rollup": "^3.18.0", | ||
| "supertest-fetch": "^1.5.0", | ||
| "tsm": "^2.3.0", | ||
| "typescript": "^4.9.5", | ||
| "uvu": "^0.5.6" | ||
| }, | ||
| "scripts": { | ||
| "build": "rollup -c ./rollup.config.js" | ||
| "build": "rollup -c", | ||
| "test": "uvu -r tsm tests", | ||
| "test:coverage": "c8 --include=src pnpm test", | ||
| "test:report": "c8 report --reporter=text-lcov > coverage.lcov", | ||
| "lint": "eslint . --ext=ts", | ||
| "format": "prettier --check \"./**/*.{ts,md}\"", | ||
| "format:fix": "prettier --write \"./**/*.{ts,md}\"" | ||
| } | ||
| } | ||
| } |
+13
-2
@@ -0,7 +1,11 @@ | ||
| <div align="center"> | ||
| # @tinyhttp/logger | ||
| [](https://npmjs.com/package/@tinyhttp/logger) [](https://npmjs.com/package/@tinyhttp/logger) [](https://tinyhttp.v1rtl.site/mw/logger) | ||
| [![npm][npm-img]][npm-url] [![GitHub Workflow Status][gh-actions-img]][github-actions] [![Coverage][cov-img]][cov-url] | ||
| Simple HTTP logger. | ||
| </div> | ||
| Minimal and flexible HTTP logger | ||
| ## Install | ||
@@ -58,1 +62,8 @@ | ||
| - [Volleyball](https://github.com/glebec/volleyball) - Tiny HTTP logger for Express showing asynchronous requests and responses | ||
| [npm-url]: https://npmjs.com/package/@tinyhttp/logger | ||
| [github-actions]: https://github.com/tinyhttp/logger/actions | ||
| [gh-actions-img]: https://img.shields.io/github/actions/workflow/status/tinyhttp/logger/ci.yml?branch=master&style=for-the-badge&color=hotpink&label=&logo=github | ||
| [cov-img]: https://img.shields.io/coveralls/github/tinyhttp/logger?style=for-the-badge&color=hotpink | ||
| [cov-url]: https://coveralls.io/github/tinyhttp/logger | ||
| [npm-img]: https://img.shields.io/npm/dt/@tinyhttp/logger?style=for-the-badge&color=hotpink |
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| var colorette = require('colorette'); | ||
| var statusEmoji = require('http-status-emojis'); | ||
| var dayjs = require('dayjs'); | ||
| var http = require('http'); | ||
| function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
| function _interopNamespace(e) { | ||
| if (e && e.__esModule) return e; | ||
| var n = Object.create(null); | ||
| if (e) { | ||
| Object.keys(e).forEach(function (k) { | ||
| if (k !== 'default') { | ||
| var d = Object.getOwnPropertyDescriptor(e, k); | ||
| Object.defineProperty(n, k, d.get ? d : { | ||
| enumerable: true, | ||
| get: function () { | ||
| return e[k]; | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| n['default'] = e; | ||
| return Object.freeze(n); | ||
| } | ||
| var statusEmoji__namespace = /*#__PURE__*/_interopNamespace(statusEmoji); | ||
| var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs); | ||
| const compileArgs = (args, req, res, options = {}, status, msg) => { | ||
| var _a, _b; | ||
| const { method } = req; | ||
| const { statusCode } = res; | ||
| const url = req.originalUrl || req.url; | ||
| const methods = (_a = options.methods) !== null && _a !== void 0 ? _a : http.METHODS; | ||
| const timestamp = (_b = options.timestamp) !== null && _b !== void 0 ? _b : false; | ||
| const emojiEnabled = options.emoji; | ||
| if (methods.includes(method) && timestamp) { | ||
| args.push(`${dayjs__default['default']() | ||
| .format(typeof timestamp !== 'boolean' && timestamp.format ? timestamp.format : 'HH:mm:ss') | ||
| .toString()} - `); | ||
| } | ||
| if (options.ip) | ||
| args.push(req.ip); | ||
| if (emojiEnabled) | ||
| args.push(statusEmoji__namespace[statusCode]); | ||
| args.push(method); | ||
| args.push(status || res.statusCode); | ||
| args.push(msg || res.statusMessage); | ||
| args.push(url); | ||
| }; | ||
| const logger = (options = {}) => { | ||
| var _a, _b; | ||
| const methods = (_a = options.methods) !== null && _a !== void 0 ? _a : http.METHODS; | ||
| const output = (_b = options.output) !== null && _b !== void 0 ? _b : { callback: console.log, color: true }; | ||
| return (req, res, next) => { | ||
| res.on('finish', () => { | ||
| const args = []; | ||
| if (methods.includes(req.method)) { | ||
| const s = res.statusCode.toString(); | ||
| if (!output.color) { | ||
| compileArgs(args, req, res, options); | ||
| const m = args.join(' '); | ||
| output.callback(m); | ||
| } | ||
| else { | ||
| switch (s[0]) { | ||
| case '2': | ||
| compileArgs(args, req, res, options, colorette.cyan(colorette.bold(s)), colorette.cyan(res.statusMessage)); | ||
| output.callback(args.join(' ')); | ||
| break; | ||
| case '4': | ||
| compileArgs(args, req, res, options, colorette.red(colorette.bold(s)), colorette.red(res.statusMessage)); | ||
| output.callback(args.join(' ')); | ||
| break; | ||
| case '5': | ||
| compileArgs(args, req, res, options, colorette.magenta(colorette.bold(s)), colorette.magenta(res.statusMessage)); | ||
| output.callback(args.join(' ')); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| next === null || next === void 0 ? void 0 : next(); | ||
| }; | ||
| }; | ||
| exports.logger = logger; |
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
69
18.97%3
-40%8530
-21.75%19
Infinity%5
-16.67%76
-53.09%+ Added
- Removed
Updated
Updated