Skip to content

Instantly share code, notes, and snippets.

@yratof
Created September 19, 2016 23:04
Show Gist options
  • Save yratof/d5edb37996572bdb4d959d156754c9cc to your computer and use it in GitHub Desktop.
Save yratof/d5edb37996572bdb4d959d156754c9cc to your computer and use it in GitHub Desktop.
query logging
<?php
/* SQL LOGGING FOR PAGES */
add_action( 'shutdown', 'sql_logger' );
function sql_logger() {
global $wpdb;
$log_file = fopen( ABSPATH.'/sql_log.txt', 'a' );
fwrite( $log_file, "//////////////////////////////////////////\n\n" . date( 'F j, Y, g:i:s a' )."\n" );
foreach ( $wpdb->queries as $q ) {
fwrite( $log_file, $q[0] . " - ( $q[1] s )" . "\n\n" );
}
fclose( $log_file );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment