Changeset 75

Show
Ignore:
Timestamp:
01.12.2006 03:32:23 (2 years ago)
Author:
jorge
Message:

Logging to file/stderr now behaves as described in FuzzyOcr?.cf

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/devel/FuzzyOcr.pm

    r74 r75  
    7070    if ($conf->{focr_global_timeout}) { 
    7171        my $t = get_timeout(); 
    72         debuglog("Global Timeout set at ".$conf->{focr_timeout}." sec.",2); 
     72        debuglog("Global Timeout set at ".$conf->{focr_timeout}." sec."); 
    7373        $t->run(sub { 
    7474            $end = fuzzyocr_do( $self, $conf, $pms ); 
     
    121121    my $main     = $self->{main}; 
    122122 
    123     debuglog("Starting FuzzyOcr...",2); 
     123    debuglog("Starting FuzzyOcr..."); 
    124124    foreach my $p ( 
    125125        $pms->{msg}->find_parts(qr(^image\b)i), 
     
    181181            $imgfiles{$imgfilename}{ftype} = 1;  
    182182            ($w,$h) = unpack("vv",substr($pdata,6,4)); 
    183             debuglog("GIF: [${h}x${w}] $imgfilename"); 
     183            infolog("GIF: [${h}x${w}] $imgfilename"); 
    184184            $imgfiles{$imgfilename}{width}  = $w; 
    185185            $imgfiles{$imgfilename}{height} = $h; 
     
    208208            } else { 
    209209                ($h,$w) = unpack("nn",substr($pdata,$pos+3,4)); 
    210                 debuglog("JPEG: [${h}x${w}] $imgfilename"); 
     210                infolog("JPEG: [${h}x${w}] $imgfilename"); 
    211211                $imgfiles{$imgfilename}{ftype} = 2; 
    212212                $imgfiles{$imgfilename}{height} = $h; 
     
    219219            $imgfiles{$imgfilename}{width}  = $w; 
    220220            $imgfiles{$imgfilename}{height} = $h; 
    221             debuglog("PNG: [${h}x${w}] $imgfilename"); 
     221            infolog("PNG: [${h}x${w}] $imgfilename"); 
    222222        } elsif ( substr($pdata,0,2) eq "BM" ) { 
    223223            ## BMP File 
     
    226226            $imgfiles{$imgfilename}{width}  = $w; 
    227227            $imgfiles{$imgfilename}{height} = $h; 
    228             debuglog("BMP: [${h}x${w}] $imgfilename"); 
     228            infolog("BMP: [${h}x${w}] $imgfilename"); 
    229229        } elsif ( 
    230230            (substr($pdata,0,4) eq "\x4d\x4d\x00\x2a") or 
     
    241241                last if ($h != 0 and $w != 0); 
    242242            } 
    243             debuglog("TIFF: [${h}x${w}] $imgfilename ($worder)"); 
    244             debuglog("Cannot determite size of TIFF image, setting to '1x1'") if ($h == 0 and $w == 0); 
     243            infolog("TIFF: [${h}x${w}] $imgfilename ($worder)"); 
     244            infolog("Cannot determite size of TIFF image, setting to '1x1'") if ($h == 0 and $w == 0); 
    245245            $imgfiles{$imgfilename}{ftype}  = 5; 
    246246            $imgfiles{$imgfilename}{width}  = $w ? $w : 1; 
     
    259259        print PICT $pdata; 
    260260        close PICT; 
    261         debuglog("Saved: $imgfilename"); 
     261        infolog("Saved: $imgfilename"); 
    262262        $cnt++; 
    263263    } 
     
    278278    # Try to load personal wordlist 
    279279    if ($conf->{focr_personal_wordlist} =~ m/^\//) { 
    280         infolog("Attempting to load personal wordlist..."); 
    281280        read_words( $conf->{focr_personal_wordlist} ); 
    282281    } else { 
     
    285284            read_words( $peruserlist ); 
    286285        } else { 
    287             errorlog("Cannot read personal_wordlist: $peruserlist, skipping..."); 
     286            # Only complain if the file exists 
     287            if ( -e $peruserlist ) { 
     288                errorlog("Cannot read personal_wordlist: $peruserlist, skipping..."); 
     289            } 
    288290        } 
    289291    } 
     
    658660            } 
    659661 
    660             debuglog("ocrdata=>>".join("",@result)."<<=end") if ($conf->{focr_verbose}>2)
     662            debuglog("ocrdata=>>".join("",@result)."<<=end")
    661663 
    662664            foreach my $ww (keys %words) { 
  • trunk/devel/FuzzyOcr/Config.pm

    r74 r75  
    33 
    44use lib qw(..); 
    5 use FuzzyOcr::Logging qw(debuglog errorlog infolog); 
     5use FuzzyOcr::Logging qw(debuglog infolog warnlog errorlog); 
    66use FuzzyOcr::Scanset; 
    77use FuzzyOcr::Preprocessor; 
     
    8383sub set_pid { 
    8484    $pid = shift; 
    85     debuglog("Saved pid: $pid",2); 
     85    debuglog("Saved pid: $pid"); 
    8686} 
    8787 
     
    439439    } 
    440440 
    441     infolog("Adding <".scalar(@cmds)."> new options"); 
    442441    $conf->{parser}->register_commands(\@cmds); 
    443442} 
     
    449448        my $main = $self->{main}; 
    450449        my $retcode; 
    451         info("FuzzyOcr: focr_end_config"); 
    452450 
    453451        # Parse preprocessor file 
     
    481479                }); 
    482480            } else { 
    483                 errorlog("$bin is already defined, skipping..."); 
     481                warnlog("$bin is already defined, skipping..."); 
    484482            } 
    485483        } 
     
    504502        my $b = "focr_bin_$a"; 
    505503        if (defined $conf->{$b} and ! -x $conf->{$b}) { 
    506             errorlog("cannot exec $a, removing..."); 
     504            infolog("cannot exec $a, removing..."); 
    507505            delete $conf->{$b}; 
    508506        }  
     
    512510            foreach my $p (@paths) { 
    513511                my $f = "$p/$a"; 
    514                 debuglog("Testing $f...",2); 
    515512                next unless -x $f; 
    516513                $conf->{$b} = $f; 
     
    520517                infolog("Using $a => $conf->{$b}"); 
    521518            } else { 
    522                 errorlog("Cannot find executable for $a"); 
     519                warnlog("Cannot find executable for $a"); 
    523520            } 
    524521        } 
     
    529526        next unless $k =~ m/^focr_/; 
    530527        next if $k =~ m/^focr_bin_/; 
    531         debuglog(" $k => ".$conf->{$k},2); 
     528        debuglog(" $k => ".$conf->{$k}); 
    532529    } 
    533530 
     
    561558        unless (HAS_DBI and HAS_DBD_MYSQL) { 
    562559            $conf->{focr_enable_image_hashing} = 0; 
    563             infolog("Disable Image Hashing"); 
     560            errorlog("Disable Image Hashing"); 
    564561            errorlog("Missing DBI") unless HAS_DBI; 
    565562            errorlog("Missing DBD::mysql") unless HAS_DBD_MYSQL; 
     
    569566        unless (HAS_MLDBM and HAS_DB_FILE and HAS_STORABLE) { 
    570567            $conf->{focr_enable_image_hashing} = 0; 
    571             infolog("Disable Image Hashing"); 
     568            errorlog("Disable Image Hashing"); 
    572569            errorlog("Missing MLDBM") unless HAS_MLDBM; 
    573570            errorlog("Missing DB_File") unless HAS_DB_FILE; 
     
    590587                    my $db = $DB{$k}; 
    591588                    if ($db->{check} < $now) { 
    592                         debuglog("Expire: <$k> Reason: $db->{check} < $now"); 
     589                        infolog("Expire: <$k> Reason: $db->{check} < $now"); 
    593590                        delete $DB{$k}; $hash++; 
    594591                    } 
     
    669666                        } 
    670667                        $sql .= ")"; 
    671                         debuglog($sql,2); 
     668                        debuglog($sql); 
    672669                        $ddb->do($sql); $err++; 
    673670                    } 
     
    704701                        } 
    705702                        $sql .= ")"; 
    706                         debuglog($sql,2); 
     703                        debuglog($sql); 
    707704                        $ddb->do($sql); $err++; 
    708705                    } 
     
    724721    my $tfile = $_[1] || 'Personal'; 
    725722    unless ( -r $wfile ) { 
    726         errorlog("Cannot read $tfile wordlist: \"$wfile\"\n Please check file path and permissions are correct."); 
     723        warnlog("Cannot read $tfile wordlist: \"$wfile\"\n Please check file path and permissions are correct."); 
    727724        return; 
    728725    } 
     
    752749    my ($file) = @_; 
    753750    unless (open(SFILE, "<$file")) { 
    754         errorlog("Failed to open scanset file \"$file\", aborting..."); 
     751        warnlog("Failed to open scanset file \"$file\", aborting..."); 
    755752        return 1; 
    756753    } 
     
    769766                next; 
    770767            } 
    771             debuglog("line $_",2); 
     768            debuglog("line $_"); 
    772769            if ($_ =~ /^(\s)*preprocessors(\s)*=(\s)*(.*)$/i) { 
    773770                my $prep = $4; 
     
    808805        # Start a new scanset 
    809806        } elsif ($_ =~ /^(\s)*scanset(\s)+(.+?)(\s)+\{$/i) { 
    810             debuglog("line $_",2); 
     807            debuglog("line $_"); 
    811808            if (grep $_ eq $3, @slabels) { 
    812809                errorlog("Label already used earlier in line $., aborting..."); 
     
    840837        # We are in the middle of a preprocessor 
    841838        if(defined $preprocessor) { 
    842             debuglog("line: $_",2); 
     839            debuglog("line: $_"); 
    843840            if ($_ =~ /^(\s)*(command|args)(\s)*=(\s)*(.*)$/i) { 
    844841                my $tag = $2; 
     
    866863        # Start a new preprocessor 
    867864        } elsif ($_ =~ /^(\s)*preprocessor(\s)+(.+?)(\s)+\{$/i) { 
    868             debuglog("line: $_",2); 
     865            debuglog("line: $_"); 
    869866            if (grep $_ eq $3, @plabels) { 
    870867                errorlog("Error, label already used earlier in line $., aborting..."); 
  • trunk/devel/FuzzyOcr/Deanimate.pm

    r70 r75  
    88use FuzzyOcr::Config qw(get_config set_config get_tmpdir); 
    99use FuzzyOcr::Misc qw(save_execute); 
    10 use FuzzyOcr::Logging qw(errorlog infolog); 
     10use FuzzyOcr::Logging qw(errorlog warnlog infolog); 
    1111 
    1212# Provide functions to deanimate gifs 
     
    4242            $tfile = $tfile3; 
    4343        } else { 
    44             errorlog("$conf->{'focr_bin_gifsicle'}: ". 
     44            warnlog("$conf->{'focr_bin_gifsicle'}: ". 
    4545                ($retcode<0) ? 'Timed out' : 'Error' 
    4646                ." [$retcode], image not reduced!"); 
     
    5353        ">>$efile"); 
    5454    return $tfile2 if ($retcode == 0); 
    55     infolog("$conf->{focr_bin_gifsicle}: cannot extract image#${index}"); 
     55    warnlog("$conf->{focr_bin_gifsicle}: cannot extract image#${index}"); 
    5656    return $tfile; 
    5757} 
     
    106106                                  }sx; 
    107107        if ($n != $frameno) { 
    108             errorlog ( "Trouble parsing 'gifsicle --info' output.\n" 
     108            warnlog ( "Trouble parsing 'gifsicle --info' output.\n" 
    109109                     . "  Expected 'image \#$frameno', found 'image \#$n', skipping..." ); 
    110110            $info{'error'}++; 
  • trunk/devel/FuzzyOcr/Hashing.pm

    r74 r75  
    1010use FuzzyOcr::Config qw(get_thresholds get_config set_config get_tmpdir get_mysql_ddb); 
    1111use FuzzyOcr::Misc qw(save_execute); 
    12 use FuzzyOcr::Logging qw(debuglog errorlog infolog); 
     12use FuzzyOcr::Logging qw(debuglog errorlog warnlog infolog); 
    1313use Fcntl; 
    1414use Fcntl ':flock'; 
     
    5959    my $conf = get_config(); 
    6060    if ($conf->{focr_enable_image_hashing} == 0) { 
    61         infolog("Image Hashing is disabled"); 
     61        warnlog("Image Hashing is disabled"); 
    6262        return (0,''); 
    6363    } 
     
    7676    if ($conf->{focr_enable_image_hashing} == 3) { 
    7777        unless (defined $conf->{focr_mysql_ddb}) { 
    78             infolog("Connection to MySQL server unavailable"); 
     78            warnlog("Connection to MySQL server unavailable"); 
    7979            return (0,''); 
    8080        } 
     
    145145        tie %DB, 'MLDBM', $dbfile, O_RDWR or $ret++; 
    146146        if ($ret>0) { 
    147             errorlog("No Image Hash database found at \"$dbfile\", or permissions wrong."); 
     147            warnlog("No Image Hash database found at \"$dbfile\", or permissions wrong."); 
    148148            return (0,''); 
    149149        } 
     
    194194        $ret = open HASH, $conf->{focr_digest_db}; 
    195195        unless($ret) { 
    196             errorlog("No Image Hash database found at \"$conf->{focr_digest_db}\", or permissions wrong."); 
     196            warnlog("No Image Hash database found at \"$conf->{focr_digest_db}\", or permissions wrong."); 
    197197            return (0,''); 
    198198        } 
     
    219219    if ($conf->{focr_enable_image_hashing} == 3) { 
    220220        unless (defined $conf->{focr_mysql_ddb}) { 
    221             infolog("Connection to MySQL server unavailable"); 
     221            warnlog("Connection to MySQL server unavailable"); 
    222222            return; 
    223223        } 
     
    276276        tie %DB, 'MLDBM', $dbfile or $ret++; 
    277277        if ($ret>0) { 
    278             errorlog("Unable to open/create Image Hash database at \"$dbfile\", check permissions."); 
     278            warnlog("Unable to open/create Image Hash database at \"$dbfile\", check permissions."); 
    279279            return; 
    280280        } 
     
    303303        } 
    304304        unless ($ret) { 
    305             errorlog("Unable to open/create Image Hash database at \"$conf->{focr_digest_db}\", check permissions."); 
     305            warnlog("Unable to open/create Image Hash database at \"$conf->{focr_digest_db}\", check permissions."); 
    306306            return; 
    307307        } 
     
    313313        close(DB); 
    314314    } 
    315     #debuglog("Digest: $digest"); 
     315    debuglog("Digest: $digest"); 
    316316} 
    317317 
     
    334334    unless (-r $pfile) { 
    335335        errorlog("Cannot read $pfile"); 
    336         return(1,''); 
     336        return(1, ''); 
    337337    } 
    338338 
    339339    my ($r, @stdout_data) = save_execute( 
    340         "$conf->{focr_bin_ppmhist} -noheader $pfile", 
    341         undef, 
     340        "$conf->{focr_bin_ppmhist} -noheader $pfile", undef, 
    342341        ">$imgdir/ppmhist.info", 
    343342        ">/dev/null", 1); 
     
    368367        } 
    369368    } 
    370     infolog("Got: <$hash>"); 
     369    debuglog("Got: <$hash>"); 
    371370    return(0, $hash); 
    372371} 
  • trunk/devel/FuzzyOcr/Logging.pm

    r70 r75  
    22 
    33use base 'Exporter'; 
    4 our @EXPORT_OK = qw(debuglog errorlog infolog logfile); 
     4our @EXPORT_OK = qw(debuglog errorlog infolog warnlog logfile); 
    55 
    66use Mail::SpamAssassin::Logger qw(log_message would_log); 
     
    3434     
    3535sub errorlog { 
     36    _log("error",$_[0]) if $conf->{focr_log_stderr}; 
    3637    my $conf = FuzzyOcr::Config::get_config(); 
    37     _log("error",$_[0]); 
    38     logfile($_[0]) if defined $conf->{focr_logfile}; 
     38    if (defined $conf->{focr_logfile}) { 
     39        logfile($_[0]); 
     40    } 
     41
     42 
     43sub warnlog { 
     44    my $conf = FuzzyOcr::Config::get_config(); 
     45    return if ($conf->{focr_verbose} < 1); 
     46    _log("warn",$_[0]) if $conf->{focr_log_stderr}; 
     47    if (defined $conf->{focr_logfile}) { 
     48        logfile($_[0]); 
     49    } 
    3950} 
    4051 
    4152sub infolog { 
    4253    my $conf = FuzzyOcr::Config::get_config(); 
    43     _log("info",$_[0]); 
    44     logfile($_[0]) if defined $conf->{focr_logfile}; 
     54    return if ($conf->{focr_verbose} < 2); 
     55    _log("info",$_[0]) if $conf->{focr_log_stderr}; 
     56    if (defined $conf->{focr_logfile}) { 
     57        logfile($_[0]); 
     58    } 
    4559} 
    4660 
    4761sub debuglog { 
    4862    my $conf = FuzzyOcr::Config::get_config(); 
    49     my $limit = defined $_[1] ? $_[1] : 1; 
    50     my $test  = defined $conf->{focr_verbose} ? $conf->{focr_verbose} : 10; 
    51     if ( $test > $limit ) { 
    52         _log("info",$_[0]) if $conf->{focr_log_stderr}; 
    53         logfile($_[0]) if defined $conf->{focr_logfile}; 
    54     } else { 
    55         _log("dbg",$_[0]) if (would_log('dbg')); 
     63    return if ($conf->{focr_verbose} < 3); 
     64    _log("dbg",$_[0]) if $conf->{focr_log_stderr}; 
     65    if (defined $conf->{focr_logfile}) { 
     66        logfile($_[0]); 
    5667    } 
    5768} 
  • trunk/devel/FuzzyOcr/Misc.pm

    r70 r75  
    77use lib qw(..); 
    88use FuzzyOcr::Config qw(set_pid unset_pid get_config get_timeout); 
    9 use FuzzyOcr::Logging qw(debuglog errorlog infolog); 
     9use FuzzyOcr::Logging qw(debuglog errorlog warnlog infolog); 
    1010use Time::HiRes qw( gettimeofday tv_interval ); 
    1111 
     
    3434        } 
    3535    } 
    36     infolog("Remove DIR: $dir"); 
     36    debuglog("Remove DIR: $dir"); 
    3737    unless(rmdir $dir) { 
    3838        errorlog("Cannot remove DIR: $dir"); 
     
    5555            return -1; 
    5656        } elsif (not $pid) { 
    57             debuglog("Exec  : $cmd",2); 
    58             debuglog("Stdin : $stdin",2)  if (defined $stdin); 
    59             debuglog("Stdout: $stdout",2) if (defined $stdout); 
    60             debuglog("Stderr: $stderr",2) if (defined $stderr); 
     57            debuglog("Exec  : $cmd"); 
     58            debuglog("Stdin : $stdin")  if (defined $stdin); 
     59            debuglog("Stdout: $stdout") if (defined $stdout); 
     60            debuglog("Stderr: $stderr") if (defined $stderr); 
    6161            if (defined $stdin) { 
    6262                open(STDIN, $stdin); 
     
    9494                return -1; 
    9595            } elsif (not $pid) { 
    96                 debuglog("Exec  : $cmd",2); 
    97                 debuglog("Stdin : $stdin",2) if (defined $stdin); 
    98                 debuglog("Stdout: $stdout",2) if (defouted $stdout); 
    99                 debuglog("Stderr: $stderr",2) if (deferred $stderr); 
     96                debuglog("Exec  : $cmd"); 
     97                debuglog("Stdin : $stdin") if (defined $stdin); 
     98                debuglog("Stdout: $stdout") if (defouted $stdout); 
     99                debuglog("Stderr: $stderr") if (deferred $stderr); 
    100100                if (defined $stdin) { 
    101101                    open(STDIN, $stdin);