You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace jrosset\CliProgram\Monolog;
|
|
|
|
use jrosset\ExtendedMonolog\ExceptionLogger;
|
|
use jrosset\ExtendedMonolog\LogDirectoryHandler;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
/**
|
|
* Implementation for an application with a {@see ConsoleOutputWithMonolog} and a {@see LogDirectoryHandler Monolog log directory} for each command
|
|
*/
|
|
trait TMonologApplication {
|
|
/**
|
|
* @var string The main log directory for Monolog: on subdirectory by command
|
|
*/
|
|
private string $logMainDirectory;
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
protected function getOutputInterfaceForCommand (Command $command, InputInterface $input, OutputInterface $output): OutputInterface {
|
|
return new ConsoleOutputWithMonolog(
|
|
$output,
|
|
new ExceptionLogger(
|
|
$command->getName(),
|
|
[
|
|
new LogDirectoryHandler(
|
|
$this->getLogMainDirectory() . DIRECTORY_SEPARATOR
|
|
. str_replace(':', DIRECTORY_SEPARATOR, $command->getName())
|
|
),
|
|
]
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* The main log directory for Monolog: on subdirectory by command
|
|
*
|
|
* @return string The main log directory for Monolog: on subdirectory by command
|
|
*/
|
|
public function getLogMainDirectory (): string {
|
|
return $this->logMainDirectory;
|
|
}
|
|
/**
|
|
* Set the main log directory for Monolog: on subdirectory by command
|
|
*
|
|
* @param string $logMainDirectory The main log directory for Monolog: on subdirectory by command
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function setLogMainDirectory (string $logMainDirectory): self {
|
|
$this->logMainDirectory = $logMainDirectory;
|
|
return $this;
|
|
}
|
|
} |