-
Notifications
You must be signed in to change notification settings - Fork 4
/
split.pl
36 lines (35 loc) · 1.13 KB
/
split.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl
use strict;
use Time::Local;
sub open_file {
my $filename = shift;
open(my $fh, '>', $filename) or die "cannot open $filename";
return $fh;
}
my %all_fd = ();
while (<>) {
if(/.*hostname=(?<hostname>[A-Za-z-]*[0-9]*).*
(?<year>[0-9][0-9][0-9][0-9])-(?<month>[0-9][0-9])-(?<day>[0-9][0-9])\s(?<hour>[0-9][0-9]):(?<minute>[0-9][0-9]):(?<second>[0-9][0-9])\.(?<mili>[0-9][0-9][0-9])
\s+
\[(?<loglevel>.*)\]
\s<[0-9.]*>@
(?<module>[0-9a-zA-Z_]+):
(?<fun>[0-9a-zA-Z_]+):
(?<line>[0-9]+)\s
/xms
){
my $filename = $+{hostname} . "." . $+{module} . "." . $+{fun} . "." . $+{line} . "." . $+{loglevel} . ".log";
if (not exists $all_fd{$filename} ) {
$all_fd{$filename} = open_file($filename);
}
my $fd = $all_fd{$filename};
my $m2 = $+{month} - 1;
my $timestamp = timelocal($+{second},$+{minute},$+{hour},$+{day}, $m2,$+{year});
my $timestamp2 = $timestamp * 1000 + $+{mili};
print $fd "$timestamp2\n";
}
}
for my $key (keys %all_fd) {
my $fd = $all_fd{$key};
close $fd;
}