Mojoliciousのログにパッケージ名と行数も出力してみた

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package MyappPL;
use Mojo::Base 'Mojolicious';

# This method will run once at server start
sub startup {
  my $self = shift;

  # ここから
  if ($self->log->is_level('debug')) {
    no warnings 'redefine';
    *Mojo::Log::format = sub {
      my ($self, $level, @lines) = @_;
      my @caller = caller(4);
      my $caller = join ' ', $caller[0], $caller[2];
      return
          '['
        . localtime(time)
        . "] [$level] [$caller] "
        . join("\n", @lines) . "\n";
    };
  }
  # ここまで追加

  # Documentation browser under "/perldoc"
  $self->plugin('PODRenderer');

  # Router
  my $r = $self->routes;

  # Normal route to controller
  $r->get('/')->to('example#welcome');
}

1;
1
2
3
4
5
6
7
[Thu Nov  8 17:31:14 2012] [info] [Mojo::Server::Daemon 198] Listening at "http://*:3001".
[Thu Nov  8 17:31:25 2012] [debug] [Mojolicious 31] Your secret passphrase needs to be changed!!!
[Thu Nov  8 17:31:25 2012] [debug] [Mojolicious::Plugin::RequestTimer 42] GET / (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11).
[Thu Nov  8 17:31:25 2012] [debug] [Mojolicious::Routes 136] Routing to controller "MyappPL::Example" and action "welcome".
[Thu Nov  8 17:31:25 2012] [debug] [Mojolicious::Plugin::EPLRenderer 49] Rendering template "example/welcome.html.ep".
[Thu Nov  8 17:31:25 2012] [debug] [Mojolicious::Plugin::EPLRenderer 49] Rendering template "layouts/default.html.ep".
[Thu Nov  8 17:31:25 2012] [debug] [Mojolicious::Plugin::RequestTimer 29] 200 OK (0.037642s, 26.566/s).
comments powered by Disqus
Built with Hugo
テーマ StackJimmy によって設計されています。