Changeset 640503
- Timestamp:
- 12/17/2012 12:41:08 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wp-log-in-browser/trunk/README.txt
r640491 r640503 19 19 To log things manually, you can use: 20 20 21 ´browser()->log ( $var, $label );´ 22 ´browser()->warn ( $var, $label );´ 23 ´browser()->info ( $var, $label );´ 24 ´browser()->error( $var, $label );´ 21 `browser()->log ( $var, $label );` 22 `browser()->warn ( $var, $label );` 23 `browser()->info ( $var, $label );` 24 `browser()->error( $var, $label );` 25 25 26 26 Also, commandas are chainable: 27 27 28 ´browser()->log( 'This is a log...' )->error( '...and this is an error' );´ 28 `browser()->log( 'This is a log...' )->error( '...and this is an error' );` 29 29 30 30 For example, to log all your main query's query_vars: 31 31 32 ´´´add_filter( 'pre_get_posts', 'log_wp_query', 10000 );32 add_filter( 'pre_get_posts', 'log_wp_query', 10000 ); 33 33 34 34 function log_wp_query( $query ) { … … 37 37 38 38 return $query; 39 } ´´´39 } 40 40 41 41 = Filters = … … 43 43 *wplinb-match-wp-debug*: Set to true to only log when wp_debug is true. To prevent logging when wp_debug is false: 44 44 45 add_filter( 'wplinb-match-wp-debug', '__return_true' );´ 45 `add_filter( 'wplinb-match-wp-debug', '__return_true' );` 46 46 47 47 *wplinb-enabled*: To disable logging completely. It takes precedence over *wplinb-match-wp-debug*. To disable logging: 48 48 49 ´add_filter( 'wplinb-enabled', '__return_false' );´ 49 `add_filter( 'wplinb-enabled', '__return_false' );` 50 50 51 51 = Profiling = … … 53 53 The plugin includes a really simple function to allow you to track execution time of different parts of your code. 54 54 55 ´browser()->timer( $key, $log = false );´ 55 `browser()->timer( $key, $log = false );` 56 56 57 57 The first time you call this function with a given $key (string) it will start a timer, and return false. You can start as many timers as you want, using different $key values. You can ignore the second parameter for this first call. … … 61 61 Example 1: Sequential use, log manually. 62 62 63 ´´´browser()->timer( 'Mega loop' );63 browser()->timer( 'Mega loop' ); 64 64 for ( $i = 0; $i < 1000000; $i++ ) { 65 65 //do something 66 66 } 67 67 $time = browser()->timer( 'Mega loop' ); 68 browser()->log( $time, 'The mega loop took:' ); ´´´68 browser()->log( $time, 'The mega loop took:' ); 69 69 70 70 Example 2: Start and end in different places, log automatically. 71 71 72 ´´´add_action( 'posts_selection', 'start_timer', 100 );72 add_action( 'posts_selection', 'start_timer', 100 ); 73 73 add_filter( 'the_posts', 'end_timer', 1, 2 ); 74 74 … … 80 80 browser()->timer( 'Main query time', true ); 81 81 return $posts; 82 } ´´´82 } 83 83 84 84 *This is not a good way of measuring how much time a query takes to run, it's just to illustrate how to use the timer.* … … 86 86 In exactly the same way, you can use the function 87 87 88 ´Browser()->memory( $key, $log = false );´ 88 `Browser()->memory( $key, $log = false );` 89 89 90 90 to measure delta of memory consumption from your first call and your second call with the same $key. … … 92 92 Example: 93 93 94 ´´´Browser()->memory( 'testing' );94 Browser()->memory( 'testing' ); 95 95 $test = array(); 96 96 for ( $i = 0; $i < 100; $i++ ) { … … 105 105 $test[$i] = md5( rand( 1, $i ) ); 106 106 } 107 Browser()->memory( 'testing', true ); 108 ´´´ 107 Browser()->memory( 'testing', true );``` 109 108 110 109 == Installation ==
Note: See TracChangeset
for help on using the changeset viewer.