{"id":18672967,"url":"https://github.com/vicanso/koa-log","last_synced_at":"2025-04-12T01:31:21.136Z","repository":{"id":34145195,"uuid":"37981716","full_name":"vicanso/koa-log","owner":"vicanso","description":"logger middlware for koa","archived":false,"fork":false,"pushed_at":"2018-11-29T09:11:42.000Z","size":53,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T21:35:49.757Z","etag":null,"topics":["koa","logging","morgan"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/vicanso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-24T11:58:02.000Z","updated_at":"2022-06-09T09:07:22.000Z","dependencies_parsed_at":"2022-09-02T15:41:47.037Z","dependency_job_id":null,"html_url":"https://github.com/vicanso/koa-log","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fkoa-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fkoa-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fkoa-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vicanso%2Fkoa-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vicanso","download_url":"https://codeload.github.com/vicanso/koa-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248070553,"owners_count":21042849,"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":["koa","logging","morgan"],"created_at":"2024-11-07T09:13:34.423Z","updated_at":"2025-04-12T01:31:20.900Z","avatar_url":"https://github.com/vicanso.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-log\n\n[![Build Status](https://travis-ci.org/vicanso/koa-log.svg?branch=master)](https://travis-ci.org/vicanso/koa-log)\n[![Coverage Status](https://img.shields.io/coveralls/vicanso/koa-log/master.svg?style=flat)](https://coveralls.io/r/vicanso/koa-log?branch=master)\n[![npm](http://img.shields.io/npm/v/koa-log.svg?style=flat-square)](https://www.npmjs.org/package/koa-log)\n[![Github Releases](https://img.shields.io/npm/dm/koa-log.svg?style=flat-square)](https://github.com/vicanso/koa-log)\n\nHTTP request logger middleware for koa, refer to express/morgan and koa-logger\n\n## API\n\n```js\nvar logger = require('koa-log');\nvar morgan = logger.morgan;\n```\n\n\n#### Predefined Formats\n\nThere are various pre-defined formats provided:\n\n##### combined\n\nStandard Apache combined log output.\n\n```\n:remote-addr - :remote-user [:date[clf]] \":method :url HTTP/:http-version\" :status :length \":referrer\" \":user-agent\"\n```\n\n##### common\n\nStandard Apache common log output.\n\n```\n:remote-addr - :remote-user [:date[clf]] \":method :url HTTP/:http-version\" :status :length\n```\n\n##### dev\n\nConcise output colored by response status for development use. The `:status`\ntoken will be colored red for server error codes, yellow for client error\ncodes, cyan for redirection codes, and uncolored for all other codes.\n\n```\n:method :url :status :response-time ms - :length\n```\n\n##### short\n\nShorter than default, also including response time.\n\n```\n:remote-addr :remote-user :method :url HTTP/:http-version :status :length - :response-time ms\n```\n\n##### tiny\n\nThe minimal output.\n\n```\n:method :url :status :length - :response-time ms\n```\n\n\n#### Tokens\n\n##### Creating new tokens\n\nTo define a token, simply invoke `morgan.token()` with the name and a callback function. This callback function is expected to return a string value. The value returned is then available as \":type\" in this case:\n\n```js\nmorgan.token('type', function(ctx){ return ctx.get('content-type'); })\n```\n\nCalling `morgan.token()` using the same name as an existing token will overwrite that token definition.\n\n##### :date[format]\n\nThe current date and time in UTC. The available formats are:\n\n  - `clf` for the common log format (`\"10/Oct/2000:13:55:36 +0000\"`)\n  - `iso` for the common ISO 8601 date time format (`2000-10-10T13:55:36.000Z`)\n  - `web` for the common RFC 1123 date time format (`Tue, 10 Oct 2000 13:55:36 GMT`)\n\nIf no format is given, then the default is `web`.\n\n##### :http-version\n\nThe HTTP version of the request.\n\n##### :method\n\nThe HTTP method of the request.\n\n##### :referrer\n\nThe Referrer header of the request. This will use the standard mis-spelled Referer header if exists, otherwise Referrer.\n\n##### :remote-addr\n\nThe remote address of the request. This will use `req.ip`, otherwise the standard `req.connection.remoteAddress` value (socket address).\n\n##### :remote-user\n\nThe user authenticated as part of Basic auth for the request.\n\n\n##### :response-time\n\nThe time between the request coming into `morgan` and when the response headers are written, in milliseconds.\n\n##### :status\n\nThe status code of the response.\n\n##### :url\n\nThe URL of the request. This will use `req.originalUrl` if exists, otherwise `req.url`.\n\n##### :user-agent\n\nThe contents of the User-Agent header of the request.\n\n### morgan.compile(format)\n\nCompile a format string into a function for use by `morgan`. A format string\nis a string that represents a single log line and can utilize token syntax.\nTokens are references by `:token-name`. If tokens accept arguments, they can\nbe passed using `[]`, for example: `:token-name[pretty]` would pass the string\n`'pretty'` as an argument to the token `token-name`.\n\nNormally formats are defined using `morgan.format(name, format)`, but for certain\nadvanced uses, this compile function is directly available.\n\n\n## Examples\n\n```js\n'use strict';\nconst Koa = require('koa');\nconst app = new Koa();\nconst koaLog = require('koa-log');\n\n\napp.use(koaLog());\n\napp.use(koaLog('dev'));\napp.use((ctx, next) =\u003e {\n\tconst delay = new Promise(function(resolve, reject) {\n\t\tsetTimeout(resolve, 3000);\n\t});\n\treturn delay.then(next);\n});\n\n// response\n\napp.use(ctx =\u003e {\n\tctx.body = 'Hello World';\n});\n\napp.listen(3000);\n\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicanso%2Fkoa-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvicanso%2Fkoa-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvicanso%2Fkoa-log/lists"}