Skip to content

Commit

Permalink
Add logging support for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Jun 9, 2018
1 parent 6da46dd commit 35070bb
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 13 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"league/climate": "^3.2",
"rdlowrey/auryn": "^1.4.2",
"webmozart/assert": "^1.2",
"symfony/yaml": "^3.0"
"symfony/yaml": "^3.0",
"amphp/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^6",
Expand Down
162 changes: 151 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion src/AcmeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@

namespace Kelunik\AcmeClient;

use Amp\ByteStream\ResourceOutputStream;
use Amp\Log\ConsoleFormatter;
use Amp\Log\StreamHandler;
use Kelunik\Acme\AcmeClient;
use Kelunik\Acme\AcmeService;
use Kelunik\Acme\Crypto\PrivateKey;
use Monolog\Logger;
use Monolog\Processor\PsrLogMessageProcessor;

class AcmeFactory {
public function build(string $directory, PrivateKey $keyPair): AcmeService {
return new AcmeService(new AcmeClient($directory, $keyPair));
$logger = null;
if (\getenv('ACME_LOG')) {
$logger = new Logger('acme');
$logger->pushProcessor(new PsrLogMessageProcessor);

$handler = new StreamHandler(new ResourceOutputStream(\STDERR));
$handler->setFormatter(new ConsoleFormatter(null, null, true, true));
$logger->pushHandler($handler);
}

return new AcmeService(new AcmeClient($directory, $keyPair, null, null, $logger));
}
}

0 comments on commit 35070bb

Please sign in to comment.