Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

wolfeidau/winston-request-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

winston-request-logger

Winston http request logger for express which is loosely based on express-request-logger.

Build Status

Getting Started

In an existing express project you can add the following configuration fragment to enable request logging to console, with colors while in development or test.

    app.configure('development', 'test', function(){
        // Request Logging
        var logger = new (winston.Logger)({ transports: [ new (winston.transports.Console)({colorize:true}) ] });
        app.use(require('winston-request-logger').create(logger));
    });

Custom formats

You can optionally specify a second argument to create(logger, [format]) to customize the object sent to Winston:

	app.use(require('winston-request-logger').create(logger, {
		'responseTime': ':responseTime ms',		// outputs '5 ms'
		'url': ':url[pathname]'					// outputs '/some/path'
	}));

Format tokens:

  • :date - Timestamp of the request.
  • :statusCode - HTTP status code of the request.
  • :method - HTTP method (GET, POST, etc.)
  • :url[segment] - Segment of the URL requested (Refer to the url module for options).
  • :responseTime - Time it took for the response (in milliseconds).
  • :ip - The client's IP address (looks to X-forwarded-for header first).
  • :userAgent - The client's browser agent (parsed with useragent.

Contributors

Mark WolfeGitHub/wolfeidauTwitter/@wolfeidau
Evan DudlaGitHub/evNNTwitter/@evandudla

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

License

Copyright (c) 2013 Mark Wolfe
Licensed under the MIT license.

About

Winston based http request logger for express.

Resources

License

Stars

Watchers

Forks

Packages

No packages published