GithubHelp home page GithubHelp logo

fxmontigny / http-logger Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hashirhussain/http-logger

0.0 0.0 0.0 5 KB

A cute and simple middleware for node.js that writes/log all HTTP requests to a file

License: MIT License

JavaScript 100.00%

http-logger's Introduction

http-logger

A cute and simple middleware for node.js to write/log all HTTP requests to a file.

Usage

var logger = require('http-logger');

logger(options)

Create a http-logger middleware function using the given options. The options argument must be a object of a predefined properties (see below for the properties).

All the options are optional

Options

http-logger accepts three properties in the options object.

dir
  • Type : String
  • Optional : Yes
  • Default value :'http_logger'

Directory name where you want to log the requests. Only pass directory name.

e.g.

logger({
dir:'logToThisFolder'
});
file
  • Type : String
  • Optional : Yes
  • Default value :'http_logger'

File name where you want to log the requests. Only pass file name.

e.g.

logger({
file:'logToThisFile'
});
dateWise
  • Type : Boolean
  • Optional : Yes
  • Default value :false

If set true then new log file will generate each day.

e.g.

logger({
dateWise:true
});
callback
  • Type : Function
  • Optional : Yes
  • Default value :empty function

Callback function return logs.

e.g.

logger({
callback:function(log) {
    console.log(log);
}
});
saveToFile
  • Type : Boolean
  • Optional : Yes
  • Default value :true

If set false no logs have been written into the file.

e.g.

logger({
saveToFile:'false'
});

Example

// Require the ingredients we need
var express = require("express");
var http = require("http");
var logger = require("http-logger");

// Build the app
var app = express();

// Use our middleware
app.use(logger());

// Add some middleware
app.use(function(req, res) {
  res.writeHead(200, { "Content-Type": "text/plain" });
  res.end("Hello world!");
});

// Start it up!
http.createServer(app).listen(3000);

http-logger's People

Contributors

hashirhussain avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.