Login   Register  
PHP Classes
elePHPant
Icontem

File: class.log.phtml

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ricardo Costa  >  MySQL Connection  >  class.log.phtml  >  Download  
File: class.log.phtml
Role: Class source
Content type: text/plain
Description: Use in MySQL Connection Class
Class: MySQL Connection
Manage and Log a connection with MySQL Server
Author: By
Last change: Set to local path
Date: 11 years ago
Size: 2,864 bytes
 

Contents

Class file image Download
<?php
//
// Por Ricardo Costa - ricardo.community@globo.com - 2002
// Classe para insercao e exibicao do log
//
//  log
//    +---- log( Nome do arquivo de log ) // Inicializa o log passando o nome do arquivo
//    +---- addLog( String para insercao, Tipo de mensagem [error, sucess] )  //  Adicionar uma linha ao arquivo de Log
//    +---- show() //  Exibir a o conteudo do log
//
//

class log
{
   var 
$filename// Caminho e nome do arquivo de log



   # Inicializa o log passando o nome do arquivo ############################################# Revisão 02/09/2002 #
   
function log($filename NULL) {

      if (!
$GLOBALS["nyear"]) 
         
$this->filename date("Y.m.d").".log";
      else    
         
$this->filename $GLOBALS["nyear"].".".mformat(2$GLOBALS["nmonth"]).".".mformat(2$GLOBALS["nday"]).".log";
   }
   
# Inicializa o log passando o nome do arquivo ############################################# Revisão 02/09/2002 #




   # Adicionar uma linha ao arquivo de Log ################################################### Revisão 02/09/2002 #
   
function addLog($text$type) {

      
$log_file = @fopen($this->filename"a+");
      if (
$log_file) {
         
$log fread($log_filefilesize($log_file));
         
$content $log;
         
$ini strlen($GLOBALS["REQUEST_URI"]) - 40;
         
$content .= "<span class=\"$type\"> - ".
                       
date("d.m.Y ..... H:m:s")." ..... ".
                       
str_pad(substr($GLOBALS["REMOTE_ADDR"]." "015), 20"."STR_PAD_RIGHT)." ".
                       
str_pad($GLOBALS["user_name"], 25"."STR_PAD_RIGHT).
                       
str_pad(substr($GLOBALS["PHP_SELF"], strrpos($GLOBALS["PHP_SELF"], "/"), strlen($GLOBALS["PHP_SELF"])), 30"."STR_PAD_RIGHT).
                        
$text</span><br>\n";
         
fputs($log_file$content);
         
fclose($log_file);
      }
   }
   
# Adicionar uma linha ao arquivo de Log ################################################### Revisão 02/09/2002 #




   # Exibir a o conteudo do log ############################################################## Revisão 02/09/2002 #
   
function show() {

      if (
$log_file = @fopen($this->filename"r")) {

         while (!
feof ($log_file)) {
            
$buffer fgets($log_file4096);
            if (
strpos($buffer$GLOBALS["nday"].".".mformat(2$GLOBALS["nmonth"]).".".$GLOBALS["nyear"]) > 1) {
               
$buffer str_replace("\\\"""\""$buffer);
               print(
$buffer);
               
flush();
            }
         }

         
fclose ($log_file);
      }
      else
          print(
"Erro ao tentar abriar o log \"$this->filename\"");
   }
   
# Exibir a o conteudo do log ############################################################## Revisão 02/09/2002 #



# Final da Classe
?>