{"id":20542211,"url":"https://github.com/weivea/fastify-logger","last_synced_at":"2025-07-20T04:33:25.531Z","repository":{"id":83302223,"uuid":"126706912","full_name":"weivea/fastify-logger","owner":"weivea","description":"fastify框架的logger日志工具","archived":false,"fork":false,"pushed_at":"2018-03-28T09:17:10.000Z","size":10,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T04:29:25.024Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/weivea.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2018-03-25T14:39:43.000Z","updated_at":"2024-09-24T03:06:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"8be8e334-72c5-43fb-8d94-226add5ef274","html_url":"https://github.com/weivea/fastify-logger","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/weivea/fastify-logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weivea","download_url":"https://codeload.github.com/weivea/fastify-logger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weivea%2Ffastify-logger/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266067281,"owners_count":23871324,"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":[],"created_at":"2024-11-16T01:29:48.903Z","updated_at":"2025-07-20T04:33:25.473Z","avatar_url":"https://github.com/weivea.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastify-logger\n\n## Install\n\n```shell\nbnpm install fastify-logger --save\n```\n\n## Usage\n\n```javascript\n// \nlet logOpt = {\n  console: process.env.NODE_ENV !== 'production', // 是否开启console.log 。。。\n  level: 'debug',\n  streams: [], // fastify-logger/lib/LogStream.js 的子类\n  format: function(data) {}, // 自定义format\n  genReqId: (function(){ // 请求id生成器\n    var maxInt = 2147483647\n    var nextReqId = 0\n    return function(req) {  \n      return nextReqId = (nextReqId + 1) \u0026 maxInt\n    }\n  })(),\n  serializers: { // 需要的额外数据\n    req: function(req) {\n      return {\n        method: req.xxx\n      }\n    }\n  },\n  file: path.join(process.cwd(), 'logs/fastify.log'), // 文件路径  \n  maxBufferLength: 4096, // 日志写入缓存队列最大长度\n  flushInterval: 1000, // flush间隔\n  logrotator: { // 分割配置\n    byHour: true,\n    byDay: false,    \n    hourDelimiter: '_'\n  }\n}\n\n// 其实只需要配置一下 file字段, 因为线上环境，路径不同，不配置的话使用默认路径\nlogOpt = {\n  file: '/path/to/log/lalala.log'\n}\n\nconst {opt, hook} = require('fastify-logger')(logOpt);\nconst fastify = require('fastify')({\n  logger: opt\n})\nhook(fastify);\n\n// Declare a route\nfastify.get('/', function(request, reply) {\n  request.log.info('123412342234', 'wwwwwwwwwwwww', { as: 23 })\n  reply.send({ hello: 'world' })\n})\n// Run the server!\nfastify.listen(3000, '0.0.0.0', function(err) {\n  if (err) throw err\n  console.log(\n    `server listening on http://${fastify.server.address().address}:${\n      fastify.server.address().port\n    }`\n  )\n})\n\n```\n\n## 扩展stream\n\ncustomSteam.js\n```javascript\nconst LogStream = require('fastify-logger/lib/LogStream')\n\nclass CustomStream extends LogStream {\n  constructor(options) {\n    super(options)\n    // ...自己的逻辑代码\n  }\n  // 复写log方法\n  log(data) {\n    // 想怎么写就怎么写\n  }\n}\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Ffastify-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweivea%2Ffastify-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweivea%2Ffastify-logger/lists"}