decahedronio / monolog-sticky-context

A Monolog processor to easily attach sticky context data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Context is lost after $recursionLimit messages

AdrianSchneider opened this issue · comments

If you set some context, and then log it more than StickyContextStack::$recursionLimit times, the context is lost.

Test case:

    public function test_it_can_retain_sticky_data()
    {
        $stack = new StickyContextStack();
        StickyContextStack::$recursionLimit = 3;

        $stack->add('username', 'aryastark');
        $this->assertEquals(['username' => 'aryastark'], $stack->all());
        $this->assertEquals(['username' => 'aryastark'], $stack->all());
        $this->assertEquals(['username' => 'aryastark'], $stack->all());

        // fails
        $this->assertEquals(['username' => 'aryastark'], $stack->all());
    }

Output:

Time: 19 ms, Memory: 4.00 MB

There was 1 failure:

1) StickyContextStackTest::test_it_can_retain_sticky_data
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    'username' => 'aryastark'
 )

Looking at the code, it never resets the counter anywhere.