[BACK]Return to log.pm CVS log [TXT][DIR] Up to [local] / wpscripts / ztransfer

Annotation of wpscripts/ztransfer/log.pm, Revision 1.6

1.1       yason       1: #!/usr/bin/perl
1.6     ! yason       2: # $Id: log.pm,v 1.5 2011/12/21 10:19:26 yason Exp $
1.1       yason       3: package log;
                      4:
                      5: my $DEBUG = 1;
                      6:
1.2       yason       7: my $MAIN_LOG = "/var/log/wpscripts/ztransfer/main.log";
                      8: my $ERROR_LOG = "/var/log/wpscripts/ztransfer/error.log";
                      9: my $ZAYAVKI_LOG = "/var/log/wpscripts/ztransfer/zayavki.log";
1.6     ! yason      10: my $ZJPEGS_LOG = "/var/log/wpscripts/ztransfer/z_jpegs.log";
        !            11: my $PJPEGS_LOG = "/var/log/wpscripts/ztransfer/p_jpegs.log";
1.2       yason      12: my $PROBAS_LOG = "/var/log/wpscripts/ztransfer/probas.log";
1.4       yason      13: my $TT_LOG = "/var/log/wpscripts/ztransfer/tt.log";
1.2       yason      14: my $CRITICAL_LOG = "/var/log/wpscripts/ztransfer/critical.log";
                     15: my $FILE_LIST = "/var/log/wpscripts/ztransfer/FILES";
                     16: my $DIFFS_FILE = "/var/log/wpscripts/ztransfer/size_diffs.log";
                     17: my $CURRENT_FILE = "/var/log/wpscripts/ztransfer/FILE";
                     18: my $CURRENT_ACTION = "/var/log/wpscripts/ztransfer/ACTION";
1.1       yason      19:
                     20:
                     21: # functions
                     22: sub error($)
                     23: {
                     24:     open(FILE, ">>$ERROR_LOG") or return();
                     25:     $_ = shift();
                     26:     print FILE scalar( localtime() ) . "| $_\n";
                     27:     print STDOUT scalar( localtime() ) . "| $_\n" if($DEBUG);
                     28:     close(FILE);
                     29: }
                     30:
                     31:
                     32: sub main($)
                     33: {
                     34:     open(FILE, ">>$MAIN_LOG") or return();
                     35:     $_ = shift();
                     36:     print FILE scalar( localtime() ) . "| $_\n";
                     37:     print STDOUT scalar( localtime() ) . "| $_\n" if($DEBUG);
                     38:     close(FILE);
                     39: }
                     40:
                     41:
                     42: sub zayavki($)
                     43: {
                     44:     open(FILE, ">>$ZAYAVKI_LOG") or return();
                     45:     $_ = shift();
                     46:     print FILE scalar( localtime() ) . "| $_\n";
                     47:     print STDOUT scalar( localtime() ) . "| $_\n" if($DEBUG);
                     48:     close(FILE);
                     49: }
                     50:
                     51:
                     52: sub probas($)
                     53: {
                     54:     open(FILE, ">>$PROBAS_LOG") or return();
1.4       yason      55:     $_ = shift();
                     56:     print FILE scalar( localtime() ) . "| $_\n";
                     57:     print STDOUT scalar( localtime() ) . "| $_\n" if($DEBUG);
                     58:     close(FILE);
                     59: }
                     60:
                     61: sub tt($)
                     62: {
                     63:     open(FILE, ">>$TT_LOG") or return();
1.1       yason      64:     $_ = shift();
                     65:     print FILE scalar( localtime() ) . "| $_\n";
                     66:     print STDOUT scalar( localtime() ) . "| $_\n" if($DEBUG);
                     67:     close(FILE);
                     68: }
                     69:
1.6     ! yason      70:  sub zjpeg($)
1.5       yason      71:  {
1.6     ! yason      72:      open(FILE, ">>$ZJPEGS_LOG") or return();
1.5       yason      73:      $_ = shift();
                     74:      print FILE scalar( localtime() ) . "| $_\n";
                     75:      print STDOUT scalar( localtime() ) . "| $_\n" if($DEBUG);
                     76:      close(FILE);
1.6     ! yason      77:  }
        !            78:
        !            79:  sub pjpeg($)
        !            80:  {
        !            81:      open(FILE, ">>$PJPEGS_LOG") or return();
        !            82:      $_ = shift();
        !            83:      print FILE scalar( localtime() ) . "| $_\n";
        !            84:      print STDOUT scalar( localtime() ) . "| $_\n" if($DEBUG);
        !            85:      close(FILE);
1.5       yason      86:  }
1.1       yason      87:
                     88: sub critical($)
                     89: {
                     90:     if( open(FILE, ">>$CRITICAL_LOG") )
                     91:     {
                     92:        $_ = shift();
                     93:        print FILE scalar( localtime() ) . "| $_\n";
                     94:        close(FILE);
                     95:        print STDOUT scalar( localtime() ) . "| $_\n" if($DEBUG);
                     96:     }
                     97:     exit(-1);  # exit program with -1 on *critical* error
                     98: }
                     99:
                    100:
                    101: sub filelist($)
                    102: {
                    103:     my $files_ref = shift;
                    104:     my @files = @$files_ref;
                    105:
                    106:     open(FILE, ">$FILE_LIST") or return();
                    107:     foreach  $_ (@files)
                    108:     {
                    109:        print FILE "$_\n";
                    110:     }
                    111:     close(FILE);
                    112: }
                    113:
                    114:
                    115: sub diff($$$)
                    116: {
                    117:     my $path = shift;
                    118:     my $size_orig = shift;
                    119:     my $size_arc = shift;
                    120:     my $diff = $size_orig / $size_arc;
                    121:
                    122:     # in human-readable format
                    123:     # we don't suppose gigabyte archives
                    124:     $size_orig = ($size_orig > 1048576 ? int($size_orig / 1024 / 1024) . " MB" : int($size_orig / 1024) . " KB");
                    125:     $size_arc = ($size_arc > 1048576 ? int($size_arc / 1024 / 1024) . " MB" : int($size_arc / 1024) . " KB");
                    126:
                    127:     open(FILE, ">>$DIFFS_FILE") or return();
                    128:     print FILE scalar( localtime() ) . "| $path - original=$size_orig, compressed=$size_arc [diff=$diff]\n";
                    129:     print STDOUT scalar( localtime() ) . "| $path - original=$size_orig, compressed=$size_arc [diff=$diff]\n" if($DEBUG);
                    130:     close(FILE);
                    131:
                    132: }
                    133:
                    134:
                    135: sub file_work_on($$)
                    136: {
                    137:     my $file = shift;
                    138:     my $action = shift;
                    139:
                    140:     open(FILE, ">$CURRENT_FILE") or return();
                    141:        print FILE $file;
                    142:     close(FILE);
                    143:
                    144:     open(ACT, ">$CURRENT_ACTION") or return();
                    145:        print ACT $action;
                    146:     close(ACT);
                    147:
                    148: }
                    149:
                    150:
                    151: sub file_work_done()
                    152: {
                    153:     # consider this stuff okay, as usually ;-)
                    154:     #  but in future maybe not to call anything external?
                    155:     system("/bin/rm $CURRENT_FILE") if(-e $CURRENT_FILE);
                    156:     system("/bin/rm $CURRENT_ACTION") if(-e $CURRENT_ACTION);
                    157: }
                    158:
                    159:
                    160: sub stdout($)
                    161: {
                    162:     my $message = shift;
                    163:     print "STDOUT: $message\n";
                    164: }
                    165:
                    166:
                    167: return(1);

CVSweb