Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r17920: bugfix and more correct logging

Committer: ailyin
bugfix and more correct logging
U   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);
 

Tags: andy, livejournal, placeholder, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments