OSDN Git Service

Plugin: add RequestLogger (developing)
authorhylom <hylom@users.sourceforge.jp>
Thu, 12 Oct 2017 10:08:07 +0000 (19:08 +0900)
committerhylom <hylom@users.sourceforge.jp>
Thu, 12 Oct 2017 10:08:07 +0000 (19:08 +0900)
src/newslash_web/lib/Newslash/Plugin/RequestLogger.pm [new file with mode: 0644]
src/newslash_web/lib/Newslash/Web.pm

diff --git a/src/newslash_web/lib/Newslash/Plugin/RequestLogger.pm b/src/newslash_web/lib/Newslash/Plugin/RequestLogger.pm
new file mode 100644 (file)
index 0000000..b3c1513
--- /dev/null
@@ -0,0 +1,35 @@
+package Newslash::Plugin::RequestLogger;
+use Mojo::Base 'Mojolicious::Plugin';
+use Data::Dumper;
+
+use constant KEY_PREFIX => 'ns_reqlog';
+
+sub register {
+    my ($self, $app, $conf) = @_;
+    my $r_opts = $app->config->{RequestLogger} || {};
+    my $opts = $conf->{options} || {};
+
+    $self->{options} = {%$opts, %$r_opts};
+    $self->{app} = $app;
+    $app->helper(request_logger => sub { state $request_logger = $self; });
+
+    $app->hook(after_dispatch => sub {
+                   my $c = shift;
+                   my $m = $c->match;
+                   my $stack = pop $m->stack->[-1];
+
+                   if ($stack->{content_path}) {
+                       # static_contents
+                       # log content_path
+                       return;
+                   }
+                   if ($stack->{action}) {
+                       # action
+                       # log action, controller, etc. params
+                   }
+               });
+}
+
+
+
+1;
index 2a3b45d..442bf21 100644 (file)
@@ -106,6 +106,8 @@ sub startup {
     # Event Que
     $app->plugin('Newslash::Plugin::EventQue');
 
+    # Request Logger
+    #$app->plugin('Newslash::Plugin::RequestLogger');
 
     ############################################################
     #