Skip to content

Commit

Permalink
change string to output on screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonid74 committed Feb 19, 2021
1 parent 7e29724 commit efdffc0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Exception/SimpleLoggerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct( string $message = '', int $code = 0, \Exception $pr
$strEOL = ( PHP_SAPI === 'cli' ? PHP_EOL : '<br>' );
parent::__construct(
'SimpleLogger caught the error!' . $strEOL . $strEOL .
'Error code: ' . ( $code ?? 'unknown' ) . $strEOL .
'Error code: ' . $code . $strEOL .
'Error text: ' . $message . $strEOL . $strEOL .
'Exitting.',
$code,
Expand Down
15 changes: 4 additions & 11 deletions src/SimpleLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ public function toLog( mixed $logData, ?string $strLogTitle = null, ?bool $isPri
$memoryUsage = $this->_memoryUsage();
$this->timeLastSave = $timeStart;

$strData2Log = sprintf( '[ %s ] [ %s ] [ %s ]', $strLogDateTime . $timeElapsed, 'session: ' . $this->strUniqId, 'memory: ' . $memoryUsage ) . $this->strEol . $this->strPreOpen . 'TITLE: ' . $strLogTitle . $this->strEol . $strDataTmp . $this->strPreClose . $this->strEol . $this->strEol;
$strData2Log = sprintf( '[ %s ] [ %s ] [ %s ]', $strLogDateTime . $timeElapsed, 'session: ' . $this->strUniqId, 'memory: ' . $memoryUsage );

if ( $isPrintOnScreen ) {
printf( '%s', $strData2Log );
printf( '%s', $strData2Log . '<br>TITLE: ' . $strLogTitle . '<br><pre>' . $strDataTmp . '</pre><br><br>' );
}

$strData2Log .= PHP_EOL . 'TITLE: ' . $strLogTitle . PHP_EOL . $strDataTmp . PHP_EOL . PHP_EOL;

if ( !isset( $this->strLogFilePath ) ) {
$this->strLogFilePath = $this->_getLogFullFileNameWithPath();
$this->strLogFilePath = dirname( $this->strLogFilePath ) . DIRECTORY_SEPARATOR . $strLogDate . '_' . basename( $this->strLogFilePath );
Expand Down Expand Up @@ -199,15 +201,6 @@ private function __construct( string $strLogFileName )
$this->setDefaultTimezone( $this->strTimezone );
$this->strLogFileName = $strLogFileName;
$this->strUniqId = $this->_uniqIdReal();
$this->strEol = PHP_EOL;
$this->strPreOpen = '';
$this->strPreClose = '';

if ( PHP_SAPI !== 'cli' ) {
$this->strEol = '<br>';
$this->strPreOpen = '<pre>';
$this->strPreClose = '</pre>';
}
}

/**
Expand Down

0 comments on commit efdffc0

Please sign in to comment.