[GH-ISSUE #1789] "Object of class Monolog\Level could not be converted to int" #758

Closed
opened 2026-03-04 02:17:43 +03:00 by kerem · 15 comments
Owner

Originally created by @NavyCoat on GitHub (Jan 26, 2023).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1789

Monolog version 3.2

I'm experiencing strange behavior from Monolog when using any logging method.

ErrorException: Warning: Object of class Monolog\Level could not be converted to int
#12 /vendor/monolog/monolog/src/Monolog/Logger.php(314): Monolog\Logger::addRecord
#11 /vendor/monolog/monolog/src/Monolog/Logger.php(614): Monolog\Logger::error
#10 /src/MyFile.php(107): Service\MyFile::foobar

Inside foobar method I'm just executing
$this->logger->error('lorem ipsum');

I am still trying to understand why this is happening.
I tried to reproduce the steps in 3v4l.org and on my local env, but this only happens on my prod env.

Can this be related to this package, or is this something with opcache, maybe? Any idea how to fix this?

Originally created by @NavyCoat on GitHub (Jan 26, 2023). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1789 Monolog version 3.2 I'm experiencing strange behavior from Monolog when using any logging method. > ErrorException: Warning: Object of class Monolog\Level could not be converted to int #12 /vendor/monolog/monolog/src/Monolog/Logger.php(314): Monolog\Logger::addRecord #11 /vendor/monolog/monolog/src/Monolog/Logger.php(614): Monolog\Logger::error #10 /src/MyFile.php(107): Service\MyFile::foobar Inside foobar method I'm just executing ` $this->logger->error('lorem ipsum');` I am still trying to understand why this is happening. I tried to reproduce the steps in 3v4l.org and on my local env, but this only happens on my prod env. Can this be related to this package, or is this something with opcache, maybe? Any idea how to fix this?
kerem 2026-03-04 02:17:43 +03:00
  • closed this issue
  • added the
    Support
    label
Author
Owner

@stof commented on GitHub (Jan 27, 2023):

addRecord has an argument type being int|Level, so PHP should not try to convert the argument to int

<!-- gh-comment-id:1406267134 --> @stof commented on GitHub (Jan 27, 2023): `addRecord` has an argument type being `int|Level`, so PHP should not try to convert the argument to `int`
Author
Owner

@Seldaek commented on GitHub (Feb 4, 2023):

Seems like an issue on your end but I can't imagine what would cause this. Perhaps incorrect version installed? Or like two versions in parallel from different pieces of software you run?

<!-- gh-comment-id:1416843997 --> @Seldaek commented on GitHub (Feb 4, 2023): Seems like an issue on your end but I can't imagine what would cause this. Perhaps incorrect version installed? Or like two versions in parallel from different pieces of software you run?
Author
Owner

@Seldaek commented on GitHub (Feb 4, 2023):

I mean opcache could be a thing if you don't clear it on deploy and you have some old or new Logger class in there, but it sounds weird even then..

<!-- gh-comment-id:1416844140 --> @Seldaek commented on GitHub (Feb 4, 2023): I mean opcache could be a thing if you don't clear it on deploy and you have some old or new Logger class in there, but it sounds weird even then..
Author
Owner

@sakarikl commented on GitHub (Feb 6, 2023):

This same thing happens to us. And affects only servers where Instana is installed (instana.io)

<!-- gh-comment-id:1418792818 --> @sakarikl commented on GitHub (Feb 6, 2023): This same thing happens to us. And affects only servers where Instana is installed (instana.io)
Author
Owner

@sakarikl commented on GitHub (Feb 6, 2023):

I bet that for us Instana hooks into monolog in PHP process and now does it using old interface.

<!-- gh-comment-id:1418794467 --> @sakarikl commented on GitHub (Feb 6, 2023): I bet that for us Instana hooks into monolog in PHP process and now does it using old interface.
Author
Owner

@NavyCoat commented on GitHub (Feb 6, 2023):

@sakarikl Thanks for a clue! I'm not using Instana, but maybe I have another tool that is doing something like it.

<!-- gh-comment-id:1419115712 --> @NavyCoat commented on GitHub (Feb 6, 2023): @sakarikl Thanks for a clue! I'm not using Instana, but maybe I have another tool that is doing something like it.
Author
Owner

@NavyCoat commented on GitHub (Feb 8, 2023):

I bet that for us Instana hooks into monolog in PHP process and now does it using old interface.

Lol, that was Instana, indeed. 😂 Thanks @sakarikl !

<!-- gh-comment-id:1422454591 --> @NavyCoat commented on GitHub (Feb 8, 2023): > I bet that for us Instana hooks into monolog in PHP process and now does it using old interface. Lol, that was Instana, indeed. :joy: Thanks @sakarikl !
Author
Owner

@sakarikl commented on GitHub (Feb 8, 2023):

I got a patch file from instana support that basically just changed enum usages to integers. And no timeline when actual fix would be available. :)

<!-- gh-comment-id:1422559501 --> @sakarikl commented on GitHub (Feb 8, 2023): I got a patch file from instana support that basically just changed enum usages to integers. And no timeline when actual fix would be available. :)
Author
Owner

@matt-horwood-mayden commented on GitHub (Sep 12, 2023):

Hello,
We are running instana and have also hit this issue, Instana have provided a patch that should fix the issue. But they seem to think its a Monolog issue.

Here is the patch if you need it, not sure if this should land as a PR also

--- vendor/monolog/monolog/src/Monolog/Logger.php.orig	2022-07-24 05:00:55.000000000 -0700
+++ vendor/monolog/monolog/src/Monolog/Logger.php	2022-11-07 08:57:00.953341669 -0800
@@ -559,7 +559,8 @@
      */
     public function debug(string|\Stringable $message, array $context = []): void
     {
-        $this->addRecord(Level::Debug, (string) $message, $context);
+        //$this->addRecord(Level::Debug, (string) $message, $context);
+        $this->addRecord(7, (string) $message, $context);
     }
 
     /**
@@ -572,7 +573,8 @@
      */
     public function info(string|\Stringable $message, array $context = []): void
     {
-        $this->addRecord(Level::Info, (string) $message, $context);
+        //$this->addRecord(Level::Info, (string) $message, $context);
+        $this->addRecord(6, (string) $message, $context);
     }
 
     /**
@@ -585,7 +587,8 @@
      */
     public function notice(string|\Stringable $message, array $context = []): void
     {
-        $this->addRecord(Level::Notice, (string) $message, $context);
+        //$this->addRecord(Level::Notice, (string) $message, $context);
+        $this->addRecord(5, (string) $message, $context);
     }
 
     /**
@@ -598,7 +601,8 @@
      */
     public function warning(string|\Stringable $message, array $context = []): void
     {
-        $this->addRecord(Level::Warning, (string) $message, $context);
+        //$this->addRecord(Level::Warning, (string) $message, $context);
+        $this->addRecord(4, (string) $message, $context);
     }
 
     /**
@@ -611,7 +615,8 @@
      */
     public function error(string|\Stringable $message, array $context = []): void
     {
-        $this->addRecord(Level::Error, (string) $message, $context);
+        //$this->addRecord(Level::Error, (string) $message, $context);
+        $this->addRecord(3, (string) $message, $context);
     }
 
     /**
@@ -624,7 +629,8 @@
      */
     public function critical(string|\Stringable $message, array $context = []): void
     {
-        $this->addRecord(Level::Critical, (string) $message, $context);
+        //$this->addRecord(Level::Critical, (string) $message, $context);
+        $this->addRecord(2, (string) $message, $context);
     }
 
     /**
@@ -637,7 +643,8 @@
      */
     public function alert(string|\Stringable $message, array $context = []): void
     {
-        $this->addRecord(Level::Alert, (string) $message, $context);
+        //$this->addRecord(Level::Alert, (string) $message, $context);
+        $this->addRecord(1, (string) $message, $context);
     }
 
     /**
@@ -650,7 +657,8 @@
      */
     public function emergency(string|\Stringable $message, array $context = []): void
     {
-        $this->addRecord(Level::Emergency, (string) $message, $context);
+        //$this->addRecord(Level::Emergency, (string) $message, $context);
+        $this->addRecord(0, (string) $message, $context);
     }
 
     /**
<!-- gh-comment-id:1715123408 --> @matt-horwood-mayden commented on GitHub (Sep 12, 2023): Hello, We are running instana and have also hit this issue, Instana have provided a patch that should fix the issue. But they seem to think its a Monolog issue. Here is the patch if you need it, not sure if this should land as a PR also ``` --- vendor/monolog/monolog/src/Monolog/Logger.php.orig 2022-07-24 05:00:55.000000000 -0700 +++ vendor/monolog/monolog/src/Monolog/Logger.php 2022-11-07 08:57:00.953341669 -0800 @@ -559,7 +559,8 @@ */ public function debug(string|\Stringable $message, array $context = []): void { - $this->addRecord(Level::Debug, (string) $message, $context); + //$this->addRecord(Level::Debug, (string) $message, $context); + $this->addRecord(7, (string) $message, $context); } /** @@ -572,7 +573,8 @@ */ public function info(string|\Stringable $message, array $context = []): void { - $this->addRecord(Level::Info, (string) $message, $context); + //$this->addRecord(Level::Info, (string) $message, $context); + $this->addRecord(6, (string) $message, $context); } /** @@ -585,7 +587,8 @@ */ public function notice(string|\Stringable $message, array $context = []): void { - $this->addRecord(Level::Notice, (string) $message, $context); + //$this->addRecord(Level::Notice, (string) $message, $context); + $this->addRecord(5, (string) $message, $context); } /** @@ -598,7 +601,8 @@ */ public function warning(string|\Stringable $message, array $context = []): void { - $this->addRecord(Level::Warning, (string) $message, $context); + //$this->addRecord(Level::Warning, (string) $message, $context); + $this->addRecord(4, (string) $message, $context); } /** @@ -611,7 +615,8 @@ */ public function error(string|\Stringable $message, array $context = []): void { - $this->addRecord(Level::Error, (string) $message, $context); + //$this->addRecord(Level::Error, (string) $message, $context); + $this->addRecord(3, (string) $message, $context); } /** @@ -624,7 +629,8 @@ */ public function critical(string|\Stringable $message, array $context = []): void { - $this->addRecord(Level::Critical, (string) $message, $context); + //$this->addRecord(Level::Critical, (string) $message, $context); + $this->addRecord(2, (string) $message, $context); } /** @@ -637,7 +643,8 @@ */ public function alert(string|\Stringable $message, array $context = []): void { - $this->addRecord(Level::Alert, (string) $message, $context); + //$this->addRecord(Level::Alert, (string) $message, $context); + $this->addRecord(1, (string) $message, $context); } /** @@ -650,7 +657,8 @@ */ public function emergency(string|\Stringable $message, array $context = []): void { - $this->addRecord(Level::Emergency, (string) $message, $context); + //$this->addRecord(Level::Emergency, (string) $message, $context); + $this->addRecord(0, (string) $message, $context); } /** ```
Author
Owner

@Seldaek commented on GitHub (Sep 12, 2023):

Yeah sorry but we are not going to patch this like that, it makes no sense. They should make sure to update their support to include Monolog 3.

<!-- gh-comment-id:1715153484 --> @Seldaek commented on GitHub (Sep 12, 2023): Yeah sorry but we are not going to patch this like that, it makes no sense. They should make sure to update their support to include Monolog 3.
Author
Owner

@sakarikl commented on GitHub (Sep 12, 2023):

We ended up dumping Instana altogether mainly because of this.

<!-- gh-comment-id:1715235075 --> @sakarikl commented on GitHub (Sep 12, 2023): We ended up dumping Instana altogether mainly because of this.
Author
Owner

@bkuschel commented on GitHub (Nov 30, 2023):

We are looking at the issue and investigating a possible fix for the Instana PHP Tracer.

<!-- gh-comment-id:1833955902 --> @bkuschel commented on GitHub (Nov 30, 2023): We are looking at the issue and investigating a possible fix for the Instana PHP Tracer.
Author
Owner

@ltrk2 commented on GitHub (Feb 26, 2024):

@NavyCoat @sakarikl @Seldaek

We fixed the behaviour identified in this issue by rolling out general support for Monolog 3 with Instana PHP Tracer 3.0.0.

<!-- gh-comment-id:1965229577 --> @ltrk2 commented on GitHub (Feb 26, 2024): @NavyCoat @sakarikl @Seldaek We fixed the behaviour identified in this issue by rolling out general support for Monolog 3 with Instana PHP Tracer 3.0.0.
Author
Owner

@matt-horwood-mayden commented on GitHub (Feb 27, 2024):

Morning @ltrk2

Do you have a planed release data for that?

<!-- gh-comment-id:1965948054 --> @matt-horwood-mayden commented on GitHub (Feb 27, 2024): Morning @ltrk2 Do you have a planed release data for that?
Author
Owner

@ltrk2 commented on GitHub (Feb 27, 2024):

@matt-horwood-mayden it's already out. It was rolled out across the board yesterday (February 26).

<!-- gh-comment-id:1967524443 --> @ltrk2 commented on GitHub (Feb 27, 2024): @matt-horwood-mayden it's already out. It was rolled out across the board yesterday (February 26).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#758
No description provided.