3

I have this in my Mojolicious app:

  use utf8;
  use Mojolicious::Lite;
  # ......
  use Mojo::Log;

  my $app = app;
  my $log = Mojo::Log->new(path => '/var/log/my_log.log', level => 'warn');

  get '/' => sub {

    .........

    $log->info("test123");

  }

  app->start;

The log file didn't even get created. After some time I created it myself, made it "chmod 777" and now it's still not being written into.

Why?

Ojman
  • 51
  • 4
  • Did you restart the app after you created the file chmod'd 777? – Chris Turner Jun 13 '18 at 13:13
  • 3
    If you only have the level `warn` you'll not get anything in the log but warnings or higher. The system does `info`, and you are doing `info` in your code. It doesn't need to write to the log, so it doesn't. – simbabque Jun 13 '18 at 13:14
  • @simbabque I've removed level => 'warn' and now it should be info by default. But it still isn't logging anything – Ojman Jun 13 '18 at 13:17
  • @ChrisTurner yes – Ojman Jun 13 '18 at 13:17
  • @Dada if it's debug by default, it should work in any case then – Ojman Jun 13 '18 at 14:24
  • Firstly, `Mojo::Log` will not create the log file until something is written to it. Secondly, are you aware that you need to access the URL for your app for the `$log->info` call to happen? Are you doing that? It would be much easier just to call `$log->info` when `$log` is first created then inside one of the path handlers. – Borodin Jun 13 '18 at 16:12
  • Actually, I can't reproduce your error: if i remove the `level => 'warn'`, it works. (if I have the permissions to access the file) Could you show us a minimalistic reproducible example and tell us exactly what you do to call the sub that is supposed to log? (for starter, remove the `....`) – Dada Jun 14 '18 at 09:31

1 Answers1

3

You need to associate the log with your app (reference https://metacpan.org/pod/Mojolicious#log)

my $log = Mojo::Log->new( path => '/var/log/my_log.log', level => 'warn' );

app->log($log);
Miller
  • 34,962
  • 4
  • 39
  • 60
  • 1
    That's not the issue. The issue is that `$log` is created with level `warn`, so `info` messages don't show. – Dada Jun 14 '18 at 09:25