Committer: ailyin
LJINT-467 (Comments for side projects (Lenta.ru olympics))U trunk/cgi-bin/Apache/LiveJournal.pm U trunk/cgi-bin/LJ/AccessLogRecord.pm
Modified: trunk/cgi-bin/Apache/LiveJournal.pm =================================================================== --- trunk/cgi-bin/Apache/LiveJournal.pm 2012-07-13 14:23:13 UTC (rev 22443) +++ trunk/cgi-bin/Apache/LiveJournal.pm 2012-07-13 14:27:34 UTC (rev 22444) @@ -2376,7 +2376,11 @@ return if $uri =~ m!^/(img|userpic)/!; } - my $rec = LJ::AccessLogRecord->new(LJ::Request->r); + my @recs = ( LJ::AccessLogRecord->new ); + if ( my $additional_records = $LJ::REQ_GLOBAL{'deferred_log_records'} ) { + push @recs, @$additional_records; + } + my @sinks = ( LJ::AccessLogSink::Database->new, LJ::AccessLogSink::DInsertd->new, @@ -2389,7 +2393,9 @@ } foreach my $sink (@sinks) { - $sink->log($rec); + foreach my $rec (@recs) { + $sink->log($rec); + } } } Modified: trunk/cgi-bin/LJ/AccessLogRecord.pm =================================================================== --- trunk/cgi-bin/LJ/AccessLogRecord.pm 2012-07-13 14:23:13 UTC (rev 22443) +++ trunk/cgi-bin/LJ/AccessLogRecord.pm 2012-07-13 14:27:34 UTC (rev 22444) @@ -2,48 +2,53 @@ use strict; sub new { - my $class = shift; + my ( $class, %args ) = @_; - my $now = time(); + my $now = $args{'time'} || time(); my @now = gmtime($now); - my $remote = eval { LJ::load_user(LJ::Request->notes('ljuser')) }; + my $remote_username = $args{'remote_username'} || LJ::Request->notes('ljuser'); + my $remote = eval { LJ::load_user($remote_username) }; my $remotecaps = $remote ? $remote->{caps} : undef; my $remoteid = $remote ? $remote->{userid} : 0; - my $ju = eval { LJ::load_userid(LJ::Request->notes('journalid')) }; - my $ctype = LJ::Request->content_type; + my $journalid = $args{'journalid'} || LJ::Request->notes('journalid'); + my $ju = eval { LJ::load_userid($journalid) }; + my $ctype = $args{'content_type'} || LJ::Request->content_type; $ctype =~ s/;.*//; # strip charset + my $request_time = $args{'request_time'} || LJ::Request->request_time(); + my $self = bless { '_now' => $now, - '_r' => LJ::Request->r, + '_r' => $args{'apreq'} || LJ::Request->r, 'whn' => sprintf("%04d%02d%02d%02d%02d%02d", $now[5]+1900, $now[4]+1, @now[3, 2, 1, 0]), 'whnunix' => $now, 'server' => $LJ::SERVER_NAME, - 'addr' => LJ::Request->remote_ip, - 'ljuser' => LJ::Request->notes('ljuser'), + 'addr' => $args{'remote_ip'} || LJ::Request->remote_ip, + 'ljuser' => $remote_username, 'remotecaps' => $remotecaps, 'remoteid' => $remoteid, - 'journalid' => LJ::Request->notes('journalid'), + 'journalid' => $journalid, 'journaltype' => ($ju ? $ju->{journaltype} : ""), 'journalcaps' => ($ju ? $ju->{caps} : undef), - 'codepath' => LJ::Request->notes('codepath'), - 'anonsess' => LJ::Request->notes('anonsess'), - 'langpref' => LJ::Request->notes('langpref'), - 'clientver' => LJ::Request->notes('clientver'), - 'uniq' => LJ::Request->notes('uniq'), - 'method' => LJ::Request->method, - 'uri' => LJ::Request->uri, - 'args' => scalar LJ::Request->args, - 'status' => LJ::Request->status, + 'codepath' => $args{'codepath'} || LJ::Request->notes('codepath'), + 'anonsess' => $args{'anonsess'} || LJ::Request->notes('anonsess'), + 'langpref' => $args{'langpref'} || LJ::Request->notes('langpref'), + 'clientver' => $args{'clientver'} || LJ::Request->notes('clientver'), + 'uniq' => $args{'uniq'} || LJ::Request->notes('uniq'), + 'method' => $args{'http_method'} || LJ::Request->method, + 'uri' => $args{'http_uri'} || LJ::Request->uri, + 'args' => $args{'http_argcount'} || scalar(LJ::Request->args), + 'status' => $args{'http_status'} || LJ::Request->status, 'ctype' => $ctype, - 'bytes' => LJ::Request->bytes_sent, - 'browser' => LJ::Request->header_in("User-Agent"), - 'secs' => $now - LJ::Request->request_time(), - 'ref' => LJ::Request->header_in("Referer"), - 'host' => LJ::Request->header_in("Host"), + 'bytes' => $args{'http_bytes_sent'} || LJ::Request->bytes_sent, + 'browser' => $args{'user_agent'} || LJ::Request->header_in("User-Agent"), + 'secs' => $now - $request_time, + 'ref' => $args{'referer'} || LJ::Request->header_in("Referer"), + 'host' => $args{'http_hostname'} || LJ::Request->header_in("Host"), + 'accept' => $args{'accept'} || LJ::Request->header_in('Accept'), }, $class; - $self->populate_gtop_info(); + $self->populate_gtop_info(%args); return $self; } @@ -53,7 +58,7 @@ } sub populate_gtop_info { - my $self = shift; + my ( $self, %args ) = @_; # If the configuration says to log statistics and GTop is available, then # add those data to the log @@ -63,10 +68,10 @@ # New Every Time: 2.17439 wallclock secs ( 1.18 usr + 0.94 sys = 2.12 CPU) @ 4716.98/s (n=10000) my $GTop = LJ::gtop() or return; - my $startcpu = LJ::Request->pnotes( 'gtop_cpu' ) or return; - my $endcpu = $GTop->cpu or return; - my $startmem = LJ::Request->pnotes( 'gtop_mem' ) or return; - my $endmem = $GTop->proc_mem( $$ ) or return; + my $startcpu = $args{'gtop_startcpu'} || LJ::Request->pnotes( 'gtop_cpu' ) or return; + my $endcpu = $args{'gtop_endcpu'} || $GTop->cpu or return; + my $startmem = $args{'gtop_startmem'} || LJ::Request->pnotes( 'gtop_mem' ) or return; + my $endmem = $args{'gtop_endmem'} || $GTop->proc_mem( $$ ) or return; my $cpufreq = $endcpu->frequency or return; # Map the GTop values into the corresponding fields in a slice