Created
January 17, 2022 09:25
-
-
Save yoku0825/8a1e2b43e80f8ce1b82f41507b28918e to your computer and use it in GitHub Desktop.
general_logをコネクションIDごとに別ファイルに分けるマン(2100年になると使えなくなる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use utf8; | |
my $file= "./general_query.log"; | |
open(my $fh, "<", $file) or die; | |
my @buff= (); | |
while (<$fh>) | |
{ | |
chomp; | |
if (/^2022-/) | |
{ | |
### Flush old buffer. | |
print_split(join(" ", @buff)); | |
@buff= (); | |
### Stack new buffer. | |
push(@buff, $_); | |
} | |
else | |
{ | |
push(@buff, $_); | |
} | |
} | |
### Flush last one buffer. | |
print_split(join(" ", @buff)); | |
sub print_split | |
{ | |
my ($new_line)= @_; | |
$new_line =~ /^(?<time>20-[\S]+)\s+(?<id>\d+)\s+(?<query>.+)/; | |
open(my $fh, ">>", sprintf("pid/%d.log", $+{id})); | |
print $fh $new_line, "\n"; | |
close($fh); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
たぶん5.6とそれ以前だと「時分秒まで同じだとタイムスタンプは省略される」に引っかかってまともに動かないと思う