GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - meatcoder/node-access-log: Add simple access logs to any http or https server

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

15 Commits
15 Commits

Folders and files

NameName
Last commit message
Last commit date
examples
examples
 
 
test
test
 
 
README.md
README.md
 
 
index.js
index.js
 
 
package.json
package.json
 
 

Repository files navigation

access-log

Add simple access logs to any http or https server. This version was forked from the original here. It was modified to make the default log output closer to the typical apache access logs. It also uses util.log as opposed to console.log for the original.

Usage

var http = require('http');
var accesslog = require('access-log');

http.createServer(function(req, res) {
  accesslog(req, res);
  res.end();
}).listen(80, '0.0.0.0');

This will automatically log requests as they come in to the web server that look like...

127.0.0.1 GET 200 /testing (0ms)
127.0.0.1 GET 200 /index.html (0ms)
127.0.0.1 GET 200 /projects (0ms)

Customization

accesslog(req, res, [format], [function])

format

You can pass in a format string, the default is

:ip :method :statusCode ":url" (:deltams)
  • :method - The request method (POST|HEAD|GET|DELETE|PUT, etc.)
  • :statusCode - The response status code sent from the server
  • :url - The requested URL
  • :delta - The latency from request to response in ms
  • :ip - The remote IP

function

You can also pass in your own custom callback, the default is console.log. The only argument passed is the access log string

Example

var format = 'url=":url" method=":method" statusCode=":statusCode" delta=":delta" ip=":ip"';

accesslog(req, res, format, function(s) {
  console.log(s);
});

yields

url="/projects" method="GET" statusCode="200" delta="0" ip="127.0.0.1"
url="/testing" method="GET" statusCode="200" delta="1" ip="127.0.0.1"
url="/index.html" method="GET" statusCode="200" delta="0" ip="127.0.0.1"

Installation

npm install access-log

Extend

Consider further customizing the access logs by using the [log-timestamp] (https://github.com/bahamas10/node-log-timestamp) module to prepend a timestamp automatically.

License

MIT Licensed

About

Add simple access logs to any http or https server

Resources

Readme
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.