Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kschroeer opened this issue Jun 30, 2022 · 1 comment
Closed

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

kschroeer opened this issue Jun 30, 2022 · 1 comment

Comments

@kschroeer
Copy link

Is there a way to log the output of the Git commands?

I didn't find any function right away that expected a LoggerInterface as a parameter, for example.

I noticed that the outputs from StdOut and StdErr are captured in the RunnerResult object. That would actually be exactly what I need.
But unfortunately only the run() method returns the RunnerResult object, not the commit() and push() methods.
So when I commit, I no longer have a way to access the RunnerResult.
How do I continue here?

@janpecha
Copy link
Contributor

janpecha commented Jul 2, 2022

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 = $git->open('/path/to/repo');

@czproject czproject locked and limited conversation to collaborators Jul 2, 2022
@janpecha janpecha converted this issue into discussion #79 Jul 2, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants