Skip to content

Mujib517/true-log

Repository files navigation

True Log

An Http Request Logger

Installation

npm install true-log --save

Integration

    var express = require('express');
    var trueLog = require('true-log');
    var app = express();

    var port = process.env.PORT || 3000;

    //register it as a middleware
    app.use(trueLog());
    
    app.listen(port, function () {
        console.log("Server is running on " + port);
    });

    app.get('/', function (req, res) {
        res.send("True logger works");
    });

Log Level

Tiny

 var trueLog = require('true-log');
 app.use(trueLog({level:'tiny'}));

Logs: Client IP, Date, Method, Url, UserAgent

Full

 app.use(trueLog({level:'full'}));

Logs: Client IP, Date, Method, Url, UserAgent, Response Time and Status code

Logging to File

By default logs would be written to console but you can redirect logs to a file by passing a writeable stream

var ws = fs.createWriteStream(path.join(__dirname, "log.txt"), { flags: 'a' });
app.use(trueLog({level:'full',stream:ws}));

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published