Skip to content

Commit

Permalink
Bug SAFeSEA#32, fix 'Start'/ End logging for EssayAnalyser [iet:10299…
Browse files Browse the repository at this point in the history
…633]

* Plus, use 4-digit years in log filenames
  • Loading branch information
nfreear committed Feb 6, 2018
1 parent 5f3fde7 commit f6d53d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions app/utils/EssayAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function analyseAndSave( $taskId, $user )
$versionId = $post[ 'version' ];
$counts = $post[ 'counts' ];
$username = $user->username;
$logData = json_encode([ 'task' => $taskId, 'ver' => $versionId, 'draft' => $draftId ]);

$post_data = [
'text' => $post["text"],
Expand All @@ -54,7 +55,7 @@ public function analyseAndSave( $taskId, $user )
'rd_save_path'=> $this->getSavePath(),
];

$log->debug(__METHOD__ . ":start - $taskId,$versionId - " . date('c'));
$log->info(sprintf( '%s | [%s @ %s] | %s | %s | %s', 'ANALYSER.Start', $username, $req->getIp(), $req->getPath(), $logData, json_encode($counts) ));

$times = (object) [ 'start' => time() ];

Expand All @@ -70,7 +71,8 @@ public function analyseAndSave( $taskId, $user )

$times->duration = $times->end - $times->start;

$log->debug(__METHOD__ . ":end - $taskId,$versionId - seconds:" . $times->duration);
$log->info(sprintf( '%s | [%s @ %s] | %s | %s', 'ANALYSER.End.OK', $username, $req->getIp(), $req->getPath(), json_encode([ 'duration' => $times->duration ]) ));
// Was: $log->debug(__METHOD__ . ":end - $taskId,$versionId - seconds:" . $times->duration);

$post_data[ 'text' ] = substr( $post_data[ 'text' ], 0, 30 ) . ' [...]';
self::_debug([ __METHOD__, 'POST', $post_data ]);
Expand All @@ -93,7 +95,7 @@ public function analyseAndSave( $taskId, $user )
$draftId = $result->db_result->draft_id;
self::_debug([ 'm' => __METHOD__, 'ok', 'u' => $url, 'taskId' => $taskId, 'draftVersion' => $versionId, 'result' => $result, 'duration_sec' => $times->duration, 'counts' => $counts ]);

$log->info(sprintf( '%s | [%s @ %s] | %s | %s', 'ANALYSER.Saved', $username, 'ip', $req->getPath(), json_encode([ 'task' => $taskId, 'ver' => $versionId, 'draft' => $draftId ]) ));
$log->info(sprintf( '%s | [%s @ %s] | %s | %s', 'ANALYSER.Saved', $username, $req->getIp(), $req->getPath(), $logData ));

$result->status = 200;
$result->redirect = true;
Expand All @@ -110,7 +112,7 @@ public function analyseAndSave( $taskId, $user )
self::_debug([ __METHOD__, 'error', 500.1, $ret ]);

// $log->info(sprintf('%s | [%s @ %s] | %s | %s', 'ACTION.SAMS_CREATE', $usr->username, $usr->ip_address, $req->getPath(), json_encode([ 'user_agent' => $req->getUserAgent() ]) ));
$log->error(sprintf( '%s | [%s @ %s] | %s | %s', 'ANALYSER.Analyser', $username, 'ip', $req->getPath(), json_encode( $ret ) ));
$log->error(sprintf( '%s | [%s @ %s] | %s | %s', 'ANALYSER.Analyser', $username, $req->getIp(), $req->getPath(), json_encode( $ret ) ));
}

return $result;
Expand All @@ -122,14 +124,15 @@ public function analyseAndSave( $taskId, $user )
* @param int $userId
* @param array $post Post-data from the end-user.
* @param object $times
* @param string $analysisJson
* @param string $analysisJsonStr
* @return object StdClass, with bool 'result' and integer 'draft_id' members.
*/
protected function saveDraft( $taskId, $userId, $post, $times, $analysisJson )
protected function saveDraft( $taskId, $userId, $post, $times, $analysisJsonStr )
{
/* @var $draft Draft */
$draft = \Model::factory('Draft')->create();
$draft->type = 0;
$draft->analysis = $analysisJson; // Was: $json;
$draft->analysis = $analysisJsonStr; // Was: $json;
$draft->task_id = $taskId;
$draft->version = $post["version"];
$draft->name = $post["name"];
Expand Down
2 changes: 1 addition & 1 deletion public_html/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
'log.writer' => new DateTimeFileWriter(array(
'path' => __DIR__ . '/../.logs',
// Was: 'path' => '../.logs',
'name_format' => 'y-m-d',
'name_format' => 'Y-m-d', // 4-digit year! Was: 'y-m-d',
'message_format' => '%label% | %date% | %message%'
))
));
Expand Down

0 comments on commit f6d53d4

Please sign in to comment.