Skip to content

Instantly share code, notes, and snippets.

@leommoore
Last active November 14, 2024 05:46

Revisions

  1. leommoore revised this gist Nov 18, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions Express_Logging.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    #Express - Logging
    The <a href='http://expressjs.com/'>Express</a> node.js web application framework comes with a built-in logging module called logger and you can use it just like any other Express module:

    The <a href='http://expressjs.com/'>express.js</a> node.js web application framework comes with a built-in logging module called logger which is the <a href='http://www.senchalabs.org/connect/logger.html'>connect.js logger</a>. It is really handy to enable and you can use it just like any other Express module.
    app.use(express.logger());


  2. leommoore revised this gist Nov 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Express_Logging.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #Express - Logging
    Express comes with a built-in logging module called logger and you can use it just like any other Express module:
    The <a href='http://expressjs.com/'>Express</a> node.js web application framework comes with a built-in logging module called logger and you can use it just like any other Express module:

    app.use(express.logger());

  3. leommoore revised this gist Nov 18, 2013. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions Express_Logging.md
    Original file line number Diff line number Diff line change
    @@ -73,7 +73,9 @@ If you prefer, you can customize the precise details to be logged using the the

    To specify the format just specify it like this:

    app.use(express.logger({ format: ':remote-addr :method :url' }));
    app.use(express.logger({
    format: ':remote-addr :method :url' }
    ));

    By default it will log everything to STDOUT but you can also configure it to log to a file like:

    @@ -82,4 +84,7 @@ By default it will log everything to STDOUT but you can also configure it to log
    var fs = require('fs');
    var app = express();

    app.use(express.logger({format: 'tiny', stream: fs.createWriteStream('app.log', {'flags': 'w'})}));
    app.use(express.logger({
    format: 'dev',
    stream: fs.createWriteStream('app.log', {'flags': 'w'})
    }));
  4. leommoore revised this gist Nov 18, 2013. 1 changed file with 12 additions and 11 deletions.
    23 changes: 12 additions & 11 deletions Express_Logging.md
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,14 @@
    #Express - Logging
    Express comes with a built-in logging module called logger and you can use it just like any other Express module:
    Express comes with a built-in logging module called logger and you can use it just like any other Express module:

    app.use(express.logger());

    By default it will log everything to STDOUT but you can also configure it to log to a file like:

    var http = require('http');
    var express = require('express');
    var fs = require('fs');
    var app = express();

    app.use(express.logger({format: 'tiny', stream: fs.createWriteStream('app.log', {'flags': 'w'})}));
    Without any configuration, the logger middleware will generate a detailed log using what is called the default format. The logger actually supports four predefined log formats: default, short ,tiny, and dev. Each of these predefined formats show various amounts of detail. You can specify one of them this way:

    app.use(express.logger('dev'));

    Without any configuration, the logger middleware will generate a detailed log. If you prefer, you can customize the details with the following options to format the output of the logger:
    If you prefer, you can customize the precise details to be logged using the the following options to format the output of the logger:

    <table>
    <tr>
    @@ -79,6 +75,11 @@ To specify the format just specify it like this:

    app.use(express.logger({ format: ':remote-addr :method :url' }));

    By default it will log everything to STDOUT but you can also configure it to log to a file like:

    The logger supports four predefined log formats: default, short ,tiny, and dev. Each of these predefined formats show various amounts of detail. You can specify one of them this way:
    app.use(express.logger('dev'));
    var http = require('http');
    var express = require('express');
    var fs = require('fs');
    var app = express();

    app.use(express.logger({format: 'tiny', stream: fs.createWriteStream('app.log', {'flags': 'w'})}));
  5. leommoore revised this gist Nov 18, 2013. 1 changed file with 42 additions and 1 deletion.
    43 changes: 42 additions & 1 deletion Express_Logging.md
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,15 @@ Express comes with a built-in logging module called logger and you can use it j

    app.use(express.logger());

    By default it will log everything to STDOUT but you can also configure it to log to a file like:

    var http = require('http');
    var express = require('express');
    var fs = require('fs');
    var app = express();

    app.use(express.logger({format: 'tiny', stream: fs.createWriteStream('app.log', {'flags': 'w'})}));

    Without any configuration, the logger middleware will generate a detailed log. If you prefer, you can customize the details with the following options to format the output of the logger:

    <table>
    @@ -39,5 +48,37 @@ Without any configuration, the logger middleware will generate a detailed log. I
    <td>Date and time of request</td>
    </tr>

    <tr>
    <td>:method</td>
    <td>The HTTP method used for making the request</td>
    </tr>

    <tr>
    <td>:url</td>
    <td>The requested URL</td>
    </tr>

    <tr>
    <td>:referrer</td>
    <td>The URL that referred the current URL</td>
    </tr>

    <tr>
    <td>:user-agent</td>
    <td>The user-agent signature</td>
    </tr>

    <tr>
    <td>:status</td>
    <td>The HTTP statusL</td>
    </tr>

    </table>


    To specify the format just specify it like this:

    app.use(express.logger({ format: ':remote-addr :method :url' }));


    The logger supports four predefined log formats: default, short ,tiny, and dev. Each of these predefined formats show various amounts of detail. You can specify one of them this way:
    app.use(express.logger('dev'));
  6. leommoore created this gist Nov 18, 2013.
    43 changes: 43 additions & 0 deletions Express_Logging.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    #Express - Logging
    Express comes with a built-in logging module called logger and you can use it just like any other Express module:

    app.use(express.logger());

    Without any configuration, the logger middleware will generate a detailed log. If you prefer, you can customize the details with the following options to format the output of the logger:

    <table>
    <tr>
    <th>Token</th>
    <th>Content</th>
    </tr>
    <tr>
    <td>:req[header]</td>
    <td>The specific HTTP header of the request</td>
    </tr>
    <tr>
    <td>:res[header]</td>
    <td>The specific HTTP header of the response</td>
    </tr>

    <tr>
    <td>:http-version</td>
    <td>The HTTP version</td>
    </tr>

    <tr>
    <td>:response-time</td>
    <td>How long it took to generate the response</td>
    </tr>

    <tr>
    <td>:remote-addr</td>
    <td>The user agent's IP address</td>
    </tr>

    <tr>
    <td>:date</td>
    <td>Date and time of request</td>
    </tr>

    </table>