From 8cb7048be6e27abad4c7c6cd76298acc6820ca23 Mon Sep 17 00:00:00 2001 From: indexzero Date: Thu, 29 Oct 2015 00:04:00 -0700 Subject: [PATCH] [breaking] Removed `Logger.prototype.extend` functionality (more maintainable without it). --- README.md | 15 --------------- lib/winston/logger.js | 17 ----------------- test/logger-test.js | 12 ------------ test/winston-test.js | 14 +------------- 4 files changed, 1 insertion(+), 57 deletions(-) diff --git a/README.md b/README.md index 583caf950..14e0dc1aa 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,6 @@ There are two different ways to use winston: directly via the default logger, or * [Events and Callbacks in Winston](#events-and-callbacks-in-winston) * [Working with multiple Loggers in winston](#working-with-multiple-loggers-in-winston) * [Using winston in a CLI tool](#using-winston-in-a-cli-tool) - * [Extending another object with Logging](#extending-another-object-with-logging) * [Filters and Rewriters](#filters-and-rewriters) * [Adding Custom Transports](#adding-custom-transports) * [Installation](#installation) @@ -639,20 +638,6 @@ Configuring output for this style is easy, just use the `.cli()` method on `wins logger.cli(); ``` -### Extending another object with Logging -Often in a given code base with lots of Loggers it is useful to add logging methods to a different object so that these methods can be called with less syntax. Winston exposes this functionality via the 'extend' method: - -``` js - var myObject = {}; - - logger.extend(myObject); - - // - // You can now call logger methods on 'myObject' - // - myObject.info("127.0.0.1 - there's no place like home"); -``` - ### Filters and Rewriters Filters allow modifying the contents of **log messages**, and Rewriters allow modifying the contents of **log meta** e.g. to mask data that should not appear in logs. diff --git a/lib/winston/logger.js b/lib/winston/logger.js index f29e05ac4..85aeebfd6 100755 --- a/lib/winston/logger.js +++ b/lib/winston/logger.js @@ -81,23 +81,6 @@ var Logger = exports.Logger = function (options) { // util.inherits(Logger, events.EventEmitter); -// -// ### function extend (target) -// #### @target {Object} Target to extend. -// Extends the target object with a 'log' method -// along with a method for each level in this instance. -// -Logger.prototype.extend = function (target) { - var self = this; - ['log', 'profile', 'startTimer'].concat(Object.keys(this.levels)).forEach(function (method) { - target[method] = function () { - return self[method].apply(self, arguments); - }; - }); - - return this; -}; - // // ### function log (level, msg, [meta], callback) // #### @level {string} Level at which to log the message. diff --git a/test/logger-test.js b/test/logger-test.js index 2d4335489..31a7b0cbd 100755 --- a/test/logger-test.js +++ b/test/logger-test.js @@ -74,18 +74,6 @@ vows.describe('winton/logger').addBatch({ "the log() method should throw an error": function (logger) { assert.throws(function () { logger.log('anything') }, Error); }, - "the extend() method called on an empty object": { - topic: function (logger) { - var empty = {}; - logger.extend(empty); - return empty; - }, - "should define the appropriate methods": function (extended) { - ['log', 'profile', 'startTimer'].concat(Object.keys(winston.config.npm.levels)).forEach(function (method) { - assert.isFunction(extended[method]); - }); - } - }, "the add() method with a supported transport": { topic: function (logger) { return logger.add(winston.transports.Console); diff --git a/test/winston-test.js b/test/winston-test.js index 599146d15..3337191a9 100644 --- a/test/winston-test.js +++ b/test/winston-test.js @@ -47,19 +47,7 @@ vows.describe('winston').addBatch({ }, "the log() method": helpers.testNpmLevels(winston, "should respond without an error", function (err) { assert.isNull(err); - }), - "the extend() method called on an empty object": { - topic: function (logger) { - var empty = {}; - winston.extend(empty); - return empty; - }, - "should define the appropriate methods": function (extended) { - ['log', 'profile', 'startTimer'].concat(Object.keys(winston.config.npm.levels)).forEach(function (method) { - assert.isFunction(extended[method]); - }); - } - } + }) } }).addBatch({ "The winston module": {