|
| 1 | +--- |
| 2 | +title: Troubleshooting |
| 3 | +custom_edit_url: https://github.com/pact-foundation/pact-php/edit/master/docs/troubleshooting.md |
| 4 | +--- |
| 5 | +<!-- This file has been synced from the pact-foundation/pact-php repository. Please do not edit it directly. The URL of the source file can be found in the custom_edit_url value above --> |
| 6 | + |
| 7 | +## Output Logging |
| 8 | + |
| 9 | +There are several ways to print the logs: |
| 10 | + |
| 11 | +### Logger Singleton Instance |
| 12 | + |
| 13 | +You can run these code (once) before running tests: |
| 14 | + |
| 15 | +```php |
| 16 | +use PhpPact\Log\Logger; |
| 17 | +$logger = Logger::instance(); |
| 18 | +$logger->attach(new File('/path/to/file', LogLevel::DEBUG)); |
| 19 | +$logger->attach(new Buffer(LogLevel::ERROR)); |
| 20 | +$logger->attach(new Stdout(LogLevel::WARN)); |
| 21 | +$logger->attach(new Stderr(LogLevel::INFO)); |
| 22 | +$logger->apply(); |
| 23 | +``` |
| 24 | + |
| 25 | +* Pros |
| 26 | + * Flexible, can be used in any test framework |
| 27 | + * Support plugins (e.g. csv, gRPC) |
| 28 | + * Support multiple sinks |
| 29 | +* Cons |
| 30 | + * Need to modify the code (once, before the tests) |
| 31 | + |
| 32 | +### PHPUnit Extension |
| 33 | + |
| 34 | +You can put these elements to PHPUnit's configuration file: |
| 35 | + |
| 36 | +```xml |
| 37 | +<?xml version="1.0" encoding="UTF-8"?> |
| 38 | +<phpunit bootstrap="vendor/autoload.php" colors="true"> |
| 39 | + ... |
| 40 | + <php> |
| 41 | + <env name="PACT_LOG" value="./log/pact.txt"/> |
| 42 | + <env name="PACT_LOGLEVEL" value="DEBUG"/> |
| 43 | + </php> |
| 44 | + <extensions> |
| 45 | + <bootstrap class="PhpPact\Log\PHPUnit\PactLoggingExtension"/> |
| 46 | + </extensions> |
| 47 | +</phpunit> |
| 48 | +``` |
| 49 | + |
| 50 | +* Pros |
| 51 | + * Support plugins (e.g. csv, gRPC) |
| 52 | + * No need to modify the code |
| 53 | +* Cons |
| 54 | + * Support only single sink (stdout or file, depend on the value of the environment variables) |
| 55 | + * Only for PHPUnit |
| 56 | + |
| 57 | +### Config |
| 58 | + |
| 59 | +Consumer: |
| 60 | + |
| 61 | +```php |
| 62 | +use PhpPact\Standalone\MockService\MockServerConfig; |
| 63 | +$config->setLogLevel('DEBUG'); |
| 64 | +``` |
| 65 | + |
| 66 | +Provider: |
| 67 | + |
| 68 | +```php |
| 69 | +use PhpPact\Standalone\ProviderVerifier\Model\VerifierConfig; |
| 70 | +$config->setLogLevel('DEBUG'); |
| 71 | +``` |
| 72 | + |
| 73 | +* Pros |
| 74 | + * Simple |
| 75 | +* Cons |
| 76 | + * Do not support plugins (e.g. csv, gRPC) |
| 77 | + * Only single sink (stdout) |
0 commit comments