[svk-commit] r2146 - in branches/svk-logging/lib/SVK: . Command Editor

stig at bestpractical.com stig at bestpractical.com
Thu Nov 16 05:45:59 EST 2006


Author: stig
Date: Thu Nov 16 05:45:58 2006
New Revision: 2146

Modified:
   branches/svk-logging/lib/SVK/Command/Commit.pm
   branches/svk-logging/lib/SVK/Editor/Copy.pm
   branches/svk-logging/lib/SVK/Editor/Status.pm
   branches/svk-logging/lib/SVK/Logger.pm
   branches/svk-logging/lib/SVK/Merge.pm
   branches/svk-logging/lib/SVK/Path.pm
   branches/svk-logging/lib/SVK/Path/View.pm
   branches/svk-logging/lib/SVK/Test.pm

Log:
* convert a bunch of warn "..." if $main::DEBUG to use $logger->debug("...") instead.
* Also, you can now change the logging level by setting the SVKDEBUG variable 
  (should this be SVKLOGGING instead?) to one of: debug, info, warn, error, fatal 
  (but not all of those are used yet)

Modified: branches/svk-logging/lib/SVK/Command/Commit.pm
==============================================================================
--- branches/svk-logging/lib/SVK/Command/Commit.pm	(original)
+++ branches/svk-logging/lib/SVK/Command/Commit.pm	Thu Nov 16 05:45:58 2006
@@ -5,6 +5,7 @@
 use constant opt_recursive => 1;
 use SVK::XD;
 use SVK::I18N;
+use SVK::Logger;
 use SVK::Editor::Status;
 use SVK::Editor::Sign;
 use SVK::Editor::Dynamic;
@@ -551,7 +552,7 @@
     $self->{xd}->checkout_delta
 	( $target->for_checkout_delta,
 	  depth => $self->{recursive} ? undef : 0,
-	  debug => $main::DEBUG,
+	  debug => $logger->is_debug(),
 	  xdroot => $xdroot,
 	  editor => $editor,
 	  send_delta => !$cb{send_fulltext},

Modified: branches/svk-logging/lib/SVK/Editor/Copy.pm
==============================================================================
--- branches/svk-logging/lib/SVK/Editor/Copy.pm	(original)
+++ branches/svk-logging/lib/SVK/Editor/Copy.pm	Thu Nov 16 05:45:58 2006
@@ -2,6 +2,7 @@
 use strict;
 use warnings;
 use SVK::Version;  our $VERSION = $SVK::VERSION;
+use SVK::Logger;
 
 require SVN::Delta;
 use base 'SVK::Editor::ByPass';
@@ -85,7 +86,7 @@
 	$pool->clear;
 	my ($toroot, $fromroot, $src_frompath) =
 	    SVK::Path::nearest_copy($cur_root, $cur_path, $ppool);
-	warn "===> $cur_path => $src_frompath" if $main::DEBUG;
+	$logger->debug("===> $cur_path => ".($src_frompath||''));
 	return unless defined $src_frompath;
 
 	# don't use the same copy twice
@@ -148,13 +149,12 @@
 	}
 
 	# GRR! cleanup this!
-	warn "==> $path(:$to) is copied from $src_frompath:$src_from" if $main::DEBUG;
+	$logger->debug("==> $path(:$to) is copied from $src_frompath:$src_from");
 	if (my ($frompath, $from) = $self->{cb_resolve_copy}->($path, $replace, $src_frompath, $src_from)) {
 	    push @{$self->{incopy}}, { path => $path,
 				       fromrev => $src_from,
 				       frompath => $src_frompath };
-	    warn "==> resolved to $frompath:$from"
-		if $main::DEBUG;
+	    $logger->debug("==> resolved to $frompath:$from");
 	    return $self->copy_source($src_frompath, $src_from);
 	}
 	else {
@@ -212,7 +212,7 @@
     my ($self, $path, $pbaton, @arg) = @_;
     return $self->{ignore_baton} if $self->should_ignore($path, $pbaton);
     if (my @ret = $self->find_copy($path, 1)) {
-	warn "==> turn $path into replace: ".join(',', at ret) if $main::DEBUG;
+	$logger->debug("==> turn $path into replace: ".join(',', at ret));
 	$self->SUPER::delete_entry($path, $arg[0], $pbaton, $arg[1]);
 	return $self->replay_add_history('directory', $path, $pbaton, @ret, $arg[1])
     }
@@ -224,7 +224,7 @@
     my ($self, $path, $pbaton, @arg) = @_;
     return $self->{ignore_baton} if $self->should_ignore($path, $pbaton);
     if (my @ret = $self->find_copy($path, 1)) {
-	warn "==> turn file $path into replace" if $main::DEBUG;
+	$logger->debug("==> turn file $path into replace");
 	$self->SUPER::delete_entry($path, $arg[0], $pbaton, $arg[1]);
 	return $self->replay_add_history('file', $path, $pbaton, @ret, $arg[1])
     }
@@ -307,8 +307,8 @@
 	 translate => sub { $_[0] =~ s/^\Q$src_target/$target/ })
 	    if $type eq 'file';
 
-    warn "****==> to delta $src_anchor / $src_target @ $self->{incopy}[-1]{fromrev} vs $self->{src}{path} / $path" if $main::DEBUG;;
-    warn "==> sample" if $main::DEBUG;
+    $logger->debug("****==> to delta $src_anchor / $src_target @ $self->{incopy}[-1]{fromrev} vs $self->{src}{path} / $path");
+    $logger->debug("==> sample");
     require SVK::Editor::Delay;
     SVK::XD->depot_delta
 	    ( oldroot => $self->{copyboundry_root}->fs->
@@ -316,8 +316,8 @@
 	      newroot => $self->{src}->root,
 	      oldpath => [$src_anchor, $src_target],
 	      newpath => File::Spec::Unix->catdir($self->{src}->path_anchor, $path),
-	      editor => SVN::Delta::Editor->new(_debug => 1)) if $main::DEBUG;
-    warn "==> done sample" if $main::DEBUG;
+	      editor => SVN::Delta::Editor->new(_debug => 1)) if $logger->is_debug();
+    $logger->debug("==> done sample");
     SVK::XD->depot_delta
 	    ( oldroot => $self->{copyboundry_root}->fs->
 	      revision_root($self->{incopy}[-1]{fromrev}),
@@ -325,7 +325,7 @@
 	      oldpath => [$src_anchor, $src_target],
 	      newpath => File::Spec::Unix->catdir($self->{src}->path_anchor, $path),
 	      editor => SVK::Editor::Delay->new(_editor => [$editor]) );
-    warn "***=>done delta" if $main::DEBUG;
+    $logger->debug("***=>done delta");
     # close file is done by the delta;
     return bless { path => $path,
 		   baton => $baton,

Modified: branches/svk-logging/lib/SVK/Editor/Status.pm
==============================================================================
--- branches/svk-logging/lib/SVK/Editor/Status.pm	(original)
+++ branches/svk-logging/lib/SVK/Editor/Status.pm	Thu Nov 16 05:45:58 2006
@@ -1,6 +1,7 @@
 package SVK::Editor::Status;
 use strict;
 use SVN::Delta;
+use SVK::Logger;
 use SVK::Version;  our $VERSION = $SVK::VERSION;
 use base 'SVK::Editor';
 
@@ -13,7 +14,7 @@
 		   (defined $self->report ? $self->report : '') ) unless $self->notify;
     $self->tree(Data::Hierarchy->new) unless $self->tree;
     use Data::Dumper;
-    warn Dumper($self) if $main::DEBUG;
+    $logger->debug(Dumper($self));
     return $self;
 }
 

Modified: branches/svk-logging/lib/SVK/Logger.pm
==============================================================================
--- branches/svk-logging/lib/SVK/Logger.pm	(original)
+++ branches/svk-logging/lib/SVK/Logger.pm	Thu Nov 16 05:45:58 2006
@@ -6,8 +6,12 @@
 
 use Log::Log4perl qw(get_logger :levels);
 
-my $conf = q{
-  log4perl.rootLogger=INFO, Screen
+my $level = {
+    map { $_ => uc $_ } qw( debug info warn error fatal )
+}->{ lc $ENV{SVKDEBUG} } || 'INFO';
+
+my $conf = qq{
+  log4perl.rootLogger=$level, Screen
   log4perl.appender.Screen = Log::Log4perl::Appender::Screen
   log4perl.appender.Screen.stderr = 0
   log4perl.appender.Screen.layout = PatternLayout

Modified: branches/svk-logging/lib/SVK/Merge.pm
==============================================================================
--- branches/svk-logging/lib/SVK/Merge.pm	(original)
+++ branches/svk-logging/lib/SVK/Merge.pm	Thu Nov 16 05:45:58 2006
@@ -519,8 +519,7 @@
 		      }) or die loc("Can't find the first revision of %1.\n", $src->path);
 	    }
 	}
-	warn "==> got $boundry_rev as copyboundry, add $self->{fromrev} as boundry as well"
-	    if $main::DEBUG;
+	$logger->debug("==> got $boundry_rev as copyboundry, add $self->{fromrev} as boundry as well");
 
 	if (defined $boundry_rev) {
 	  require SVK::Editor::Copy;
@@ -576,7 +575,7 @@
  # translate to (path, rev) for dst
 sub resolve_copy {
     my ($self, $srcinfo, $dstinfo, $cp_path, $cp_rev) = @_;
-    warn "==> to resolve $cp_path $cp_rev" if $main::DEBUG;
+    $logger->debug("==> to resolve $cp_path $cp_rev");
     my $path = $cp_path;
     my $src = $self->{src};
     my $srcpath = $src->path;

Modified: branches/svk-logging/lib/SVK/Path.pm
==============================================================================
--- branches/svk-logging/lib/SVK/Path.pm	(original)
+++ branches/svk-logging/lib/SVK/Path.pm	Thu Nov 16 05:45:58 2006
@@ -7,6 +7,7 @@
 use Class::Autouse qw(SVK::Editor::Dynamic SVK::Editor::TxnCleanup);
 use SVN::Delta;
 
+use SVK::Logger;
 use SVK::Depot;
 use base 'SVK::Accessor';
 
@@ -200,7 +201,7 @@
 
 	my ($base_rev, $editor) = $m->get_merge_back_editor
 	    ($mpath, $arg{message}, $mcallback);
-	$editor->{_debug}++ if $main::DEBUG;
+	$editor->{_debug}++ if $logger->is_debug();
 	return ($editor, $inspector,
 		mirror => $m,
 		post_handler => \$post_handler,
@@ -620,7 +621,7 @@
     $self = $self->new->as_depotpath;
     my $usrc = $src->universal;
     my $srckey = join(':', $usrc->{uuid}, $usrc->{path});
-    warn "trying to look for the revision on $self->{path} that was merged from $srckey\@$src->{revision} at $path" if $main::DEBUG;
+    $logger->debug("trying to look for the revision on $self->{path} that was merged from $srckey\@$src->{revision} at $path");
 
     my %copies = map { join(':', $_->{uuid}, $_->{path}) => $_ }
 	reverse $merge->copy_ancestors($self);
@@ -628,7 +629,7 @@
     $self->search_revision
 	( cmp => sub {
 	      my $rev = shift;
-	      warn "==> look at $rev" if $main::DEBUG;
+	      $logger->debug("==> look at $rev");
 	      my $search = $self->new(revision => $rev);
 	      my $minfo = { %copies,
 			    %{$merge->merge_info($search)} };
@@ -658,7 +659,7 @@
 	      }
 
 	      # see if prev got different merge info about srckey.
-	      warn "==> to compare with $prev" if $main::DEBUG;
+	      $logger->debug("==> to compare with $prev");
 	      my $uret = $merge->merge_info_with_copy
 		  ($self->new(revision => $prev))->{$srckey}
 		      or return 0;

Modified: branches/svk-logging/lib/SVK/Path/View.pm
==============================================================================
--- branches/svk-logging/lib/SVK/Path/View.pm	(original)
+++ branches/svk-logging/lib/SVK/Path/View.pm	Thu Nov 16 05:45:58 2006
@@ -2,7 +2,7 @@
 use strict;
 use SVK::Version;  our $VERSION = $SVK::VERSION;
 use SVK::I18N;
-
+use SVK::Logger;
 use base 'SVK::Path';
 
 __PACKAGE__->mk_clonable_accessors(qw(source));
@@ -70,7 +70,7 @@
 	    );
     }
     $editor = SVN::Delta::Editor->new(_debug => 1, _editor => [$editor])
-	if $main::DEBUG;
+	if $logger->is_debug();
     return ($editor, $inspector, %extra);
 }
 

Modified: branches/svk-logging/lib/SVK/Test.pm
==============================================================================
--- branches/svk-logging/lib/SVK/Test.pm	(original)
+++ branches/svk-logging/lib/SVK/Test.pm	Thu Nov 16 05:45:58 2006
@@ -3,6 +3,8 @@
 use SVK::Version;  our $VERSION = $SVK::VERSION;
 use base 'Exporter';
 
+use SVK::Logger;
+
 our @EXPORT = qw(plan_svm new_repos build_test build_floating_test
 		 get_copath append_file overwrite_file
 		 overwrite_file_raw is_file_content
@@ -58,11 +60,11 @@
     *SVK::Util::get_prompt = *SVK::XD::get_prompt = sub {
 	local $| = 1;
 	print "$_[0]\n" if $show_prompt;
-	print STDOUT "$_[0]\n" if $main::DEBUG;
+	$logger->debug("$_[0]");
 	return $answer unless ref($answer); # compat
 	die "expecting input" unless @$answer;
 	my $ans = shift @$answer;
-	print STDOUT "-> $answer->[0]\n" if $main::DEBUG;
+	$logger->debug("-> ".($answer->[0]||''));
 	return $ans unless ref($ans);
 	
 	if (ref($ans->[0]) eq 'Regexp') {


More information about the svk-commit mailing list