Skip to content

How to log the output of the Git commands? #79

Answered by janpecha
kschroeer asked this question in Q&A
Discussion options

You must be logged in to vote

Hello. You can create own implementation of IRunner, something like:

class LoggingRunner implements \CzProject\GitPhp\IRunner
{
	private $logger;
	private $runner;


	public function __construct(
		LoggerInterface $logger,
		\CzProject\GitPhp\IRunner $runner
	)
	{
		$this->logger = $logger;
		$this->runner = $runner;
	}


	public function run($cwd, array $args, array $env = NULL)
	{
		$result = $this->runner->run($cwd, $args, $env);

		// log result
		$this->logger->log($result);

		return $result;
	}


	public function getCwd()
	{
		return $this->runner->getCwd();
	}
}


$git = new \CzProject\GitPhp\Git(
	new LoggingRunner(
		$logger,
		new \CzProject\GitPhp\Runners\CliRunner
	)
);
$repo = 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by janpecha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #78 on July 02, 2022 13:50.