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

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

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

CVSweb