{"id":18535292,"url":"https://github.com/tinyhttp/logger","last_synced_at":"2025-04-09T15:32:02.205Z","repository":{"id":107762507,"uuid":"383790465","full_name":"tinyhttp/logger","owner":"tinyhttp","description":"🪵 Minimal and flexible HTTP logger","archived":false,"fork":false,"pushed_at":"2025-03-03T12:09:46.000Z","size":242,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T08:47:16.457Z","etag":null,"topics":["esm","http","javascript","logger","logging","nodejs","tinyhttp"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tinyhttp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"issuehunt":"talentlessguy","github":["tinyhttp","talentlessguy"]}},"created_at":"2021-07-07T12:25:59.000Z","updated_at":"2025-03-03T12:09:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"fa828fa1-8a69-444c-aa53-629868444c74","html_url":"https://github.com/tinyhttp/logger","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":"tinyhttp/repo-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Flogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Flogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Flogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinyhttp%2Flogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinyhttp","download_url":"https://codeload.github.com/tinyhttp/logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248058070,"owners_count":21040688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esm","http","javascript","logger","logging","nodejs","tinyhttp"],"created_at":"2024-11-06T19:21:55.939Z","updated_at":"2025-04-09T15:32:02.200Z","avatar_url":"https://github.com/tinyhttp.png","language":"TypeScript","readme":"\u003cdiv align=\"center\"\u003e\n\n# @tinyhttp/logger\n\n[![npm][npm-img]][npm-url] [![GitHub Workflow Status][gh-actions-img]][github-actions] [![Coverage][cov-img]][cov-url]\n\n\u003c/div\u003e\n\nMinimal and flexible HTTP logger\n\n## Install\n\n```sh\npnpm i @tinyhttp/logger\n```\n\n## API\n\n```ts\nimport { logger } from '@tinyhttp/logger'\n```\n\n### `logger(options)`\n\nReturns the middleware for logging HTTP requests.\n\n#### Options\n\n- `methods`: a list of HTTP methods to log. Defaults to `http`'s `METHODS`.\n- `timestamp.format`: timestamp format. It is consumed by the [dayjs](https://day.js.org) library. If a string is specified, it is used as a format; otherwise just enabled.\n- `output.callback`: a function that receives the log generated by the logger.\n- `output.color`: a property that determines whether the logger will generate a message with color. Useful for logging into the console; disable if logging into a file or other colorless environments.\n- `emoji`: enable emojis for HTTP status codes. See [http-status-emojis](https://github.com/bendrucker/http-status-emojis/blob/master/index.js) for a full list.\n- `ip`: log IP address.\n\n## Example\n\n```ts\nimport { App } from '@tinyhttp/app'\nimport { logger } from '@tinyhttp/logger'\n\nnew App()\n  .use(\n    logger({\n      methods: ['GET', 'POST'],\n      timestamp: { format: 'HH:mm:ss' },\n      output: { callback: console.log, color: false }\n    })\n  )\n  .get('/', (req, res) =\u003e res.send('Hello world'))\n  .post('/', (req, res) =\u003e res.send('Sent POST'))\n  .listen(3000)\n```\n\nTo Log a level, use the enum `LogLevel`\n\n```ts\nimport { App } from '@tinyhttp/app'\nimport { logger, LogLevel } from '@tinyhttp/logger'\n\nnew App()\n  .use(\n    logger({\n      methods: ['GET', 'POST'],\n      timestamp: { format: 'HH:mm:ss' },\n      output: { callback: console.log, color: false, level: LogLevel.warn }\n    })\n  )\n  .get('/', (req, res) =\u003e res.send('Hello world'))\n  .listen(3000)\n```\n\nThis also includes a simple file logger. To stream to a file, simply supply the filename in the options. Supported file names innclude\n`./file.log` or `./log/tiny.log`\n\n```ts\nimport { App } from '@tinyhttp/app'\nimport { logger } from '@tinyhttp/logger'\n\nnew App()\n  .use(\n    logger({\n      methods: ['GET', 'POST'],\n      timestamp: { format: 'HH:mm:ss' },\n      output: { callback: console.log, color: false, filename: './log/tiny.log' }\n    })\n  )\n  .get('/', (req, res) =\u003e res.send('Hello world'))\n  .listen(3000)\n```\n\n## Alternatives\n\n- [Pino HTTP](https://github.com/pinojs/pino-http) - high-speed HTTP logger for Node.js\n- [chrona](https://github.com/xambassador/chrona) - Simple HTTP request logger middleware for express.js inspired from koa-logger, written in typescript.\n\n[npm-url]: https://npmjs.com/package/@tinyhttp/logger\n[github-actions]: https://github.com/tinyhttp/logger/actions\n[gh-actions-img]: https://img.shields.io/github/actions/workflow/status/tinyhttp/logger/ci.yml?branch=master\u0026style=for-the-badge\u0026color=hotpink\u0026label=\u0026logo=github\n[cov-img]: https://img.shields.io/coveralls/github/tinyhttp/logger?style=for-the-badge\u0026color=hotpink\n[cov-url]: https://coveralls.io/github/tinyhttp/logger\n[npm-img]: https://img.shields.io/npm/dt/@tinyhttp/logger?style=for-the-badge\u0026color=hotpink\n","funding_links":["https://issuehunt.io/r/talentlessguy","https://github.com/sponsors/tinyhttp","https://github.com/sponsors/talentlessguy"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyhttp%2Flogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinyhttp%2Flogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyhttp%2Flogger/lists"}