小时代5-perl如何运用logwrapper的方法
有时候我们经常需要记录一下程序运行过程中的所以日志,包括错误日志和输入输出日志。在下面的这个例子中,logWrapper子函数就实现了这样的功能,记录了程序的所有输入输出和执行时间,下面就通过这个例子看一下这个程序是如何执行的。 #!/usr/bin/perl use warnings; use strict; no strict "refs"; sub testLogToStd{ print "Test stdout : n"; open LOG,"> 2.txt"; select LOG; print "just a testn"; #recover STDOUT select STDOUT; print "just a test2n"; close LOG; } sub testFun{ print "From testFunn"; print STDERR "From TestFun Errorn"; } sub testFun2{ my $arg1 = shift; my $arg2 = shift; print "From testFun2n"; print $arg1."n"; print $arg2."n"; } my $log_root = "log" if(! $3 ||$3 == ""); my $ret = system("mkdir $log_root") if(! -e $log_root); my $report_log = "$log_root/report.log"; open my $REPORTLOG,">",$report_log or die "cannot not open log file report.logn"; sub logWrapper{ my $log_root = shift; my $REPORTLOG = shift; my $fun = shift; my @parameters = @_; *old_stdout = *STDOUT; *old_stderr = *STDERR; open LOG, ">","$log_root/$fun.log" or die "annot open log file $fun.n"; *STDOUT = *LOG; *STDERR = *LOG; my $start = time; my $ret = &$fun(@parameters); my $end = time; *STDOUT = *old_stdout; *STDERR = *old_stderr; close LOG; my $duration = $end - $start; print $REPORTLOG "$funn"; print $REPORTLOG "start:".localtime($start)."n"; print $REPORTLOG "end:".localtime($end)."n"; print $REPORTLOG "duration:".formatTimeDuration($duration)."n"; print $REPORTLOG "result:$retn"; print $REPORTLOG "n"; print $REPORTLOG "n"; } sub formatTimeDuration($){ my $t = shift; my $hrs = int($t/3600); my $mins = int($t%3600/60); my $secs = int($t%3600%60); return "$hrs:$mins:$secs"; } &logWrapper($log_root,$REPORTLOG,"testFun"); &logWrapper($log_root,$REPORTLOG,"testFun2","arg1","arg2"); print "thanksn"; 若需要调用外部命令,则需要如下: #!/usr/bin/perl use strict; use warnings; # run external commands # redirect stdout and stderr sub run_cmd{ my $cmd = shift; my $pid = open(PH, "$cmd 2>&1 |"); while (<PH>) {print $_; } } open(FH, ">", "perl-test.log"); *old_stdout = *STDOUT; *old_stderr = *STDERR; *STDOUT = *FH; *STDERR = *FH; my $ret = undef; $ret = readpipe("cp a b "); $ret = system("cp a b"); $ret = `cp a b`; run_cmd("cp a b"); print "AA"; print STDERR "BB"; *STDOUT = *old_stdout; *STDERR = *old_stderr;
www.urukw.com/gbdfyldl www.urukw.com/gbdfkhbl www.urukw.com/gbdfylkh www.urukw.com/gbylgbdf www.urukw.com/gggbdfylc www.urukw.com/gbdfsjzmdl www.urukw.com/gbdfylfl www.urukw.com/gbdfzmnyq www.urukw.com/gbdfyj www.urukw.com/gbdfxmf www.urukw.com/szdmdgbdf www.urukw.com/mdgbdf www.urukw.com/gbdfdhkh www.urukw.com/gbdfdlkh www.urukw.com/gbdfwtkh www.urukw.com/gbdfkh1581260 www.urukw.com/gbdfylhbwz www.urukw.com/gbdfyq www.urukw.com/sygbdfyl www.urukw.com/gbdfylzmyq www.urukw.com/gbdfylyflm www.urukw.com/gbdfylcznl www.urukw.com/gbdfwz www.urukw.com/gbdftz www.urukw.com/gbdfdh www.urukw.com/gbdfsj www.urukw.com/gggbdf www.urukw.com/gbdfgfw www.urukw.com/gbdfkhw www.urukw.com/gbdfsh www.urukw.com/gbdfsjxz www.urukw.com/gbdfylsjxz www.urukw.com/gbdfwfm www.urukw.com/gbdfdtkh www.urukw.com/gbdfhy www.urukw.com/gbdfrhkh www.urukw.com/gbdfzdl www.urukw.com/gbdfw www.urukw.com/gbdfdtkmdl www.urukw.com/gbdfglw www.urukw.com/gbdfxjw www.urukw.com/gbdfwtkhzx www.urukw.com/gbdfwtdhkh www.urukw.com/gbdfwkh www.urukw.com/gbdfwthykh www.urukw.com/gbdftgy www.urukw.com/gbdfylwz www.urukw.com/gbdfzmzc www.urukw.com/gbdfbjl www.urukw.com/gbdfylyq www.urukw.com/mdgbdfrqrh www.urukw.com/gbdfmdyjm www.urukw.com/mdgbdfaqm www.urukw.com/gbdfkmdl www.urukw.com/gbdfxwz www.urukw.com/gbdfwtzx www.urukw.com/gbdfdms www.urukw.com/gbdfzc www.urukw.com/gbdfsy www.urukw.com/gbdfwzx www.urukw.com/gbdfnyqb www.urukw.com/gbdfzj www.urukw.com/gbdfdz www.jcukg.com/gbdf www.jcukg.com/gbdfkh www.jcukg.com/gbdfylw www.jcukg.com/gbdfyl www.jcukg.com/gbdfhykh www.jcukg.com/1659988_comgbdf www.jcukg.com/gbdfdhtz www.jcukg.com/gbdfylpt www.jcukg.com/gbdfshy www.jcukg.com/gbdfzxkh www.jcukg.com/gbdfgw www.jcukg.com/gbdfwt www.jcukg.com/gbdfylc www.jcukg.com/gbdfdl www.jcukg.com/gbdfxc www.jcukg.com/gbdfyldl www.jcukg.com/gbdfkhbl www.jcukg.com/gbdfylkh www.jcukg.com/gbylgbdf www.jcukg.com/gggbdfylc www.jcukg.com/gbdfsjzmdl www.jcukg.com/gbdfylfl www.jcukg.com/gbdfzmnyq www.jcukg.com/gbdfyj www.jcukg.com/gbdfxmf www.jcukg.com/szdmdgbdf www.jcukg.com/mdgbdf www.jcukg.com/gbdfdhkh www.jcukg.com/gbdfdlkh www.jcukg.com/gbdfwtkh www.jcukg.com/gbdfkh1581260 www.jcukg.com/gbdfylhbwz www.jcukg.com/gbdfyq www.jcukg.com/sygbdfyl www.jcukg.com/gbdfylzmyq www.jcukg.com/gbdfylyflm www.jcukg.com/gbdfylcznl www.jcukg.com/gbdfwz www.jcukg.com/gbdftz www.jcukg.com/gbdfdh www.jcukg.com/gbdfsj www.jcukg.com/gggbdf www.jcukg.com/gbdfgfw www.jcukg.com/gbdfkhw www.jcukg.com/gbdfsh www.jcukg.com/gbdfsjxz www.jcukg.com/gbdfylsjxz www.jcukg.com/gbdfwfm www.jcukg.com/gbdfdtkh www.jcukg.com/gbdfhy www.jcukg.com/gbdfrhkh www.jcukg.com/gbdfzdl www.jcukg.com/gbdfw www.jcukg.com/gbdfdtkmdl www.jcukg.com/gbdfglw www.jcukg.com/gbdfxjw www.jcukg.com/gbdfwtkhzx www.jcukg.com/gbdfwtdhkh www.jcukg.com/gbdfwkh www.jcukg.com/gbdfwthykh www.jcukg.com/gbdftgy www.jcukg.com/gbdfylwz www.jcukg.com/gbdfzmzc www.jcukg.com/gbdfbjl www.jcukg.com/gbdfylyq www.jcukg.com/mdgbdfrqrh www.jcukg.com/gbdfmdyjm www.jcukg.com/mdgbdfaqm www.jcukg.com/gbdfkmdl www.jcukg.com/gbdfxwz www.jcukg.com/gbdfwtzx www.jcukg.com/gbdfdms www.jcukg.com/gbdfzc www.jcukg.com/gbdfsy www.jcukg.com/gbdfwzx www.jcukg.com/gbdfnyqb www.jcukg.com/gbdfzj www.jcukg.com/gbdfdz www.yrikt.com/gbdf www.yrikt.com/gbdfkh www.yrikt.com/gbdfylw www.yrikt.com/gbdfyl www.yrikt.com/gbdfhykh www.yrikt.com/1659988_comgbdf www.yrikt.com/gbdfdhtz www.yrikt.com/gbdfylpt www.yrikt.com/gbdfshy www.yrikt.com/gbdfzxkh www.yrikt.com/gbdfgw www.yrikt.com/gbdfwt www.yrikt.com/gbdfylc www.yrikt.com/gbdfdl www.yrikt.com/gbdfxc www.yrikt.com/gbdfyldl www.yrikt.com/gbdfkhbl www.yrikt.com/gbdfylkh www.yrikt.com/gbylgbdf www.yrikt.com/gggbdfylc www.yrikt.com/gbdfsjzmdl www.yrikt.com/gbdfylfl www.yrikt.com/gbdfzmnyq www.yrikt.com/gbdfyj www.yrikt.com/gbdfxmf www.yrikt.com/szdmdgbdf www.yrikt.com/mdgbdf www.yrikt.com/gbdfdhkh www.yrikt.com/gbdfdlkh www.yrikt.com/gbdfwtkh www.yrikt.com/gbdfkh1581260 www.yrikt.com/gbdfylhbwz www.yrikt.com/gbdfyq www.yrikt.com/sygbdfyl www.yrikt.com/gbdfylzmyq www.yrikt.com/gbdfylyflm www.yrikt.com/gbdfylcznl www.yrikt.com/gbdfwz www.yrikt.com/gbdftz www.yrikt.com/gbdfdh www.yrikt.com/gbdfsj www.yrikt.com/gggbdf www.yrikt.com/gbdfgfw www.yrikt.com/gbdfkhw www.yrikt.com/gbdfsh www.yrikt.com/gbdfsjxz www.yrikt.com/gbdfylsjxz www.yrikt.com/gbdfwfm www.yrikt.com/gbdfdtkh www.yrikt.com/gbdfhy www.yrikt.com/gbdfrhkh www.yrikt.com/gbdfzdl www.yrikt.com/gbdfw www.yrikt.com/gbdfdtkmdl www.yrikt.com/gbdfglw www.yrikt.com/gbdfxjw www.yrikt.com/gbdfwtkhzx www.yrikt.com/gbdfwtdhkh www.yrikt.com/gbdfwkh www.yrikt.com/gbdfwthykh www.yrikt.com/gbdftgy www.yrikt.com/gbdfylwz www.yrikt.com/gbdfzmzc www.yrikt.com/gbdfbjl www.yrikt.com/gbdfylyq www.yrikt.com/mdgbdfrqrh www.yrikt.com/gbdfmdyjm www.yrikt.com/mdgbdfaqm www.yrikt.com/gbdfkmdl www.yrikt.com/gbdfxwz www.yrikt.com/gbdfwtzx www.yrikt.com/gbdfdms www.yrikt.com/gbdfzc www.yrikt.com/gbdfsy www.yrikt.com/gbdfwzx www.yrikt.com/gbdfnyqb www.yrikt.com/gbdfzj www.yrikt.com/gbdfdz www.bwjvy.com/gbdf www.bwjvy.com/gbdfkh www.bwjvy.com/gbdfylw www.bwjvy.com/gbdfyl www.bwjvy.com/gbdfhykh www.bwjvy.com/1659988_comgbdf www.bwjvy.com/gbdfdhtz www.bwjvy.com/gbdfylpt www.bwjvy.com/gbdfshy www.bwjvy.com/gbdfzxkh www.bwjvy.com/gbdfgw www.bwjvy.com/gbdfwt www.bwjvy.com/gbdfylc www.bwjvy.com/gbdfdl www.bwjvy.com/gbdfxc www.bwjvy.com/gbdfyldl www.bwjvy.com/gbdfkhbl www.bwjvy.com/gbdfylkh www.bwjvy.com/gbylgbdf www.bwjvy.com/gggbdfylc www.bwjvy.com/gbdfsjzmdl www.bwjvy.com/gbdfylfl www.bwjvy.com/gbdfzmnyq www.bwjvy.com/gbdfyj www.bwjvy.com/gbdfxmf www.bwjvy.com/szdmdgbdf www.bwjvy.com/mdgbdf www.bwjvy.com/gbdfdhkh www.bwjvy.com/gbdfdlkh www.bwjvy.com/gbdfwtkh www.bwjvy.com/gbdfkh1581260 www.bwjvy.com/gbdfylhbwz www.bwjvy.com/gbdfyq www.bwjvy.com/sygbdfyl www.bwjvy.com/gbdfylzmyq www.bwjvy.com/gbdfylyflm www.bwjvy.com/gbdfylcznl www.bwjvy.com/gbdfwz www.bwjvy.com/gbdftz www.bwjvy.com/gbdfdh www.bwjvy.com/gbdfsj www.bwjvy.com/gggbdf www.bwjvy.com/gbdfgfw www.bwjvy.com/gbdfkhw www.bwjvy.com/gbdfsh www.bwjvy.com/gbdfsjxz www.bwjvy.com/gbdfylsjxz www.bwjvy.com/gbdfwfm www.bwjvy.com/gbdfdtkh www.bwjvy.com/gbdfhy www.bwjvy.com/gbdfrhkh www.bwjvy.com/gbdfzdl www.bwjvy.com/gbdfw www.bwjvy.com/gbdfdtkmdl www.bwjvy.com/gbdfglw www.bwjvy.com/gbdfxjw www.bwjvy.com/gbdfwtkhzx www.bwjvy.com/gbdfwtdhkh www.bwjvy.com/gbdfwkh www.bwjvy.com/gbdfwthykh www.bwjvy.com/gbdftgy www.bwjvy.com/gbdfylwz www.bwjvy.com/gbdfzmzc www.bwjvy.com/gbdfbjl www.bwjvy.com/gbdfylyq www.bwjvy.com/mdgbdfrqrh www.bwjvy.com/gbdfmdyjm www.bwjvy.com/mdgbdfaqm www.bwjvy.com/gbdfkmdl www.bwjvy.com/gbdfxwz www.bwjvy.com/gbdfwtzx www.bwjvy.com/gbdfdms www.bwjvy.com/gbdfzc www.bwjvy.com/gbdfsy www.bwjvy.com/gbdfwzx www.bwjvy.com/gbdfnyqb www.bwjvy.com/gbdfzj www.bwjvy.com/gbdfdz www.vrtyo.com/gbdf www.vrtyo.com/gbdfkh www.vrtyo.com/gbdfylw www.vrtyo.com/gbdfyl www.vrtyo.com/gbdfhykh www.vrtyo.com/1659988_comgbdf www.vrtyo.com/gbdfdhtz www.vrtyo.com/gbdfylpt www.vrtyo.com/gbdfshy www.vrtyo.com/gbdfzxkh www.vrtyo.com/gbdfgw www.vrtyo.com/gbdfwt www.vrtyo.com/gbdfylc www.vrtyo.com/gbdfdl www.vrtyo.com/gbdfxc www.vrtyo.com/gbdfyldl www.vrtyo.com/gbdfkhbl www.vrtyo.com/gbdfylkh www.vrtyo.com/gbylgbdf www.vrtyo.com/gggbdfylc www.vrtyo.com/gbdfsjzmdl www.vrtyo.com/gbdfylfl www.vrtyo.com/gbdfzmnyq www.vrtyo.com/gbdfyj www.vrtyo.com/gbdfxmf www.vrtyo.com/szdmdgbdf www.vrtyo.com/mdgbdf www.vrtyo.com/gbdfdhkh www.vrtyo.com/gbdfdlkh www.vrtyo.com/gbdfwtkh www.vrtyo.com/gbdfkh1581260 www.vrtyo.com/gbdfylhbwz www.vrtyo.com/gbdfyq www.vrtyo.com/sygbdfyl www.vrtyo.com/gbdfylzmyq www.vrtyo.com/gbdfylyflm www.vrtyo.com/gbdfylcznl www.vrtyo.com/gbdfwz www.vrtyo.com/gbdftz www.vrtyo.com/gbdfdh www.vrtyo.com/gbdfsj www.vrtyo.com/gggbdf www.vrtyo.com/gbdfgfw www.vrtyo.com/gbdfkhw www.vrtyo.com/gbdfsh www.vrtyo.com/gbdfsjxz www.vrtyo.com/gbdfylsjxz www.vrtyo.com/gbdfwfm www.vrtyo.com/gbdfdtkh www.vrtyo.com/gbdfhy www.vrtyo.com/gbdfrhkh www.vrtyo.com/gbdfzdl www.vrtyo.com/gbdfw www.vrtyo.com/gbdfdtkmdl www.vrtyo.com/gbdfglw www.vrtyo.com/gbdfxjw www.vrtyo.com/gbdfwtkhzx www.vrtyo.com/gbdfwtdhkh www.vrtyo.com/gbdfwkh www.vrtyo.com/gbdfwthykh www.vrtyo.com/gbdftgy www.vrtyo.com/gbdfylwz www.vrtyo.com/gbdfzmzc www.vrtyo.com/gbdfbjl www.vrtyo.com/gbdfylyq www.vrtyo.com/mdgbdfrqrh www.vrtyo.com/gbdfmdyjm www.vrtyo.com/mdgbdfaqm www.vrtyo.com/gbdfkmdl www.vrtyo.com/gbdfxwz www.vrtyo.com/gbdfwtzx www.vrtyo.com/gbdfdms www.vrtyo.com/gbdfzc www.vrtyo.com/gbdfsy www.vrtyo.com/gbdfwzx www.vrtyo.com/gbdfnyqb www.vrtyo.com/gbdfzj www.vrtyo.com/gbdfdz www.jltwy.com/gbdf www.jltwy.com/gbdfkh www.jltwy.com/gbdfylw www.jltwy.com/gbdfyl www.jltwy.com/gbdfhykh www.jltwy.com/1659988_comgbdf www.jltwy.com/gbdfdhtz www.jltwy.com/gbdfshy www.jltwy.com/gbdfzxkh www.jltwy.com/gbdfgw www.jltwy.com/gbdfwt www.jltwy.com/gbdfylc www.jltwy.com/gbdfdl www.jltwy.com/gbdfxc www.jltwy.com/gbdfyldl www.jltwy.com/gbdfkhbl www.jltwy.com/gbdfylkh www.jltwy.com/gbylgbdf www.jltwy.com/gggbdfylc www.jltwy.com/gbdfsjzmdl www.jltwy.com/gbdfzmnyq www.jltwy.com/gbdfyj www.jltwy.com/gbdfxmf www.jltwy.com/szdmdgbdf www.jltwy.com/mdgbdf www.jltwy.com/gbdfwtkh www.jltwy.com/gbdfkh1581260 www.jltwy.com/gbdfylhbwz www.jltwy.com/gbdfyq www.jltwy.com/sygbdfyl www.jltwy.com/gbdfylzmyq www.jltwy.com/gbdfylyflm www.jltwy.com/gbdfylcznl www.jltwy.com/gbdfwz www.jltwy.com/gbdftz www.jltwy.com/gbdfdh www.jltwy.com/gbdfsj www.jltwy.com/gggbdf www.jltwy.com/gbdfgfw www.jltwy.com/gbdfkhw www.jltwy.com/gbdfsh www.jltwy.com/gbdfsjxz www.jltwy.com/gbdfylsjxz www.jltwy.com/gbdfwfm www.jltwy.com/gbdfdtkh www.jltwy.com/gbdfhy www.jltwy.com/gbdfrhkh www.jltwy.com/gbdfzdl www.jltwy.com/gbdfw www.jltwy.com/gbdfdtkmdl www.jltwy.com/gbdfglw www.jltwy.com/gbdfxjw www.jltwy.com/gbdfwtkhzx www.jltwy.com/gbdfwtdhkh www.jltwy.com/gbdfwkh www.jltwy.com/gbdfwthykh www.jltwy.com/gbdftgy www.jltwy.com/gbdfbjl www.jltwy.com/gbdfylyq www.jltwy.com/mdgbdfrqrh www.jltwy.com/gbdfmdyjm www.jltwy.com/mdgbdfaqm www.jltwy.com/gbdfkmdl www.jltwy.com/gbdfxwz www.jltwy.com/gbdfwtzx www.jltwy.com/gbdfdms www.jltwy.com/gbdfzc www.jltwy.com/gbdfsy www.jltwy.com/gbdfwzx www.jltwy.com/gbdfnyqb www.jltwy.com/gbdfzj www.jltwy.com/gbdfdz www.mvxjd.com/gbdf www.mvxjd.com/gbdfkh www.mvxjd.com/gbdfylw www.mvxjd.com/gbdfyl www.mvxjd.com/gbdfhykh www.mvxjd.com/1659988_comgbdf www.mvxjd.com/gbdfdhtz www.mvxjd.com/gbdfylpt www.mvxjd.com/gbdfshy www.mvxjd.com/gbdfzxkh www.mvxjd.com/gbdfgw www.mvxjd.com/gbdfwt www.mvxjd.com/gbdfylc www.mvxjd.com/gbdfdl www.mvxjd.com/gbdfxc www.mvxjd.com/gbdfyldl www.mvxjd.com/gbdfkhbl www.mvxjd.com/gbdfylkh www.mvxjd.com/gbylgbdf www.mvxjd.com/gggbdfylc www.mvxjd.com/gbdfsjzmdl www.mvxjd.com/gbdfylfl www.mvxjd.com/gbdfzmnyq www.mvxjd.com/gbdfyj www.mvxjd.com/gbdfxmf www.mvxjd.com/szdmdgbdf www.mvxjd.com/mdgbdf www.mvxjd.com/gbdfdhkh www.mvxjd.com/gbdfdlkh www.mvxjd.com/gbdfwtkh www.mvxjd.com/gbdfkh1581260 www.mvxjd.com/gbdfylhbwz www.mvxjd.com/gbdfyq www.mvxjd.com/sygbdfyl www.mvxjd.com/gbdfylzmyq www.mvxjd.com/gbdfylyflm www.mvxjd.com/gbdfylcznl www.mvxjd.com/gbdfwz www.mvxjd.com/gbdftz www.mvxjd.com/gbdfdh www.mvxjd.com/gbdfsj www.mvxjd.com/gggbdf www.mvxjd.com/gbdfgfw www.mvxjd.com/gbdfkhw www.mvxjd.com/gbdfsh