/[pxelator]/lib/PXElator/log.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/PXElator/log.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 72 - (hide annotations)
Thu Jul 30 23:57:19 2009 UTC (14 years, 8 months ago) by dpavlin
File size: 983 byte(s)
record and display log changes by mac addresses

1 dpavlin 49 package log;
2    
3     use warnings;
4     use strict;
5     use autodie;
6    
7     use server;
8    
9     our $dir = "$server::base_dir/log";
10     mkdir $dir unless -e $dir;
11    
12     foreach ( glob("$dir/pxelator.*.log") ) {
13     warn "unlink $_ ", -s $_;
14     unlink $_;
15     }
16    
17 dpavlin 72 my $mac_dir = "$dir/mac";
18     mkdir $mac_dir unless -e $mac_dir;
19    
20     use Time::HiRes qw/time/;
21     my $start_t = time();
22    
23     sub mac {
24     my ( $mac, $message ) = @_;
25     print "MAC $mac $message\n";
26     open(my $fh, '>>', "$mac_dir/$mac");
27     print $fh time() - $start_t, "\t$message\n";
28     close($fh);
29     }
30    
31     our $mac_pos;
32    
33     use File::Slurp;
34    
35     sub mac_changes {
36     my $mac = shift;
37    
38     my @changes;
39    
40     foreach my $mac_path ( sort glob("$mac_dir/*") ) {
41    
42     open(my $fh, '<', $mac_path);
43    
44     my $pos = $mac_path;
45     $pos =~ s{/([^/]+$)}{/\.$1\.pos};
46     my $mac = uc($1);
47     $mac =~ s{(..)}{$1:}g;
48     $mac =~ s{:$}{};
49     seek $fh, read_file($pos), 0 if -e $pos;
50    
51     while(<$fh>) {
52     chomp;
53     push @changes, "$_\t$mac";
54     }
55    
56     warn "pos $pos ",tell($fh);
57     write_file $pos, tell($fh);
58     }
59    
60     return @changes;
61     }
62    
63 dpavlin 49 1;

  ViewVC Help
Powered by ViewVC 1.1.26