Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mojo::Log does not log to path on "context" grandchildren, if child not yet used #2218

Open
Xyem opened this issue Jan 6, 2025 · 0 comments

Comments

@Xyem
Copy link

Xyem commented Jan 6, 2025

  • Mojolicious version: 9.39
  • Perl version: v5.40.0, linux
  • Operating system: Arch Linux

Steps to reproduce the behavior

use Mojo::Log;

my $log = Mojo::Log->new(path => 'app.log')->info('Core log object');
my $child_log = $log->context('[stream id 1234]');
my $grandchild_log = $child_log->context('[stream id 1234]', '[username foo]')->info('Grandchild log object');

Expected behavior

Expected that all messages would be logged to the file.

Actual behavior

'Grandchild log object' is not logged to the file and is output to the terminal instead.
This only happens if $child_log has not been used to log. If/once it has, the message goes to the file as expected.

Implemented workaround

Adding a Log class that inherits from Mojo::Log and passes the parent instead of itself as the parent (if it exists), was an acceptable workaround for this application (at least, for the time being), but other side-effects of doing this aren't known/explored.

package MyApp::Log;
use Mojo::Base 'Mojo::Log', '-signatures';

sub context ($self, @context) {
  return $self->new(
    context => \@context,
    level   => $self->level,
    parent  => ($self->{parent} || $self),
  );
}

1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant