Gergő Tisza has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/191810

Change subject: Make logging less noisy in debug mode
......................................................................

Make logging less noisy in debug mode

Suppress logger console output if the logger is disabled.

Change-Id: I5f45bb7fc68f33880f8a4d1737f0055335fe5071
---
M resources/mmv/logging/mmv.logging.ActionLogger.js
M resources/mmv/logging/mmv.logging.AttributionLogger.js
M resources/mmv/logging/mmv.logging.DimensionLogger.js
M resources/mmv/logging/mmv.logging.DurationLogger.js
M resources/mmv/logging/mmv.logging.Logger.js
M resources/mmv/logging/mmv.logging.PerformanceLogger.js
6 files changed, 42 insertions(+), 8 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer 
refs/changes/10/191810/1

diff --git a/resources/mmv/logging/mmv.logging.ActionLogger.js 
b/resources/mmv/logging/mmv.logging.ActionLogger.js
index 7d55dd0..63fe9bd 100644
--- a/resources/mmv/logging/mmv.logging.ActionLogger.js
+++ b/resources/mmv/logging/mmv.logging.ActionLogger.js
@@ -130,7 +130,9 @@
                var actionText = this.logActions[action] || action,
                        self = this;
 
-               mw.log( actionText );
+               if ( this.isEnabled() ) {
+                       mw.log( actionText );
+               }
 
                if ( forceEventLog || self.isInSample( action ) ) {
                        return this.loadDependencies().then( function () {
@@ -169,6 +171,18 @@
                return Math.floor( Math.random() * factor ) === 0;
        };
 
+       /**
+        * Returns whether logging this event is enabled. This is intended for 
console logging, which
+        * (in debug mode) should be done even if the request is not being 
sampled, as long as logging
+        * is enabled for some sample.
+        * @param {string} action The key representing the action
+        * @returns {boolean} True if this logging is enabled
+        */
+       L.isEnabled = function ( action ) {
+               var factor = this.getActionFactor( action );
+               return $.isNumeric( factor ) && factor >= 1;
+       };
+
        mw.mmv.logging.ActionLogger = ActionLogger;
        mw.mmv.actionLogger = new ActionLogger();
 }( mediaWiki, jQuery, OO ) );
diff --git a/resources/mmv/logging/mmv.logging.AttributionLogger.js 
b/resources/mmv/logging/mmv.logging.AttributionLogger.js
index 330ef30..44d4773 100644
--- a/resources/mmv/logging/mmv.logging.AttributionLogger.js
+++ b/resources/mmv/logging/mmv.logging.AttributionLogger.js
@@ -56,9 +56,12 @@
                        loggedIn: !mw.user.isAnon(),
                        samplingFactor: this.samplingFactor
                };
-               mw.log( 'author: ' + ( data.authorPresent ? 'present' : 
'absent' ) +
-                       ', source: ' + ( data.sourcePresent ? 'present' : 
'absent' ) +
-                       ', license: ' + ( data.licensePresent ? 'present' : 
'absent' ) );
+
+               if ( this.isEnabled() ) {
+                       mw.log( 'author: ' + ( data.authorPresent ? 'present' : 
'absent' ) +
+                               ', source: ' + ( data.sourcePresent ? 'present' 
: 'absent' ) +
+                               ', license: ' + ( data.licensePresent ? 
'present' : 'absent' ) );
+               }
 
                this.log( data );
        };
diff --git a/resources/mmv/logging/mmv.logging.DimensionLogger.js 
b/resources/mmv/logging/mmv.logging.DimensionLogger.js
index ca18f0c..1bcad32 100644
--- a/resources/mmv/logging/mmv.logging.DimensionLogger.js
+++ b/resources/mmv/logging/mmv.logging.DimensionLogger.js
@@ -66,7 +66,10 @@
                        context: context,
                        samplingFactor: this.samplingFactor
                };
-               mw.log( 'mw.mmw.logger.DimensionLogger', data );
+
+               if ( this.isEnabled() ) {
+                       mw.log( 'mw.mmw.logger.DimensionLogger', data );
+               }
 
                this.log( data );
        };
diff --git a/resources/mmv/logging/mmv.logging.DurationLogger.js 
b/resources/mmv/logging/mmv.logging.DurationLogger.js
index 99728fb..591048e 100644
--- a/resources/mmv/logging/mmv.logging.DurationLogger.js
+++ b/resources/mmv/logging/mmv.logging.DurationLogger.js
@@ -136,7 +136,9 @@
                        } );
                }
 
-               mw.log( 'mw.mmw.logger.DurationLogger', e );
+               if ( this.isEnabled() ) {
+                       mw.log( 'mw.mmw.logger.DurationLogger', e );
+               }
 
                this.log( e );
 
diff --git a/resources/mmv/logging/mmv.logging.Logger.js 
b/resources/mmv/logging/mmv.logging.Logger.js
index af36f5e..fffe72c 100644
--- a/resources/mmv/logging/mmv.logging.Logger.js
+++ b/resources/mmv/logging/mmv.logging.Logger.js
@@ -103,6 +103,16 @@
        };
 
        /**
+        * Returns whether logging this event is enabled. This is intended for 
console logging, which
+        * (in debug mode) should be done even if the request is not being 
sampled, as long as logging
+        * is enabled for some sample.
+        * @returns {boolean} True if this logging is enabled
+        */
+       L.isEnabled = function () {
+               return $.isNumeric( this.samplingFactor ) && 
this.samplingFactor >= 1;
+       };
+
+       /**
         * True if the schema has a country field. Broken out in a separate 
function so it's easy to mock.
         * @returns {boolean}
         */
diff --git a/resources/mmv/logging/mmv.logging.PerformanceLogger.js 
b/resources/mmv/logging/mmv.logging.PerformanceLogger.js
index 62c9d83..1d5d310 100644
--- a/resources/mmv/logging/mmv.logging.PerformanceLogger.js
+++ b/resources/mmv/logging/mmv.logging.PerformanceLogger.js
@@ -258,7 +258,7 @@
                                stats.request = Math.round( 
timingEntry.responseStart - timingEntry.requestStart );
                                stats.response = Math.round( 
timingEntry.responseEnd - timingEntry.responseStart );
                                stats.cache = Math.round( 
timingEntry.domainLookupStart - timingEntry.fetchStart );
-                       } else if ( performance.getEntriesByType( 'resource' 
).length === 150 ) {
+                       } else if ( performance.getEntriesByType( 'resource' 
).length === 150 && this.isEnabled() ) {
                                // browser stops logging after 150 entries
                                mw.log( 'performance buffer full, results are 
probably incorrect' );
                        }
@@ -416,7 +416,9 @@
         * @inheritdoc
         */
        PL.log = function ( data ) {
-               mw.log( 'mw.mmv.logging.PerformanceLogger', data );
+               if ( this.isEnabled() ) {
+                       mw.log( 'mw.mmv.logging.PerformanceLogger', data );
+               }
                return mw.mmv.logging.Logger.prototype.log.call( this, data );
        };
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5f45bb7fc68f33880f8a4d1737f0055335fe5071
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MultimediaViewer
Gerrit-Branch: master
Gerrit-Owner: GergÅ‘ Tisza <[email protected]>

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

Reply via email to