Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/MonologHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ protected function addContext(array $context = [])
}

// Add session data.
if ($session = $this->app->session->all()) {
$session = isset($this->app) ? $this->app->session->all() : null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should'nt you check for $this->app->has('session') here instead of isset($this->app)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you shouldn't because if $this->app is null you cannot call the method has, and that's why it's failing now and it's better to check first with an isset()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my use cases it was only failing because session does not exist on $this->app, not because $this->app does not exist at all. In which situation $this->app is not defined?

Copy link

@tristanjahier tristanjahier Oct 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested again and $this->app does exists in Lumen, that is the ->session part that is failing.

Changing the if condition to $this->app->has('session') && $session = $this->app->session->all() solves the problem.

if ($session) {
// Add user session information.
if (isset($person['session'])) {
$person['session'] = array_merge($session, $person['session']);
Expand Down