Ori.livneh has uploaded a new change for review.

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

Change subject: Add quick-n-dirty logging function hackLog()
......................................................................

Add quick-n-dirty logging function hackLog()

I use this often when debugging issues in production. It doesn't rely on any
specific library or MediaWiki feature, so it is useful when you need something
that will work when other code breaks.

Change-Id: I1397655cc4250dc243b4911bdaca61311d5bb857
---
M wmf-config/StartProfiler.php
1 file changed, 29 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/mediawiki-config 
refs/changes/85/277585/1

diff --git a/wmf-config/StartProfiler.php b/wmf-config/StartProfiler.php
index 326ae90..cfb2f27 100644
--- a/wmf-config/StartProfiler.php
+++ b/wmf-config/StartProfiler.php
@@ -5,6 +5,35 @@
 // NOTE: this file is loaded early on in WebStart.php, so be careful with
 // globals.
 
+// Quick and dirty logging function for local debugging.
+function hackLog() {
+       static $reqId;
+
+       $reqId = $reqId ?: md5( rand() );
+       $timeStamp = date( 'r' );
+
+       $lines = array_map( function ( $arg ) {
+               return json_encode( $arg,
+                       JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
+       }, func_get_args() );
+
+       $lines[] = implode( ' → ', array_map( function ( $item ) {
+               return isset( $item['type'] )
+                       ? $item['class'] . $item['type'] . $item['function'] . 
'()'
+                       : $item['function'] . '()';
+       }, array_reverse( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ) ) ) );
+
+       $msg = '';
+       $lineCount = count( $lines );
+       foreach ( $lines as $idx => $line ) {
+               $msg .= sprintf( "%s [%.6s] #%02d/%02d: %s\n", $timeStamp, 
$reqId, $idx
+                       + 1, $lineCount, $line );
+       }
+
+       file_put_contents( '/tmp/hack.log', $msg, FILE_APPEND );
+}
+
+
 if ( ini_get( 'hhvm.stats.enable_hot_profiler' ) ) {
        // Single-request profiling, via 'forceprofile=1' (web) or 
'--profiler=text' (CLI).
        if (

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1397655cc4250dc243b4911bdaca61311d5bb857
Gerrit-PatchSet: 1
Gerrit-Project: operations/mediawiki-config
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <o...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to