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;
}

View File

@ -484,8 +484,8 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
if (($rc=$this->ls_zinitsender(self::LSZ_WINDOW,'')) < 0)
return $rc;
Log::debug(sprintf('%s: ZMODEM Link Options %d/%d, %s%s%s%s',
__METHOD__,
Log::debug(sprintf('%s: - ZMODEM Link Options %d/%d, %s%s%s%s',
self::LOGKEY,
$this->ls_MaxBlockSize,
$this->ls_txWinSize,
($this->ls_Protocol&self::LSZ_OPTCRC32) ? 'CRC32' : 'CRC16',
@ -1136,7 +1136,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$incrc = crc16($data.chr($frametype));
if ($this->DEBUG)
Log::debug(sprintf('%s: - ls_zrecvdata16 CRC%d got %08x - calculated %08x',self::LOGKEY,16,$incrc,$crc),['m'=>__METHOD__]);
Log::debug(sprintf('%s: - ls_zrecvdata16 CRC%d got %08x - calculated %08x',self::LOGKEY,16,$incrc,$crc));
if ($incrc != $crc)
return self::LSZ_BADCRC;
@ -2383,7 +2383,7 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
*/
private function ls_zsendfinfo(Send $send,int $sernum,int $pos,int $fileleft,int $bytesleft): int
{
Log::debug(sprintf('%s: + Start [%s]',__METHOD__,$send->name));
Log::debug(sprintf('%s:+ ls_zsendfinfo [%s]',self::LOGKEY,$send->name));
$trys = 0;
$retransmit = 1;
@ -2466,7 +2466,6 @@ final class Zmodem extends Protocol implements CRCInterface,ZmodemInterface
$crc = $this->CRC32_UPDATE($c,$crc);
$crc = $this->CRC32_FINISH($crc);
dump([__METHOD__,'crc'=>$crc,'crc32'=>crc32(file_get_contents($send->name))]);
if (($rc=$this->ls_zsendhhdr(self::ZCRC,$this->ls_storelong($crc))) < 0)
return $rc;
@ -2488,7 +2487,7 @@ dump([__METHOD__,'crc'=>$crc,'crc32'=>crc32(file_get_contents($send->name))]);
break;
default:
Log::error(sprintf('%s: ? Something strange [%d]',__METHOD__,$rc));
Log::error(sprintf('%s: ? Something strange [%d]',self::LOGKEY,$rc));
if ($rc < 0)
return $rc;
@ -2496,7 +2495,7 @@ dump([__METHOD__,'crc'=>$crc,'crc32'=>crc32(file_get_contents($send->name))]);
} while ($trys < 10);
Log::error(sprintf('%s: ? Something strange or timeout [%d]',__METHOD__,$rc));
Log::error(sprintf('%s:? Something strange or timeout [%d]',self::LOGKEY,$rc));
return $rc;
}
@ -2504,7 +2503,7 @@ dump([__METHOD__,'crc'=>$crc,'crc32'=>crc32(file_get_contents($send->name))]);
private function ls_zsendhhdr(int $frametype,array $hdr): int
{
if ($this->DEBUG)
Log::debug(sprintf('%s: + Start',__METHOD__));
Log::debug(sprintf('%s:+ ls_zsendhhdr',self::LOGKEY));
/* Send **<DLE> */
$this->client->buffer_add(chr(self::ZPAD).chr(self::ZPAD).chr(self::ZDLE));
@ -2547,7 +2546,7 @@ dump([__METHOD__,'crc'=>$crc,'crc32'=>crc32(file_get_contents($send->name))]);
*/
private function ls_zsendsinit(string $attstr): int
{
Log::debug(sprintf('%s: + Start [%s]',__METHOD__,$attrstr));
Log::debug(sprintf('%s:+ ls_zsendsinit [%s]',self::LOGKEY,$attrstr));
$trys = 0;
$retransmit = 1;
@ -2610,7 +2609,7 @@ dump([__METHOD__,'crc'=>$crc,'crc32'=>crc32(file_get_contents($send->name))]);
break;
default:
Log::error(sprintf('%s: ? Something strange [%d]',__METHOD__,$rc));
Log::error(sprintf('%s: ? Something strange [%d]',self::LOGKEY,$rc));
if ($rc < 0)
return $rc;
@ -2618,7 +2617,7 @@ dump([__METHOD__,'crc'=>$crc,'crc32'=>crc32(file_get_contents($send->name))]);
} while ($trys < 10);
Log::error(sprintf('%s: ? Something strange or timeout [%d]',__METHOD__,$rc));
Log::error(sprintf('%s:? Something strange or timeout [%d]',self::LOGKEY,$rc));
return $rc;
}
}