{"id":13800520,"url":"https://github.com/dominhhai/koa-log4js","last_synced_at":"2025-08-21T02:31:30.866Z","repository":{"id":57289401,"uuid":"56642714","full_name":"dominhhai/koa-log4js","owner":"dominhhai","description":"log4js-node supports Koa-middleware","archived":false,"fork":false,"pushed_at":"2020-02-27T08:58:59.000Z","size":24,"stargazers_count":82,"open_issues_count":5,"forks_count":16,"subscribers_count":4,"default_branch":"v2.x","last_synced_at":"2024-12-09T06:23:25.317Z","etag":null,"topics":["koa","koa-log4js","koa-middleware","log4js-node","logger-middleware"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/koa-log4","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/dominhhai.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":"2016-04-20T00:43:48.000Z","updated_at":"2024-10-16T07:45:08.000Z","dependencies_parsed_at":"2022-09-08T15:30:38.482Z","dependency_job_id":null,"html_url":"https://github.com/dominhhai/koa-log4js","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominhhai%2Fkoa-log4js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominhhai%2Fkoa-log4js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominhhai%2Fkoa-log4js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dominhhai%2Fkoa-log4js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dominhhai","download_url":"https://codeload.github.com/dominhhai/koa-log4js/tar.gz/refs/heads/v2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230046462,"owners_count":18164467,"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","koa-log4js","koa-middleware","log4js-node","logger-middleware"],"created_at":"2024-08-04T00:01:13.349Z","updated_at":"2024-12-19T18:15:57.070Z","avatar_url":"https://github.com/dominhhai.png","language":"JavaScript","funding_links":[],"categories":["仓库"],"sub_categories":["中间件"],"readme":"# koa-log4js\nA wrapper for [log4js-node](https://github.com/nomiddlename/log4js-node) which support [Koa](https://github.com/koajs/koa) logger middleware.\nLog message is forked from Express (Connect) logger [file](https://github.com/nomiddlename/log4js-node/blob/master/lib/connect-logger.js).\n\n## Note\nThis branch is use to [Koa v2.x](https://github.com/koajs/koa/tree/v2.x).\nTo use Koa v0.x \u0026 v1.x, please check the [master](https://github.com/dominhhai/koa-log4js/tree/master) branch.\n\n## Installation\n\n#### for koa v0.x \u0026 v1.x\n```\n$ npm i --save koa-log4@1\n```\n\n#### for koa v2.x\n```\n$ npm i --save koa-log4@2\n```\n\n___The default logger is for [koa v2.x](https://github.com/koajs/koa/tree/v2.x)___\n```\n$ npm i --save koa-log4\n```\n\n## Usage\nConfig koa-log4js is same as the original [log4js-node](https://github.com/nomiddlename/log4js-node).\n\n### Normal log4js way\nThis way is same as the original [log4js-node](https://github.com/nomiddlename/log4js-node).\n\n```javascript\nconst log4js = require('koa-log4')\n\nconst log = log4js.getLogger('index')\nlog.info('index do some awesome things')\n```\n\n### Koa-middleware way\nSimilar to use Express (Connect) logger middleware.\n\n```javascript\nconst log4js = require('koa-log4')\napp.use(log4js.koaLogger(log4js.getLogger(\"http\"), { level: 'auto' }))\n```\n\nThere are more configuration options:\n\n```javascript\nconst log4js = require(\"koa-log4\")\napp.use(log4js.koaLogger(\n    // the logger to log to\n    log4js.getLogger(\"http\"),\n    // the options object\n    {\n        // select the level all access logs will be set to, or use \"auto\" to choose depending on the status code (see next option)\n        level: \"auto\",\n        // if `level` is set to \"auto\" the default rule will map 200-299 to INFO, 300-399 to WARN and 400-599 to ERROR.\n        // you can override this behavior by setting your own custom levelMapper.\n        // (the example is the default implementation, do not copy unless you want to modify it)\n        levelMapper: function(statusCode) {\n            if (statusCode \u003e= 400)\n                return levels.ERROR\n            if (statusCode \u003e= 300)\n                return levels.WARN\n            return levels.INFO\n        }\n    }\n))\n```\n\n## Full Example\nCheck [this repo](https://github.com/dominhhai/koa-log4js-example/tree/v2.x) for full example with `Koa v2`.\n\n## Others\nSee [here](https://github.com/nomiddlename/log4js-node) for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominhhai%2Fkoa-log4js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdominhhai%2Fkoa-log4js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdominhhai%2Fkoa-log4js/lists"}