User Tools


<?php
 
class Logger
{
    private $loglimit = 0;
    // some nice colors for 256 color terminals:
    private $colors = array(197,199,203,172,114,202,129,94,205,112,194,46);
    private $counter = 0;
 
    public function __construct($loglimit)
    {
        $this->loglimit = $loglimit;
    }
 
    // print colored debug information
    public function message($section='_',$loglevel=0,$message,$color=null)
    {
        if($loglevel <= $this->loglimit)
        {
            $color = current(array_filter(array($color,$this->colors[$loglevel%count($this->colors)])));
            printf("\x1b[33m%s%d%'-8d\x1b[0m\t%s\x1b[38;5;%dm%s\x1b[0m\n",$section,$loglevel,
                ++$this->counter,str_repeat('   ',$loglevel),$color,$message);
        }
    }
 
    // highlight a string (by inverting colors)
    public function highlight($s)
    {
        return "\x1b[7m".$s."\x1b[27m";
    }
 
    // underline a string
    public function underline($s)
    {
        return "\x1b[4m".$s."\x1b[24m";
    }
}
 
?>

CL Wiki

Institute of Computational Linguistics – University of Zurich