--- devel.module.old	2009-04-02 13:05:20.000000000 -0500
+++ devel.module	2009-11-04 11:59:50.000000000 -0600
@@ -763,7 +763,49 @@ function devel_shutdown_real() {
           $output .= ob_get_clean();
         }
       }
-
+			// if queries are being logged to a file
+			if ((variable_get('dev_query', FALSE)) && (variable_get('devel_query_file', FALSE))) {
+				$data = ':==' . date('c') . '===  Page: ' . $_GET['q'] . "\n";
+				$data .= $query_summary . "\n";
+				$query_header = "ms \t # \t where \t query \r";
+				$query_data = '';
+				foreach($queries as $query) {
+					// get name of function
+					$ar = explode("\n", $query[0]);
+    			$query_function = array_shift($ar);
+					// get query count
+					$count = isset($counts[$query[0]]) ? $counts[$query[0]] : 0;
+					$query[0]=join(' ',$ar);
+			
+					$diff = round($query[1] * 1000, 2);
+					if ($diff > variable_get('devel_execution', 5)) {
+						$query_count = $diff;
+					}
+					else {
+						$query_count = $diff;
+					}
+					if ($count > 1) {
+						$query_count = $count;
+					}
+					else {
+						$query_count = $count;
+					}	
+					// get SQL that was executed - check_plain is not necessary when writing to file			
+					$pos = strpos($query[0], '*/') !== FALSE ? strpos($query[0], '*/') + 3 : 0;					
+    			$query_sql = substr($query[0], $pos);
+					// get time in milliseconds
+					$query_time = round($query['1'] * 1000, 2);
+					// add to query data table
+					$query_data .= $query_time . "\t" . $query_count . "\t" . $query_function . "\t" . $query_sql . "\r";
+				}
+				// get the file handle and write the data for this page request
+				$file = devel_get_log_file();
+				fwrite($file, $data);
+				fwrite($file, $query_header);
+				fwrite($file, $query_data);
+				fclose($file);
+			}	
+			
       if (variable_get('dev_mem', FALSE) && function_exists('memory_get_usage')) {
         $memory_shutdown = memory_get_usage();
         $args = array('@memory_init' => round($memory_init / 1024 / 1024, 2), '@memory_shutdown' => round($memory_shutdown / 1024 / 1024, 2));
@@ -781,6 +823,17 @@ function devel_shutdown_real() {
   devel_store_queries();
 }
 
+function devel_get_log_file() {
+	// write to a log file under the Drupal directory
+	global $base_path;
+
+  $tmp_dir = variable_get('file_directory_temp', '/tmp');
+	$log_file_path = $_SERVER['DOCUMENT_ROOT'] . $base_path . $tmp_dir . '/queries.tsv';
+  $query_log_file = fopen($log_file_path, 'a+');
+	
+  return $query_log_file;
+}
+
 function devel_store_queries() {
   if (variable_get('devel_store_queries', 0) && rand(1, variable_get('devel_store_random', 1)) == 1) {
     global $active_db, $queries, $db_type;
@@ -929,12 +982,18 @@ function devel_admin_settings() {
     '#title' => t('Display query log'),
     '#default_value' => variable_get('devel_query_display', 0),
     '#description' => t('Display a log of the database queries needed to generate the current page, and the execution time for each. Also, queries which are repeated during a single page view are summed in the # column, and printed in red since they are candidates for caching.'));
+		
+	$form['queries']['devel_query_file'] = array('#type' => 'checkbox',
+    '#title' => t('Log queries to file'),
+    '#default_value' => variable_get('devel_query_file', 0),
+    '#description' => t('Log the database queries to a tab-delimited file in the temporary directory (queries.tsv).'));
+		
   $form['queries']['devel_query_sort'] = array('#type' => 'radios',
     '#title' => t('Sort query log'),
     '#default_value' =>   variable_get('devel_query_sort', DEVEL_QUERY_SORT_BY_SOURCE),
     '#options' => array(t('by source'), t('by duration')),
-    '#description' => t('The query table can be sorted in the order that the queries were executed or by descending duration.'),
-  );
+    '#description' => t('The query table can be sorted in the order that the queries were executed or by descending duration.'));
+		
   $form['queries']['devel_execution'] = array('#type' => 'textfield',
     '#title' => t('Slow query highlighting'),
     '#default_value' => variable_get('devel_execution', 5),
