public function log($message, $type = "MESSAGE", $text_attributes = [])
    {

        $type = strtoupper($type);

        switch ($type) {

            case 'RAW':
                break;

            case 'ERROR':
                $this->number_of_errors++;
                $this->onError($message);
            default:
                $message = $type . ': ' . $message;
        }
        
        $this->logToFile($message);
        
        if(empty($text_attributes)){
            file_put_contents("php://stdout", "\n".$message);
            return $message;
        }
        
        if(is_array($text_attributes)){
            if(isset($text_attributes['bold']) && $text_attributes['bold']){
                file_put_contents("php://stdout", "\033[1m");
            }

            if(isset($text_attributes['underline']) && $text_attributes['underline']){
                file_put_contents("php://stdout","\033[4m");
            }

            if(isset($text_attributes['fgcolor']) && isset($this->fgcolors[$text_attributes['fgcolor']])){
                file_put_contents("php://stdout", "\033[".$this->fgcolors[$text_attributes['fgcolor']]."m");
            }

            if(isset($text_attributes['bgcolor']) && isset($this->fgcolors[$text_attributes['bgcolor']])){
               file_put_contents("php://stdout", "\033[".$this->bgcolors[$bgcolor]."m");
            }

            if(isset($text_attributes['underline']) && $text_attributes['underline']){
                file_put_contents("php://stdout","\033[4m");
            }

            if(isset($text_attributes['overwrite']) && $text_attributes['overwrite']){
                file_put_contents("php://stdout", "\033[2K\033[A");
            }
        } else if(is_string($text_attributes) && isset($this->fgcolors[$text_attributes])){
            file_put_contents("php://stdout", "\033[".$this->fgcolors[$text_attributes]."m");
        }
        

        file_put_contents("php://stdout", "\n".$message);

        if(!is_array($text_attributes) || !isset($text_attributes['keep']) || !$text_attributes['keep']){
            file_put_contents("php://stdout","\033[0m");
        }

        return $message;
    }