Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bithavoc/express-winston
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cf5c5379c9a42789f1192a28dcd1e937e6e2c35e
Choose a base ref
...
head repository: bithavoc/express-winston
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: aed072e64494a5ec1783ed18f75205cafba7f605
Choose a head ref
  • 10 commits
  • 5 files changed
  • 4 contributors

Commits on Jun 16, 2017

  1. Show default colorize value in readme.

    Help (ever so slightly) to clarify confusion in #151.
    rosston committed Jun 16, 2017
    Copy the full SHA
    320cc49 View commit details

Commits on Jul 9, 2017

  1. Ignore custom vimrc files.

    rosston committed Jul 9, 2017
    Copy the full SHA
    245d977 View commit details

Commits on Jan 9, 2018

  1. Fix typo

    RichardMisiak committed Jan 9, 2018
    Copy the full SHA
    674ffee View commit details
  2. Copy the full SHA
    c4e1a5d View commit details

Commits on Feb 12, 2018

  1. Copy the full SHA
    768248a View commit details

Commits on Feb 15, 2018

  1. Copy the full SHA
    1c39ece View commit details
  2. Merge pull request #164 from Kmaschta/master

    Fix memory usage under heavy load in expressWinston.logger
    bithavoc authored Feb 15, 2018
    Copy the full SHA
    a861a56 View commit details
  3. Merge pull request #166 from bithavoc/feature/165

    Fix #165 bump version of lodash due security vuln
    bithavoc authored Feb 15, 2018
    Copy the full SHA
    83514c6 View commit details
  4. Copy the full SHA
    fff53cd View commit details
  5. Version bump 2.5.0

    bithavoc committed Feb 15, 2018
    Copy the full SHA
    aed072e View commit details
Showing with 21 additions and 15 deletions.
  1. +1 −0 .gitignore
  2. +2 −1 AUTHORS
  3. +2 −2 Readme.md
  4. +14 −10 index.js
  5. +2 −2 package.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -17,3 +17,4 @@ npm-debug.log
.DS_Store
lib/.DS_Store
coverage.html
.vimrc
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Heapsource <npm@heapsource.com> (http://www.heapsource.com)
Bithavoc <im@bithavoc.io> (https://bithavoc.io)
Lars Jacob (http://jaclar.net)
Jonathan Lomas (http://floatinglomas.ca)
Xavier Damman (http://xdamman.com)
Quentin Rossetti <quentin.rossetti@gmail.com>
Damian Kaczmarek <rush@rushbase.net>
Robbie Trencheny <me@robbiet.us> (http://robbie.io)
Ross Brandes <ross.brandes@gmail.com>
Kévin Maschtaler (https://www.kmaschta.me)
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ Use `expressWinston.logger(options)` to create a middleware to log your HTTP req
meta: true, // optional: control whether you want to log the meta data about the request (default to true)
msg: "HTTP {{req.method}} {{req.url}}", // optional: customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}"
expressFormat: true, // Use the default Express/morgan request formatting. Enabling this will override any msg if true. Will only output colors with colorize set to true
colorize: true, // Color the text and status code, using the Express/morgan color palette (text: gray, status: default green, 3XX cyan, 4XX yellow, 5XX red).
colorize: false, // Color the text and status code, using the Express/morgan color palette (text: gray, status: default green, 3XX cyan, 4XX yellow, 5XX red).
ignoreRoute: function (req, res) { return false; } // optional: allows to skip some log messages based on request and/or response
}));

@@ -383,7 +383,7 @@ If you set statusLevels to true express-winston will log sub 400 responses at in
}
```

## Dynamica Status Levels
## Dynamic Status Levels

If you set statusLevels to false and assign a function to level, you can customize the log level for any scenario.

24 changes: 14 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -195,6 +195,20 @@ exports.logger = function logger(options) {
options.skip = options.skip || exports.defaultSkip;
options.dynamicMeta = options.dynamicMeta || function(req, res) { return null; };

var expressMsgFormat = "{{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms";
if (options.colorize) {
expressMsgFormat = chalk.grey("{{req.method}} {{req.url}}") +
" {{res.statusCode}} " +
chalk.grey("{{res.responseTime}}ms");
}

var msgFormat = !options.expressFormat ? options.msg : expressMsgFormat;

// Using mustache style templating
var template = _.template(msgFormat, {
interpolate: /\{\{(.+?)\}\}/g
});

return function (req, res, next) {
var coloredRes = {};

@@ -291,25 +305,15 @@ exports.logger = function logger(options) {

meta = _.assign(meta, options.baseMeta);

var expressMsgFormat = "{{req.method}} {{req.url}} {{res.statusCode}} {{res.responseTime}}ms";
if (options.colorize) {
// Palette from https://github.com/expressjs/morgan/blob/master/index.js#L205
var statusColor = 'green';
if (res.statusCode >= 500) statusColor = 'red';
else if (res.statusCode >= 400) statusColor = 'yellow';
else if (res.statusCode >= 300) statusColor = 'cyan';

expressMsgFormat = chalk.grey("{{req.method}} {{req.url}}") +
" {{res.statusCode}} " +
chalk.grey("{{res.responseTime}}ms");
coloredRes.statusCode = chalk[statusColor](res.statusCode);
}
var msgFormat = !options.expressFormat ? options.msg : expressMsgFormat;

// Using mustache style templating
var template = _.template(msgFormat, {
interpolate: /\{\{(.+?)\}\}/g
});

var msg = template({req: req, res: _.assign({}, res, coloredRes)});

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
"middleware",
"colors"
],
"version": "2.4.0",
"version": "2.5.0",
"repository": {
"type": "git",
"url": "https://github.com/bithavoc/express-winston.git"
@@ -48,7 +48,7 @@
},
"dependencies": {
"chalk": "~0.4.0",
"lodash": "~4.11.1"
"lodash": "~4.17.5"
},
"devDependencies": {
"blanket": "^1.2.2",