jenkins-bot has submitted this change and it was merged.
Change subject: Zap logger enterContext / leaveContext / renameContext
......................................................................
Zap logger enterContext / leaveContext / renameContext
Mostly unused methods let you get in a mess.
Bug: T129946
Change-Id: I0c5f55f6d4fc340c89f7732200cce5c1746c271a
---
M Core/Http/RequestHandler.php
M Core/Logging/Logger.php
M Core/Logging/TaggedLogger.php
M Maintenance/MaintenanceBase.php
M Tests/BaseSmashPigUnitTestCase.php
5 files changed, 12 insertions(+), 92 deletions(-)
Approvals:
Awight: Looks good to me, approved
jenkins-bot: Verified
diff --git a/Core/Http/RequestHandler.php b/Core/Http/RequestHandler.php
index 4a645fb..552a243 100644
--- a/Core/Http/RequestHandler.php
+++ b/Core/Http/RequestHandler.php
@@ -47,9 +47,13 @@
// --- Initialize core services ---
$config = new Configuration( $view );
- Logger::init( $config->val( 'logging/root-context' ),
$config->val( 'logging/log-level' ), $config );
Context::init( $config );
- Logger::enterContext( Context::get()->getContextId() );
+ Logger::init(
+ $config->val( 'logging/root-context' ),
+ $config->val( 'logging/log-level' ),
+ $config,
+ Context::get()->getContextId()
+ );
if ( $config->nodeExists( 'disabled' ) && $config->val(
'disabled' ) ) {
Logger::debug( '403 will be given for disabled view.',
$uri );
diff --git a/Core/Logging/Logger.php b/Core/Logging/Logger.php
index 4877053..5d4c0de 100644
--- a/Core/Logging/Logger.php
+++ b/Core/Logging/Logger.php
@@ -20,11 +20,12 @@
* @param string $name Root context name
* @param int $threshold Minimum log level to record into the
context
* @param Configuration $config Configuration object to use
+ * @param string $prefix Base prefix for logger
*
* @throws \SmashPig\Core\SmashPigException if the logging framework
was attempted
* to be initialized twice
*/
- static function init( $name, $threshold, Configuration $config ) {
+ static function init( $name, $threshold, Configuration $config, $prefix
) {
if ( self::$context ) {
throw new SmashPigException( "Attempting to
reinitialize the logger is not allowed!" );
}
@@ -47,6 +48,7 @@
}
self::$context = new LogContextHandler( $name, $streamObjs );
+ self::$context->enterContext( $prefix );
self::$threshold = $threshold;
}
@@ -77,48 +79,6 @@
throw new SmashPigException( "No context available.
Logger not initialized?" );
}
return Logger::$context;
- }
-
- /**
- * Enters a new context with the current context as its parent.
- * Shadows @ref LogContextHandler->enterContext()
- *
- * @param string $name Child context name
- */
- public static function enterContext( $name ) {
- static::$context->enterContext( $name );
- }
-
- /**
- * Renames the current logging context. Effects the log prefix used for
all
- * events under this context. May have adverse effects on logstreams
that log
- * in real time (IE: Syslog) because they will have logged items under
the old
- * context name.
- *
- * Shadows @ref LogContextHandler->renameContext()
- *
- * @param string $newName New name for the current context
- * @param bool $addLogEntry If false will not create a log line
stating the name change
- *
- * @return string The old name of this context
- */
- public static function renameContext( $newName, $addLogEntry = true ) {
- return static::$context->renameContext( $newName, $addLogEntry
);
- }
-
- /**
- * Leaves the current context for the parent context. You may not leave
the root
- * context.
- *
- * Side effects include removing all stored log lines for this context.
Before this
- * happens all LogStreams have the opportunity to do last chance
processing.
- *
- * Shadows @ref LogContextHandler->leaveContext()
- *
- * @return string|bool The current context name, or false if this is
the root context
- */
- public static function leaveContext() {
- return static::$context->leaveContext();
}
/* === EVENT HANDLING === */
diff --git a/Core/Logging/TaggedLogger.php b/Core/Logging/TaggedLogger.php
index 55aa740..fe51f23 100644
--- a/Core/Logging/TaggedLogger.php
+++ b/Core/Logging/TaggedLogger.php
@@ -22,49 +22,6 @@
$this->context = Logger::getContext();
}
- /* === CONTEXT HELPER METHODS === */
- /**
- * Enters a new context with the current context as its parent.
- * Shadows @ref LogContextHandler->enterContext()
- *
- * @param string $name Child context name
- */
- public static function enterContext( $name ) {
- Logger::enterContext( $name );
- }
-
- /**
- * Renames the current logging context. Effects the log prefix used for
all
- * events under this context. May have adverse effects on logstreams
that log
- * in real time (IE: Syslog) because they will have logged items under
the old
- * context name.
- *
- * Shadows @ref LogContextHandler->renameContext()
- *
- * @param string $newName New name for the current context
- * @param bool $addLogEntry If false will not create a log line
stating the name change
- *
- * @return string The old name of this context
- */
- public static function renameContext( $newName, $addLogEntry = true ) {
- return Logger::renameContext( $newName, $addLogEntry );
- }
-
- /**
- * Leaves the current context for the parent context. You may not leave
the root
- * context.
- *
- * Side effects include removing all stored log lines for this context.
Before this
- * happens all LogStreams have the opportunity to do last chance
processing.
- *
- * Shadows @ref LogContextHandler->leaveContext()
- *
- * @return string|bool The current context name, or false if this is
the root context
- */
- public static function leaveContext() {
- return Logger::leaveContext();
- }
-
/* === EVENT HANDLING === */
/**
* Log an immediate/critical failure. Will be immediately forwarded to
the designated
diff --git a/Maintenance/MaintenanceBase.php b/Maintenance/MaintenanceBase.php
index f135966..28b0ae1 100644
--- a/Maintenance/MaintenanceBase.php
+++ b/Maintenance/MaintenanceBase.php
@@ -137,11 +137,10 @@
Logger::init(
$config->val( 'logging/root-context' ) . '-' . end(
explode( "\\", $maintClass ) ),
$config->val( 'logging/log-level' ),
- $config
+ $config,
+ Context::get()->getContextId()
);
Logger::getContext()->addLogStream( new ConsoleLogStream() );
-
- Logger::enterContext( Context::get()->getContextId() );
set_error_handler(
'\SmashPig\Maintenance\MaintenanceBase::lastChanceErrorHandler' );
set_exception_handler(
'\SmashPig\Maintenance\MaintenanceBase::lastChanceExceptionHandler' );
diff --git a/Tests/BaseSmashPigUnitTestCase.php
b/Tests/BaseSmashPigUnitTestCase.php
index 4d0b27c..1fc34d4 100644
--- a/Tests/BaseSmashPigUnitTestCase.php
+++ b/Tests/BaseSmashPigUnitTestCase.php
@@ -36,7 +36,7 @@
Context::init( $config );
if ( !self::$loggerCreated ) {
// Don't care which config the logger gets, let's just
not explode
- Logger::init( 'test', 'debug', $config );
+ Logger::init( 'test', 'debug', $config, 'test' );
self::$loggerCreated = true;
}
return $config;
--
To view, visit https://gerrit.wikimedia.org/r/286255
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0c5f55f6d4fc340c89f7732200cce5c1746c271a
Gerrit-PatchSet: 3
Gerrit-Project: wikimedia/fundraising/SmashPig
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits