jenkins-bot has submitted this change and it was merged.

Change subject: Inherit from LogData to add locationData
......................................................................


Inherit from LogData to add locationData

Change-Id: I38e87211d32b524a1105b1757fd33121cf34489a
---
M lib/Logger.bunyan.js
M lib/Logger.js
M lib/ParsoidLogger.js
M lib/linter.js
4 files changed, 49 insertions(+), 28 deletions(-)

Approvals:
  Subramanya Sastry: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/Logger.bunyan.js b/lib/Logger.bunyan.js
index 989ae59..fd235b9 100644
--- a/lib/Logger.bunyan.js
+++ b/lib/Logger.bunyan.js
@@ -63,14 +63,10 @@
        return logger.bind(this._logger);
 };
 
-BunyanLogger.prototype._createBunyanLog = function (logData) {
-       var location = logData.locationData();
-       var log = {
-               logType: logData.logType,
-               wiki: location.wiki,
-               title: location.title,
-               oldid: location.oldid
-       };
+BunyanLogger.prototype._createBunyanLog = function(logData) {
+       var log = Object.create(logData.locationData, {
+               logType: { value: logData.logType }
+       });
        var flat = logData.flatLogObject();
        Object.keys(flat).forEach(function(k) {
                // Be sure we don't have a `type` field here since logstash
diff --git a/lib/Logger.js b/lib/Logger.js
index 982cd27..d658a23 100644
--- a/lib/Logger.js
+++ b/lib/Logger.js
@@ -27,6 +27,10 @@
        this._testAllRE = new RegExp(/^$/);
 };
 
+Logger.prototype._createLogData = function( logType, logObject ) {
+       return new LogData( logType, logObject );
+};
+
 /**
  * @method
  *
@@ -41,7 +45,7 @@
                // Tests whether logType matches any of the applicable logTypes
                if (this._testAllRE.test(logType)) {
                        var logObject = Array.prototype.slice.call(arguments, 
1);
-                       var logData = new LogData(logType, logObject);
+                       var logData = this._createLogData( logType, logObject );
                        // If we are already processing a log request, but a 
log was generated
                        // while processing the first request, 
processingLogRequest will be true.
                        // We ignore all follow-on log events unless they are 
fatal. We put all
diff --git a/lib/ParsoidLogger.js b/lib/ParsoidLogger.js
index 5d57fd7..a649385 100644
--- a/lib/ParsoidLogger.js
+++ b/lib/ParsoidLogger.js
@@ -5,16 +5,32 @@
        Util = require( './mediawiki.Util.js' ).Util,
        coreutil = require('util');
 
+
+function LocationData( wiki, title, meta ) {
+       this.wiki = wiki;
+       this.title = title;
+       this.oldId = ( meta && meta.revision && meta.revision.revid ) ?
+               meta.revision.revid : null;
+}
+LocationData.prototype.toString = function() {
+       return coreutil.format(
+               "[%s/%s%s]", this.wiki, this.title,
+               this.oldId ? "?oldid=" + this.oldId : ""
+       );
+};
+
+
+function ParsoidLogData( logType, logObject, locationData ) {
+       this.locationData = locationData;
+       LogData.call( this, logType, logObject );
+}
+coreutil.inherits( ParsoidLogData, LogData );
+
+
 function ParsoidLogger(env) {
        this.env = env;
        Logger.apply(this, {});
-
-       // Set up a location message function in Logdata
-       // so all logging backends can output location message
-       var logger = this;
-       LogData.prototype.locationData = function() { return 
logger.locationData(this); };
 }
-
 coreutil.inherits(ParsoidLogger, Logger);
 
 ParsoidLogger.prototype.getDefaultBackend = function() {
@@ -77,25 +93,27 @@
        }
 };
 
-ParsoidLogger.prototype.locationData = function(logData) {
-       var data = { wiki: this.env.conf.wiki.iwp, title: this.env.page.name };
-       data.msg = '[' + this.env.conf.wiki.iwp + '/' + this.env.page.name;
-       var meta = this.env.page.meta;
-       if (meta && meta.revision && meta.revision.revid) {
-               data.oldId = meta.revision.revid;
-               data.msg += '?oldid=' + meta.revision.revid;
-       }
-       data.msg = data.msg + ']';
-       return data;
+ParsoidLogger.prototype._createLogData = function( logType, logObject ) {
+       return new ParsoidLogData( logType, logObject, this.locationData() );
+};
+
+// Set up a location message function in Logdata
+// so all logging backends can output location message
+ParsoidLogger.prototype.locationData = function() {
+       return new LocationData(
+               this.env.conf.wiki.iwp,
+               this.env.page.name,
+               this.env.page.meta
+       );
 };
 
 ParsoidLogger.prototype._defaultBackend = function(logData, cb) {
        // The default logging backend provided by Logger.js is not useful to 
us.
        // Parsoid needs to be able to emit page location to logs.
        try {
-               console.warn('[' + logData.logType + ']' + 
logData.locationData().msg + ' ' + logData.fullMsg());
+               console.warn( "[%s]%s %s", logData.logType, 
logData.locationData.toString(), logData.fullMsg() );
        } catch(e){
-               console.error("Error in ParsoidLogger._defaultBackend: " + e);
+               console.error( "Error in ParsoidLogger._defaultBackend: %s", e 
);
        } finally{
                cb();
        }
diff --git a/lib/linter.js b/lib/linter.js
index 8071fdb..ea2e009 100644
--- a/lib/linter.js
+++ b/lib/linter.js
@@ -57,12 +57,15 @@
                        wiki = this._env.conf.wiki.iwp;
 
                msg.type = logType.match(re)[1];
-               msg.location = logData.locationData().msg;
                msg.wiki = wiki;
                msg.page = this._env.page.name;
                msg.revision = this._env.page.meta.revision.revid;
                msg.wikiurl = 
this._env.conf.parsoid.interwikiMap.get(wiki).split('/w/')[0];
 
+               if ( logData.locationData ) {
+                       msg.location = logData.locationData.toString();
+               }
+
                if (dsr) {
                        msg.dsr = dsr;
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/169272
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I38e87211d32b524a1105b1757fd33121cf34489a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: Marcoil <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to