diff --git a/html/inc/submit_util.inc b/html/inc/submit_util.inc index 12e7181217..3daebe8ba2 100644 --- a/html/inc/submit_util.inc +++ b/html/inc/submit_util.inc @@ -21,22 +21,26 @@ require_once("../inc/submit_db.inc"); -$log_file = null; -$verbose = true; - +// write status and error messages to log +// function log_write($x) { - global $verbose, $log_file; + static $enabled, $log_file; - if (!$verbose) return; - if (!$log_file) { - $hostname = gethostname(); - $log_dir = "../../log_$hostname"; - if (!file_exists($log_dir)) { - mkdir($log_dir); + if (!isset($enabled)) { + $enabled = false; + $filename = parse_config(get_config(), ""); + if (!$filename) { + return; } - $log_file = fopen("$log_dir/submit_log.txt", "a"); + $log_dir = parse_config(get_config(), ""); + if (!$log_dir) { + return; + } + $log_file = fopen("$log_dir/$filename", "a"); if (!$log_file) return; + $enabled = true; } + if (!$enabled) return; fwrite($log_file, sprintf("%s: %s\n", strftime("%c"), $x)); fflush($log_file); } diff --git a/html/user/submit_rpc_handler.php b/html/user/submit_rpc_handler.php index e59445c847..845aa6dbd8 100644 --- a/html/user/submit_rpc_handler.php +++ b/html/user/submit_rpc_handler.php @@ -471,6 +471,7 @@ function submit_batch($r) { log_write("batch update to njobs failed"); xml_error(-1, "batch->update() failed"); } + log_write("adding jobs to existing batch $batch_id"); } else { $batch_name = (string)($r->batch->batch_name); $batch_name = BoincDb::escape_string($batch_name); @@ -511,6 +512,7 @@ function submit_batch($r) { log_write("batch update to IN_PROGRESS failed"); xml_error(-1, "batch->update() failed"); } + log_write("updated batch state to IN_PROGRESS"); echo "$batch_id @@ -1022,13 +1024,13 @@ estimate_batch($r); exit; } -$request_log = parse_config(get_config(), ""); +// optionally write request message (XML) to log file +// +$request_log = parse_config(get_config(), ""); if ($request_log) { - $request_log_dir = parse_config(get_config(), ""); - if ($request_log_dir) { - $request_log = $request_log_dir . "/" . $request_log; - } - if ($file = fopen($request_log, "a+")) { + $log_dir = parse_config(get_config(), ""); + $request_log = $log_dir . "/" . $request_log; + if ($file = fopen($request_log, "a")) { fwrite($file, "\n\n" . $_POST['request'] . "\n\n"); fclose($file); } diff --git a/tools/submit_api_test.py b/tools/submit_api_test.py index 63e5e39099..db1751392f 100644 --- a/tools/submit_api_test.py +++ b/tools/submit_api_test.py @@ -191,5 +191,5 @@ def test_get_output_files(): print(r) #test_query_batch(328) -test_submit_batch('batch_41') +test_submit_batch('batch_43') #test_create_batch('batch_33')