stackify / stackify-log-monolog

Apache License 2.0
3 stars 6 forks source link

Bug: handler eats non-DEBUG messages? #12

Closed pnoeric closed 5 years ago

pnoeric commented 5 years ago

Interesting (and unfortunately, what appears to be a pretty serious) bug I found... when I have 2 handlers, one to log to a local file and one to send to Stackify, the Stackify handler "eats" any messages that aren't DEBUG level. So for INFO, WARNING, ERROR and other messages, I see them in Stackify, but not in my local log.

I wrote some code to reproduce the problem, try this:

<?php

require( __DIR__ . '/../vendor/autoload.php' );
$log_path = __DIR__ . '/../test-monolog-stackify.log';

use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Stackify\Log\Monolog\Handler as StackifyHandler;
use Stackify\Log\Transport\ExecTransport;

// prepare Stackify handler
$stackify_transport = new ExecTransport( '--my api key--' );
$handler_stackify   = new StackifyHandler( 'Main site', 'Test', $stackify_transport );

// now create the main logger and tell it where to send the messages
$log = new Logger( 'test' );

echo "<p>Adding stream handler...</p>";
$log->pushHandler( new StreamHandler( $log_path ) );

// add Stackify handler?
if ( 1 ) {
    echo "<p>Adding Stackify handler...</p>";
    $log->pushHandler( $handler_stackify );
}

$log->debug( '#Test debug message' );
$log->warn( '#Test warn message' );
$log->error( '#Test error message' );

$log->debug( '#Test debug message 2' );
$log->warn( '#Test warn message 2' );
$log->error( '#Test error message 2' );

echo "<p>Logged 6 test messages, please check the log file and/or Stackify!</p>";

When I run this with the Stackify handler DISABLED (change the if statement to 0), I see all 6 messages in the local log file.

But when I turn on Stackify, I see the 6 messages in the Stackify log viewer (good), but ONLY the 2 "DEBUG" messages in my local log file.

What's going on?!

Here's my Composer.json and my installed packages FYI, I think everything is up to date

{
  "name": "myproject/myproject",
  "type": "project",
  "require": {
    "theiconic/php-ga-measurement-protocol": "^2.7",
    "monolog/monolog": "1.24.0",
    "stackify/monolog": "~1.0",
    "filp/whoops": "^2.4",
    "php": "^7.1"
  },
  "require-dev": {
    "phpunit/phpunit": "^7",
    "monolog/monolog": "1.24.0",
    "codeception/codeception-progress-reporter": "1.0.9",
    "codeception/codeception": "2.5.6"
  }
}
behat/gherkin                             v4.6.0  Gherkin DSL parser for PHP 5.3
codeception/codeception                   2.5.6   BDD-style testing framework
codeception/codeception-progress-reporter 1.0.9
codeception/phpunit-wrapper               7.7.1   PHPUnit classes used by Codeception
codeception/stub                          2.1.0   Flexible Stub wrapper for PHPUnit's Mock Builder
doctrine/instantiator                     1.2.0   A small, lightweight utility to instantiate objects in PHP without invoking their constructors
facebook/webdriver                        1.7.1   A PHP client for Selenium WebDriver
filp/whoops                               2.4.1   php error handling for cool kids
guzzlehttp/guzzle                         6.3.3   Guzzle is a PHP HTTP client library
guzzlehttp/promises                       v1.3.1  Guzzle promises library
guzzlehttp/psr7                           1.6.1   PSR-7 message implementation that also provides common utility methods
monolog/monolog                           1.24.0  Sends your logs to files, sockets, inboxes, databases and various web services
myclabs/deep-copy                         1.9.1   Create deep copies (clones) of your objects
phar-io/manifest                          1.0.3   Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                           2.0.1   Library for handling version information and constraints
phpdocumentor/reflection-common           1.0.1   Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock         4.3.1   With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver               0.4.0
phpspec/prophecy                          1.8.1   Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage                 6.1.4   Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator                 2.0.2   FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template                 1.2.1   Simple template engine.
phpunit/php-timer                         2.1.2   Utility class for timing
phpunit/php-token-stream                  3.0.2   Wrapper around PHP's tokenizer extension.
phpunit/phpunit                           7.5.14  The PHP Unit Testing framework.
psr/container                             1.0.0   Common Container Interface (PHP FIG PSR-11)
psr/http-message                          1.0.1   Common interface for HTTP messages
psr/log                                   1.1.0   Common interface for logging libraries
ralouphie/getallheaders                   3.0.3   A polyfill for getallheaders.
sebastian/code-unit-reverse-lookup        1.0.1   Looks up which function or method a line of code belongs to
sebastian/comparator                      3.0.2   Provides the functionality to compare PHP values for equality
sebastian/diff                            3.0.2   Diff implementation
sebastian/environment                     4.2.2   Provides functionality to handle HHVM/PHP environments
sebastian/exporter                        3.1.0   Provides the functionality to export PHP variables for visualization
sebastian/global-state                    2.0.0   Snapshotting of global state
sebastian/object-enumerator               3.0.3   Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector                1.1.1   Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context               3.0.0   Provides functionality to recursively process PHP variables
sebastian/resource-operations             2.0.1   Provides a list of PHP built-in functions that operate on resources
sebastian/version                         2.0.1   Library that helps with managing the version number of Git-hosted PHP projects
stackify/logger                           1.1.0   Stackify logs and errors for PHP
stackify/monolog                          1.1.0   Stackify logs and errors for Monolog
symfony/browser-kit                       v4.3.2  Symfony BrowserKit Component
symfony/console                           v4.3.2  Symfony Console Component
symfony/css-selector                      v4.3.2  Symfony CssSelector Component
symfony/dom-crawler                       v4.3.2  Symfony DomCrawler Component
symfony/event-dispatcher                  v4.3.2  Symfony EventDispatcher Component
symfony/event-dispatcher-contracts        v1.1.5  Generic abstractions related to dispatching event
symfony/finder                            v4.3.2  Symfony Finder Component
symfony/polyfill-ctype                    v1.11.0 Symfony polyfill for ctype functions
symfony/polyfill-mbstring                 v1.11.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php73                    v1.11.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions
symfony/process                           v4.3.2  Symfony Process Component
symfony/service-contracts                 v1.1.5  Generic abstractions related to writing services
symfony/yaml                              v4.3.2  Symfony Yaml Component
theiconic/php-ga-measurement-protocol     v2.7.1  Send data to Google Analytics from the server using PHP. This library fully implements GA measurement protocol.
theseer/tokenizer                         1.1.3   A small library for converting tokenized PHP source code into XML and potentially other formats
webmozart/assert                          1.4.0   Assertions to validate method input/output with nice error messages.
pnoeric commented 5 years ago

Hi @darinhoward and @homiedopie - really appreciate the quick attention and fix here. Can you also please bump the version number, so Packagist will see the new version and then my project (which loads this library via composer) will pick it up? Excited to test it.

darinhoward commented 5 years ago

Version numbers have been updated for both versions (1.1.1 and 2.1.1). @pnoeric

pnoeric commented 5 years ago

It's working great! Thank you.