src/BaseException.php
public static function generateExceptionLog(
		\Throwable $Throwable, $timestamp = null){

		if(empty($timestamp)){

			$timestamp = time();
		}

		if($Throwable instanceof BaseException ||
			$Throwable instanceof PHPErrorException){

			/** @noinspection PhpUndefinedMethodInspection */

			$trace = $Throwable->getStackTrace();
		}
		else{

			$trace = array_reverse($Throwable->getTrace());
		}

		/**
		 * Convenience method for Windows-1252 to UTF-8 iconv().
		 *
		 * @param $string
		 *
		 * @return string
		 */

		$iconv = function($string){

			if(mb_detect_encoding($string,'Windows-1252, UTF-8, ISO-8859-1') === 'UTF-8'){
				
				return $string;
			}
			
			return @iconv('Windows-1252', 'UTF-8//TRANSLIT', $string);
		};

		/**
		 * Convenience method for UTF-8 htmlspecialchars().
		 *
		 * @param $string
		 *
		 * @return string
		 */

		$html_encode = function($string){

			return htmlspecialchars($string, ENT_NOQUOTES, 'UTF-8');
		};

		$muted = false;

		if($Throwable instanceof Silenced){

			$muted = true;
		}

		ob_start();

		// Construct XML

		echo '<?xml version="1.0" encoding="UTF-8"?>';

		?>
		<exception>

		<thrown timestamp="<?= $timestamp; ?>"><?= date(
				'd-m-Y H:i:s',
				$timestamp
			); ?></thrown>

		<class><?= get_class($Throwable); ?></class>
		<origin line="<?= $Throwable->getLine(); ?>"><?= $html_encode(
				$Throwable->getFile()
			); ?></origin>
		<message><?= $html_encode($Throwable->getMessage()); ?></message>

		<trace muted="<?= ($muted ? 'true' : 'false') ?>">

			<?php
			foreach($trace as $trace_item){

				if(strpos($trace_item['function'], '{closure}') !== false){

					$trace_item['function'] = '{closure}';
				}
				?>

				<call>
					<function><?= $html_encode(
							(isset($trace_item['class']) ?
								$trace_item['class'] : '') .
							(isset($trace_item['type']) ? $trace_item['type'] :
								'') .
							(isset($trace_item['function']) ?
								$trace_item['function'] : '')
						) ?></function>
					<file line="<?= (isset($trace_item['line']) ?
						$trace_item['line'] : ''); ?>">
						<?= (isset($trace_item['file']) ?
							$html_encode($trace_item['file']) : ''); ?>
					</file>
					<arguments>

						<? foreach((array) $trace_item['args'] as $argument){

							$silent = false;

							if($muted){

								$silent = true;
							}
							elseif($argument instanceof Silenced){

								$silent = true;
							}
							?>

							<argument type="<?= gettype($argument); ?>"
							          silent="<?= ($silent ? 'true' :
								          'false') ?>">

								<?php

								if($silent){

									if(is_object($argument)){

										echo $iconv(get_class($argument));
									}
									elseif(is_array($argument)){

										echo $iconv(
											'array[' .
											count($argument) . ']'
										);
									}
									elseif(is_string($argument)){

										echo $iconv(
											'string[' .
											strlen($argument) . ']'
										);
									}
									elseif(is_bool($argument)){

										echo $iconv(
											$argument ?
												'true' : 'false'
										);
									}
									elseif(is_null($argument)){

										echo $iconv('null');
									}
								}
								else{

									echo '<![CDATA[' . $iconv(
											print_r(
												$argument,
												true
											)
										) . ']]>';
								}
								?>

							</argument>

						<?php } ?>

					</arguments>
				</call>

			<?php } ?>

		</trace>

		<get>

			<?php foreach((array) $_GET as $name => $value){ ?>

				<value name="<?= $html_encode($name); ?>">
					<?= '<![CDATA[' . $iconv(print_r($value, true)) . ']]>'; ?>
				</value>

			<?php } ?>

		</get>

		<post>

			<?php foreach((array) $_POST as $name => $value){ ?>

				<value name="<?= $html_encode($name); ?>">
					<?= '<![CDATA[' . $iconv(print_r($value, true)) . ']]>'; ?>
				</value>

			<?php } ?>

		</post>

		<?php if($Throwable instanceof ExternalException){ ?>

			<error>
				<?= $html_encode($Throwable->getExternalData()); ?>
			</error>

		<?php } ?>

		<server>

			<?php foreach((array) $_SERVER as $name => $value){ ?>

				<value name="<?= $html_encode($name); ?>">
					<?= '<![CDATA[' . $iconv(print_r($value, true)) . ']]>'; ?>
				</value>

			<?php } ?>

		</server>

		</exception><?php

		return ob_get_clean();
	}
public static function generateExceptionLog(
		\Throwable $Throwable, $timestamp = null){

		if(empty($timestamp)){

			$timestamp = time();
		}

		if($Throwable instanceof BaseException ||
			$Throwable instanceof PHPErrorException){

			/** @noinspection PhpUndefinedMethodInspection */

			$trace = $Throwable->getStackTrace();
		}
		else{

			$trace = array_reverse($Throwable->getTrace());
		}

		/**
		 * Convenience method for Windows-1252 to UTF-8 iconv().
		 *
		 * @param $string
		 *
		 * @return string
		 */

		$iconv = function($string){

			if(mb_detect_encoding($string,'Windows-1252, UTF-8, ISO-8859-1') === 'UTF-8'){
				
				return $string;
			}
			
			return @iconv('Windows-1252', 'UTF-8//TRANSLIT', $string);
		};

		/**
		 * Convenience method for UTF-8 htmlspecialchars().
		 *
		 * @param $string
		 *
		 * @return string
		 */

		$html_encode = function($string){

			return htmlspecialchars($string, ENT_NOQUOTES, 'UTF-8');
		};

		$muted = false;

		if($Throwable instanceof Silenced){

			$muted = true;
		}

		ob_start();

		// Construct XML

		echo '<?xml version="1.0" encoding="UTF-8"?>';

		?>
		<exception>

		<thrown timestamp="<?= $timestamp; ?>"><?= date(
				'd-m-Y H:i:s',
				$timestamp
			); ?></thrown>

		<class><?= get_class($Throwable); ?></class>
		<origin line="<?= $Throwable->getLine(); ?>"><?= $html_encode(
				$Throwable->getFile()
			); ?></origin>
		<message><?= $html_encode($Throwable->getMessage()); ?></message>

		<trace muted="<?= ($muted ? 'true' : 'false') ?>">

			<?php
			foreach($trace as $trace_item){

				if(strpos($trace_item['function'], '{closure}') !== false){

					$trace_item['function'] = '{closure}';
				}
				?>

				<call>
					<function><?= $html_encode(
							(isset($trace_item['class']) ?
								$trace_item['class'] : '') .
							(isset($trace_item['type']) ? $trace_item['type'] :
								'') .
							(isset($trace_item['function']) ?
								$trace_item['function'] : '')
						) ?></function>
					<file line="<?= (isset($trace_item['line']) ?
						$trace_item['line'] : ''); ?>">
						<?= (isset($trace_item['file']) ?
							$html_encode($trace_item['file']) : ''); ?>
					</file>
					<arguments>

						<? foreach((array) $trace_item['args'] as $argument){

							$silent = false;

							if($muted){

								$silent = true;
							}
							elseif($argument instanceof Silenced){

								$silent = true;
							}
							?>

							<argument type="<?= gettype($argument); ?>"
							          silent="<?= ($silent ? 'true' :
								          'false') ?>">

								<?php

								if($silent){

									if(is_object($argument)){

										echo $iconv(get_class($argument));
									}
									elseif(is_array($argument)){

										echo $iconv(
											'array[' .
											count($argument) . ']'
										);
									}
									elseif(is_string($argument)){

										echo $iconv(
											'string[' .
											strlen($argument) . ']'
										);
									}
									elseif(is_bool($argument)){

										echo $iconv(
											$argument ?
												'true' : 'false'
										);
									}
									elseif(is_null($argument)){

										echo $iconv('null');
									}
								}
								else{

									echo '<![CDATA[' . $iconv(
											print_r(
												$argument,
												true
											)
										) . ']]>';
								}
								?>

							</argument>

						<?php } ?>

					</arguments>
				</call>

			<?php } ?>

		</trace>

		<get>

			<?php foreach((array) $_GET as $name => $value){ ?>

				<value name="<?= $html_encode($name); ?>">
					<?= '<![CDATA[' . $iconv(print_r($value, true)) . ']]>'; ?>
				</value>

			<?php } ?>

		</get>

		<post>

			<?php foreach((array) $_POST as $name => $value){ ?>

				<value name="<?= $html_encode($name); ?>">
					<?= '<![CDATA[' . $iconv(print_r($value, true)) . ']]>'; ?>
				</value>

			<?php } ?>

		</post>

		<?php if($Throwable instanceof ExternalException){ ?>

			<error>
				<?= $html_encode($Throwable->getExternalData()); ?>
			</error>

		<?php } ?>

		<server>

			<?php foreach((array) $_SERVER as $name => $value){ ?>

				<value name="<?= $html_encode($name); ?>">
					<?= '<![CDATA[' . $iconv(print_r($value, true)) . ']]>'; ?>
				</value>

			<?php } ?>

		</server>

		</exception><?php

		return ob_get_clean();
	}
public static function generateExceptionLog ( \ Throwable $ Throwable , $ timestamp = null ) { if ( empty ( $ timestamp ) ) { $ timestamp = time ( ) ; } if ( $ Throwable instanceof BaseException || $ Throwable instanceof PHPErrorException ) { /** @noinspection PhpUndefinedMethodInspection */ $ trace = $ Throwable -> getStackTrace ( ) ; } else { $ trace = array_reverse ( $ Throwable -> getTrace ( ) ) ; } /**
		 * Convenience method for Windows-1252 to UTF-8 iconv().
		 *
		 * @param $string
		 *
		 * @return string
		 */ $ iconv = function ( $ string ) { if ( mb_detect_encoding ( $ string , 'Windows-1252, UTF-8, ISO-8859-1' ) === 'UTF-8' ) { return $ string ; } return @ iconv ( 'Windows-1252' , 'UTF-8//TRANSLIT' , $ string ) ; } ; /**
		 * Convenience method for UTF-8 htmlspecialchars().
		 *
		 * @param $string
		 *
		 * @return string
		 */ $ html_encode = function ( $ string ) { return htmlspecialchars ( $ string , ENT_NOQUOTES , 'UTF-8' ) ; } ; $ muted = false ; if ( $ Throwable instanceof Silenced ) { $ muted = true ; } ob_start ( ) ; // Construct XML echo '<?xml version="1.0" encoding="UTF-8"?>' ; ?>
		<exception>

		<thrown timestamp="<?= $ timestamp ; ?>"><?= date ( 'd-m-Y H:i:s' , $ timestamp ) ; ?></thrown>

		<class><?= get_class ( $ Throwable ) ; ?></class>
		<origin line="<?= $ Throwable -> getLine ( ) ; ?>"><?= $ html_encode ( $ Throwable -> getFile ( ) ) ; ?></origin>
		<message><?= $ html_encode ( $ Throwable -> getMessage ( ) ) ; ?></message>

		<trace muted="<?= ( $ muted ? 'true' : 'false' ) ?>">

			<?php foreach ( $ trace as $ trace_item ) { if ( strpos ( $ trace_item [ 'function' ] , '{closure}' ) !== false ) { $ trace_item [ 'function' ] = '{closure}' ; } ?>

				<call>
					<function><?= $ html_encode ( ( isset ( $ trace_item [ 'class' ] ) ? $ trace_item [ 'class' ] : '' ) . ( isset ( $ trace_item [ 'type' ] ) ? $ trace_item [ 'type' ] : '' ) . ( isset ( $ trace_item [ 'function' ] ) ? $ trace_item [ 'function' ] : '' ) ) ?></function>
					<file line="<?= ( isset ( $ trace_item [ 'line' ] ) ? $ trace_item [ 'line' ] : '' ) ; ?>">
						<?= ( isset ( $ trace_item [ 'file' ] ) ? $ html_encode ( $ trace_item [ 'file' ] ) : '' ) ; ?> < / file > < arguments > < ? foreach ( ( array ) $ trace_item [ 'args' ] as $ argument ) { $ silent = false ; if ( $ muted ) { $ silent = true ; } elseif ( $ argument instanceof Silenced ) { $ silent = true ; } ?>

							<argument type="<?= gettype ( $ argument ) ; ?>"
							          silent="<?= ( $ silent ? 'true' : 'false' ) ?>">

								<?php if ( $ silent ) { if ( is_object ( $ argument ) ) { echo $ iconv ( get_class ( $ argument ) ) ; } elseif ( is_array ( $ argument ) ) { echo $ iconv ( 'array[' . count ( $ argument ) . ']' ) ; } elseif ( is_string ( $ argument ) ) { echo $ iconv ( 'string[' . strlen ( $ argument ) . ']' ) ; } elseif ( is_bool ( $ argument ) ) { echo $ iconv ( $ argument ? 'true' : 'false' ) ; } elseif ( is_null ( $ argument ) ) { echo $ iconv ( 'null' ) ; } } else { echo '<![CDATA[' . $ iconv ( print_r ( $ argument , true ) ) . ']]>' ; } ?>

							</argument>

						<?php } ?>

					</arguments>
				</call>

			<?php } ?>

		</trace>

		<get>

			<?php foreach ( ( array ) $ _GET as $ name => $ value ) { ?>

				<value name="<?= $ html_encode ( $ name ) ; ?>">
					<?= '<![CDATA[' . $ iconv ( print_r ( $ value , true ) ) . ']]>' ; ?>
				</value>

			<?php } ?>

		</get>

		<post>

			<?php foreach ( ( array ) $ _POST as $ name => $ value ) { ?>

				<value name="<?= $ html_encode ( $ name ) ; ?>">
					<?= '<![CDATA[' . $ iconv ( print_r ( $ value , true ) ) . ']]>' ; ?>
				</value>

			<?php } ?>

		</post>

		<?php if ( $ Throwable instanceof ExternalException ) { ?>

			<error>
				<?= $ html_encode ( $ Throwable -> getExternalData ( ) ) ; ?>
			</error>

		<?php } ?>

		<server>

			<?php foreach ( ( array ) $ _SERVER as $ name => $ value ) { ?>

				<value name="<?= $ html_encode ( $ name ) ; ?>">
					<?= '<![CDATA[' . $ iconv ( print_r ( $ value , true ) ) . ']]>' ; ?>
				</value>

			<?php } ?>

		</server>

		</exception><?php return ob_get_clean ( ) ; }
Generate an XML-based exception-log.

<p>Similar to the output of {@link BaseException::displayException()}
but better suited for automated processing. The XML generated by this
method can stored and used for ex-post analysis of the Exception.</p>

<p>The optional {@link $timestamp} parameter contains the timestamp to
be listed in the log. If omitted, the current time is used. This
parameter is useful to "sync up" the logged timestamp with the one used
in the actual creation of the exception-log based upon this XML output.
</p>

@param \Throwable $Throwable
@param integer $timestamp

@return string
Generate an XML - based exception - log .