Logging updates

This commit is contained in:
Deon George
2021-08-18 22:11:16 +10:00
parent e8df6f7103
commit 6af466605a
2 changed files with 22 additions and 21 deletions

View File

@@ -24,6 +24,8 @@ use App\Models\Address;
*/
final class Send extends Item
{
private const LOGKEY = 'IS-';
private Collection $list;
private ?Item $sending;
private Collection $packets;
@@ -124,17 +126,17 @@ final class Send extends Item
*/
public function add(string $file): void
{
Log::debug(sprintf('%s: + Start [%s]',__METHOD__,$file));
Log::debug(sprintf('%s:+ add [%s]',self::LOGKEY,$file));
try {
$this->list->push(new Item($file,self::I_SEND));
} catch (FileNotFoundException) {
Log::error(sprintf('%s: ! Item [%s] doesnt exist',__METHOD__,$file));
Log::error(sprintf('%s:! Item [%s] doesnt exist',self::LOGKEY,$file));
return;
} catch (UnreadableFileException) {
Log::error(sprintf('%s: ! Item [%s] cannot be read',__METHOD__,$file));
Log::error(sprintf('%s:! Item [%s] cannot be read',self::LOGKEY,$file));
return;
// Uncaught, rethrow the error
@@ -157,7 +159,7 @@ final class Send extends Item
if ($successful) {
$this->sending->sent = TRUE;
$end = time()-$this->start;
Log::debug(sprintf('%s: - Closing [%s], sent in [%d]',__METHOD__,$this->sending->file_name,$end));
Log::debug(sprintf('%s: - Closing [%s], sent in [%d]',self::LOGKEY,$this->sending->file_name,$end));
}
if (! $this->sending instanceof Mail)
@@ -186,7 +188,7 @@ final class Send extends Item
*/
public function open(): bool
{
Log::debug(sprintf('%s: + Start',__METHOD__));
Log::debug(sprintf('%s:+ open',self::LOGKEY));
// If we have mail, we'll send that first
if ($this->sending = $this->packets
@@ -212,11 +214,11 @@ final class Send extends Item
$this->f = fopen($this->sending->file_name,'rb');
if (! $this->f) {
Log::error(sprintf('%s: ! Unable to open file [%s] for reading',__METHOD__,$this->sending->file_name));
Log::error(sprintf('%s:! Unable to open file [%s] for reading',self::LOGKEY,$this->sending->file_name));
return FALSE;
}
Log::info(sprintf('%s: = End - File [%s] opened with size [%d]',__METHOD__,$this->sending->file_name,$this->sending->file_size));
Log::info(sprintf('%s:= open - File [%s] opened with size [%d]',self::LOGKEY,$this->sending->file_name,$this->sending->file_size));
return TRUE;
}
@@ -230,7 +232,7 @@ final class Send extends Item
{
// Netmail
if ($x=$ao->getNetmail()) {
Log::debug(sprintf('%s: - Netmail(s) added for sending to [%s]',__METHOD__,$ao->ftn));
Log::debug(sprintf('%s: - Netmail(s) added for sending to [%s]',self::LOGKEY,$ao->ftn));
$this->packets->push(new Mail($x,self::I_SEND));
}
@@ -257,7 +259,7 @@ final class Send extends Item
}
$this->file_pos += strlen($data);
Log::debug(sprintf('%s: - Read [%d] bytes, file pos now [%d]',__METHOD__,strlen($data),$this->file_pos));
Log::debug(sprintf('%s: - Read [%d] bytes, file pos now [%d]',self::LOGKEY,strlen($data),$this->file_pos));
if ($data === FALSE)
throw new UnreadableFileException('Error reading file: '.$this->sending->file_name);
@@ -288,7 +290,7 @@ final class Send extends Item
if ($rc)
$this->file_pos = $pos;
Log::debug(sprintf('%s: - Seeked to [%d]',__METHOD__,$this->file_pos));
Log::debug(sprintf('%s:= Seeked to [%d]',self::LOGKEY,$this->file_pos));
return $rc;
}