Committer: ailyin
bugfix and more correct loggingU trunk/cgi-bin/LJ/MemCache.pm A trunk/var/memcache-profile/ A trunk/var/memcache-profile/.placeholder
Modified: trunk/cgi-bin/LJ/MemCache.pm =================================================================== --- trunk/cgi-bin/LJ/MemCache.pm 2010-12-13 11:26:28 UTC (rev 17919) +++ trunk/cgi-bin/LJ/MemCache.pm 2010-12-13 11:47:29 UTC (rev 17920) @@ -158,6 +158,7 @@ use String::CRC32 qw(); use Carp qw(); +use IO::Handle qw(); ### VARIABLES ### @@ -211,6 +212,8 @@ userpic preformated ) ], ); +my $logfile = undef; + ### PRIVATE FUNCTIONS ### sub _hashfunc { @@ -263,11 +266,18 @@ *_profile = sub { my ( $funcname, $key, $result ) = @_; + unless ( defined $logfile ) { + open $logfile, ">>$ENV{LJHOME}/var/memcache-profile/$$.log" + or die "cannot open log: $!"; + + $logfile->autoflush; + } + $key =~ s/\b\d+\b/?/g; - warn "[memcache-profile] $funcname($key) " . - ( defined $result ? '[hit]' : '[miss]' ) . - "\n"; + print $logfile "[memcache-profile] $funcname($key) " . + ( defined $result ? '[hit]' : '[miss]' ) . + "\n"; }; } else { *_profile = sub {}; @@ -486,7 +496,7 @@ sub incr { my ( $key, $value ) = @_; - $value = '' unless defined $value; + $value = 1 unless defined $value; my $conn = _get_connection($key); @@ -501,7 +511,7 @@ sub decr { my ( $key, $value ) = @_; - $value = '' unless defined $value; + $value = 1 unless defined $value; my $conn = _get_connection($key);