Last active
December 5, 2017 19:59
-
-
Save a-ast/87c742641391188221d366b58195077d to your computer and use it in GitHub Desktop.
Spryker DataImport: Add logging to console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
protected function createStreamHandler(): HandlerInterface | |
{ | |
$handler = new StreamHandler('php://stdout', Logger::INFO); | |
$formatter = new LineFormatter("\033[1;30m%datetime%\e[0m %message%" . PHP_EOL, 'H:i:s'); | |
$handler->setFormatter($formatter); | |
return $handler; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Pyz\Zed\DataImport\Business\Logger; | |
use Monolog\Handler\HandlerInterface; | |
use Monolog\Handler\StreamHandler; | |
use Monolog\Logger; | |
use Spryker\Shared\Log\Config\LoggerConfigInterface; | |
class LoggerConfig implements LoggerConfigInterface | |
{ | |
public function getChannelName(): string | |
{ | |
return 'DataImport'; | |
} | |
/** | |
* @return \Monolog\Handler\HandlerInterface[] | |
*/ | |
public function getHandlers(): array | |
{ | |
return [$this->createStreamHandler()]; | |
} | |
/** | |
* @return \callable[] | |
*/ | |
public function getProcessors(): array | |
{ | |
return []; | |
} | |
protected function createStreamHandler(): HandlerInterface | |
{ | |
return new StreamHandler('php://stdout', Logger::INFO); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Spryker\Shared\Log; | |
class YourWriterStep implements DataImportStepInterface | |
{ | |
use LoggerTrait; | |
public function doSomething() | |
{ | |
$this->getLogger(new LoggerConfig())->info('Log something'); | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment