[jifty-devel] patches to make Jifty more chatty

Dobrica Pavlinusic dpavlin at rot13.org
Mon Jun 19 09:41:41 EDT 2006


After short conversation at #jifty, it seemd that additional logging of
dispatch rules would be nice, so I wrote patch for Dispatcher which
adds dump to DEBUG log like this:

DEBUG - Rules in stage RUN:
under 'blog','wiki'
    run {...}
    on PUT 'entries/*'
        run {...}
    on '*/*'
        run {...}
    on '*'
        run {...}
    on ''
        show '/display/list'
under '(?-xism:logs/(\d+))'
    when {...}
    show '/error'
    set 'model'
    run {...}

However, I still haven't found good place to call dump_rules (right now,
I'm calling it from Jifty::Handler right after $self->dispatcher->import_plugins,
but that produces output twice). I'm open for suggestions where is the
right place to call it from.

Second patch adds action warnings and errors to debug log.

Does this make sense or am I barking at wrong tree?

-- 
Dobrica Pavlinusic               2share!2flame            dpavlin at rot13.org
Unix addict. Internet consultant.             http://www.rot13.org/~dpavlin
-------------- next part --------------
=== lib/Jifty/Dispatcher.pm
==================================================================
--- lib/Jifty/Dispatcher.pm	(revision 1316)
+++ lib/Jifty/Dispatcher.pm	(local)
@@ -1190,4 +1191,51 @@
     return @matches;
 }
 
+=head2 dump_rules
+
+Dump all defined rules in debug log
+
+=cut
+
+sub dump_rules {
+    my $self = shift;
+
+	sub unroll {
+		my ($level, $rule) = @_;
+		my $log =
+			# indentation
+			( "    " x $level ) .
+			# op
+			( $rule->[0] || "undef op" ) . ' ' .
+			# arguments
+			(
+				ref $rule->[1] eq 'ARRAY' ? "'" . join("','", @{ $rule->[1] }) . "'" :
+				ref $rule->[1] eq 'HASH'  ? $rule->[1]->{method} . " '" . $rule->[1]->{""} ."'" :
+				ref $rule->[1] eq 'CODE'  ? '{...}' :
+											"'" . $rule->[1] . "'"
+			) .
+			"\n";
+
+		if (ref $rule->[2] eq 'ARRAY') {
+			$level++;
+			foreach my $sr ( @{ $rule->[2] } ) {
+				$log .= unroll( $level, $sr );
+			}
+		}
+
+		return $log;
+	}
+
+	no strict 'refs';
+	foreach my $stage ( qw/SETUP RUN CLEANUP/ ) {
+
+		my $log = '';
+		foreach my $r ( @{ $self . '::RULES_' . $stage } ) {
+			$log .= unroll( 0,$r );
+		}
+
+		Jifty->log->debug( "Rules in stage $stage:\n", $log) if ($log);
+	}
+};
+
 1;
-------------- next part --------------
=== lib/Jifty/Action.pm
==================================================================
--- lib/Jifty/Action.pm	(revision 1316)
+++ lib/Jifty/Action.pm	(local)
@@ -169,6 +169,18 @@
     $self->log->debug("Running action");
     unless ($self->result->success) {
         $self->log->debug("Not taking action, as it doesn't validate");
+
+		# dump field warnings and errors to debug log
+		foreach my $what (qw/warnings errors/) {
+			my $f = "field_" . $what;
+			my @r =
+				map {
+					$_ . ": " . $self->result->{$f}->{$_}
+				} grep { $self->result->{$f}->{$_} }
+					keys %{ $self->result->{$f} };
+			$self->log->debug("Action result $what:\n\t", join("\n\t", @r)) if (@r);
+		}
+
         return;
     }
     $self->log->debug("Taking action");


More information about the jifty-devel mailing list