{"id":18631342,"url":"https://github.com/bahamas10/node-access-log","last_synced_at":"2025-04-11T06:32:07.457Z","repository":{"id":57172385,"uuid":"6515779","full_name":"bahamas10/node-access-log","owner":"bahamas10","description":"Add simple access logs to any http or https server","archived":false,"fork":false,"pushed_at":"2022-11-22T00:52:53.000Z","size":25,"stargazers_count":9,"open_issues_count":2,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-25T10:37:49.691Z","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/bahamas10.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}},"created_at":"2012-11-03T02:55:13.000Z","updated_at":"2019-09-01T16:36:02.000Z","dependencies_parsed_at":"2023-01-23T17:15:53.867Z","dependency_job_id":null,"html_url":"https://github.com/bahamas10/node-access-log","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahamas10%2Fnode-access-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahamas10%2Fnode-access-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahamas10%2Fnode-access-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahamas10%2Fnode-access-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahamas10","download_url":"https://codeload.github.com/bahamas10/node-access-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248356333,"owners_count":21090189,"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-07T05:06:42.931Z","updated_at":"2025-04-11T06:32:07.152Z","avatar_url":"https://github.com/bahamas10.png","language":"JavaScript","readme":"access-log\n==========\n\nAdd simple access logs to any http or https server\n\nUsage\n-----\n\n``` js\nvar http = require('http');\nvar accesslog = require('access-log');\n\nhttp.createServer(function(req, res) {\n  accesslog(req, res);\n  res.end();\n}).listen(80, '0.0.0.0');\n```\n\nThis will automatically log requests as they come in to the\nweb server that look like...\n\n```\n127.0.0.1 - - [13/Sep/2013:01:38:09 -0400] \"GET / HTTP/1.1\" 200 - \"-\" \"-\"\n127.0.0.1 - - [13/Sep/2013:01:38:09 -0400] \"GET /testing HTTP/1.1\" 200 - \"-\" \"-\"\n127.0.0.1 - - [13/Sep/2013:01:38:10 -0400] \"GET /index.html HTTP/1.1\" 200 - \"-\" \"-\"\n```\n\nCustomization\n-------------\n\n### accesslog(req, res, [opts], [function])\n\n#### opts\n\nOpts is an object that can contain a format identifier and userID func (both optional).\n\nFor example,\n\n``` js\n{\n    userID: function (req) { return req.user; },\n    format : 'url=\":url\" method=\":method\" statusCode=\":statusCode\" delta=\":delta\" ip=\":ip\"'\n}\n```\n\nYou can pass in a format string, the default is Apache Common Log Format\nhttp://en.wikipedia.org/wiki/Common_Log_Format\n\nIf `opts` is a string, it is assumed to be the `opts.format` property.\n\n```\n:ip - :userID [:clfDate] \":method :url :protocol/:httpVersion\" :statusCode :contentLength \":referer\" \":userAgent\"\n```\n\n- `clfDate`: The date of the end of the response in Apache Common Log format\n- `contentLength`: The response `Content-Length` header, or `-` if unset\n- `delta`: The time in ms from request to response\n- `endDate`: The ISO formatted string when the response was ended\n- `endTime`: The epoch time when the response was ended\n- `host`: The host header from the request if set\n- `httpVersion`: The HTTP version used (ie. `1.0`, `1.1`)\n- `ip`: The remote IP\n- `Xip`: The remote IP, using `X-Forwarded-For` if set\n- `method`: The HTTP method\n- `protocol`: `HTTP` or `HTTPS`\n- `referer`: The request `Referer` header, or `-` if unset\n- `startDate`: The ISO formatted string when the request was received\n- `startTime`: The epoch time when the request was received\n- `statusCode`: The response status code sent from the server\n- `url`: The requested URL\n- `urlDecoded`: The decoded request URL (ie. `%20` =\u003e ` `)\n- `userID`: The username if applicable\n- `userAgent`: The request `User-Agent` header, or `-` if unset\n\n**NOTE:** Wrap variables in `{}` to protect against unwanted interpolation.\n\nex:\n\n```\nrequest to :url took :{delta}ms\n```\n\n#### function\n\nYou can also pass in your own custom callback, the default is `console.log`.\nThe only argument passed is the access log string\n\nExample\n-------\n\n``` js\nvar format = 'url=\":url\" method=\":method\" statusCode=\":statusCode\" delta=\":delta\" ip=\":ip\"';\n\naccesslog(req, res, format, function(s) {\n  console.log(s);\n});\n```\n\nyields\n\n```\nurl=\"/projects\" method=\"GET\" statusCode=\"200\" delta=\"0\" ip=\"127.0.0.1\"\nurl=\"/testing\" method=\"GET\" statusCode=\"200\" delta=\"1\" ip=\"127.0.0.1\"\nurl=\"/index.html\" method=\"GET\" statusCode=\"200\" delta=\"0\" ip=\"127.0.0.1\"\n```\n\nInstallation\n------------\n\n    npm install access-log\n\nExtend\n------\n\nConsider further customizing the access logs by using the [log-timestamp]\n(https://github.com/bahamas10/node-log-timestamp) module to prepend a timestamp\nautomatically.\n\nLicense\n-------\n\nMIT Licensed\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahamas10%2Fnode-access-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahamas10%2Fnode-access-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahamas10%2Fnode-access-log/lists"}