Below is my schedule task. I want to know is there a way I can log an error in my log.txt file.
Note: I don't want Moodle error logging function.
Want to know what step I will have to follow to do the same.
I just want a simple custom function which will write any error in my log.txt file. also, want to know where can I store this log.txt file as all my custom schedule tasks are in my task folder inside the certificate folder.(mod/certificate/task/scheduletask.php)
public function execute() {
global $DB;
$subject = get_string('email_subject_course_expiry', 'mod_certificate','');
$records = $DB->get_recordset_sql ("SELECT DISTINCT fullname AS usercoursename,usr.firstname AS firstname,usr.email AS useremail,usr.deviceid AS deviceid,
FROM vw_complan_comptemp_comp
vw_user_devicedetails AS usr
");
if(is_null($records) || empty($records))
{ exit;
}
else
{
foreach ($records as $id => $student) {
$data = new \stdClass();
$data->usercoursename = $student->usercoursename;
$data->firstname = $student->firstname;
$data->useremail= $student->useremail;
$data->deviceid= $student->deviceid;
$data->notifydate= $student->notifydate;
if(time() == $data->notifydate)
{
$eol = PHP_EOL;
$header = "From:"."info@learntodrill.com". $eol;
$header .= "MIME-Version: 1.0". $eol;
$header .= "Return-Path:"."info@learntodrill.com". $eol;
$header .= "Content-Type: text/html; charset=\"iso-8859-1\"" . $eol;
$find[] = '[Course Name]';
$replace[] = (string)($data->usercoursename);
$find[] = '[Student First Name]';
$replace[] = (string) ($data->firstname);
$email_body = str_replace($find, $replace, $emailbody);
if (mail((string)($data->useremail), $subject, $email_body, $header, '-f'."info@learntodrill.com"))
{
$find[] = '[Course Name]';
$replace[] = (string)($data->usercoursename);
$msg_payload = str_replace($find, $replace, $msg_notify);
}
else
{
exit;
}
}
}