Skip to content

wlog

wlog.php

function wlog($t) {
    $filename = './wlog.log';
    $file = fopen( $filename, "a+" );
    if ( $file )
    {
        fputs ( $file, date("Y-m-d H:i:s").' '.$t."\n");
    }
    fclose ($file);
}

function wlogdump($i) {
    ob_start();
    print_r($i);
    $p = ob_get_contents();
    ob_end_clean();
    wlog($p);
}

function wlog_id()
{
   $length=4;
   $chars="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   $clen   = strlen( $chars )-1;
   $id  = '';

   for ($i = 0; $i < $length; $i++) {
       $id .= $chars[mt_rand(0,$clen)];
   }
   return ($id);
}
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
ini_set('error_reporting', E_ALL);

require_once('/wlog.php');
$wlogid = wlog_id();

wlog(__FILE__.' CODE '.$wlogid.' start');
wlog(__FILE__.' CODE '.$wlogid.' AAA');
wlog(__FILE__.' CODE '.$wlogid.' end');

wlog(__FILE__.' EVENT 1111');
wlog(__CLASS__.'->'.__FUNCTION__.' OK');
wlog(__CLASS__.'->'.__FUNCTION__.' ERROR');

Clearing

# 1 remove require_once('./wlog.php');

# 2. find
grep 'wlog(' -r . --include=*.php

# 3-A delete lines with wlog function
find . -type f -name '*.php' -exec grep -l 'wlog(' {} \; | xargs sed -i '/wlog/d'

# 3-B comment wlog function in files
find . -type f -name '*.php' -exec grep -l 'wlog(' {} \; | xargs sed -i 's|wlog(|#wlog(|g'

# 4 remove log files
find . -name wlog.log | xargs rm -f 
rm -f wlog.php