Created
November 4, 2012 13:53
-
-
Save thefuxia/4012007 to your computer and use it in GitHub Desktop.
T5 Log Queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: T5 Log Queries | |
* Description: Writes all queries to '/query-log.sql'. | |
* Plugin URI: http://wordpress.stackexchange.com/a/70853/73 | |
* Version: 2012.11.04 | |
* Author: Thomas Scholz | |
* Author URI: http://toscho.de | |
* Licence: MIT | |
*/ | |
add_filter( 'query', 't5_log_queries' ); | |
/** | |
* Write the SQL to a file. | |
* | |
* @wp-hook query | |
* @param string $query | |
* @return string Unchanged query | |
*/ | |
function t5_log_queries( $query ) | |
{ | |
static $first = TRUE; | |
// Change the path here. | |
$log_path = apply_filters( | |
't5_log_queries_path', | |
ABSPATH . 'query-log.sql' | |
); | |
$header = ''; | |
if ( $first ) | |
{ | |
$time = date( 'Y-m-d H:i:s' ); | |
$request = $_SERVER['REQUEST_URI']; | |
$header = "\n\n# -- Request URI: $request, Time: $time ------------\n"; | |
$first = FALSE; | |
} | |
file_put_contents( $log_path, "$header\n$query", FILE_APPEND | LOCK_EX ); | |
return $query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Track it with
tail
: