Created
June 25, 2015 14:36
-
-
Save icarofreire/e62547afa769fbfa3079 to your computer and use it in GitHub Desktop.
Classe para criar um arquivo de log no sistema.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Classe para criar um arquivo de log do sistema. | |
* para debugar o programa ou deixar um logger no sistema. | |
* | |
* Ex: log::w( <variavel ou array> ); | |
* */ | |
class log | |
{ | |
/* definição do nome do arquivo de log que será criado. */ | |
private static $ARQUIVO = CAMINHO_ARQ_LOG."Logx"; | |
/* Se for um array, concatena os dados com uma quebra de linha. '\n' */ | |
private function log_array($array){ | |
if(is_array($array)){ | |
$str = ""; | |
foreach($array as $i){ | |
$str .= $i."\n"; | |
} | |
return substr($str,0,-1);// remove o ultimo '\n'; | |
}else{ return $array; } | |
} | |
/* metodo utilizado para escrever no arquivo de log. | |
* w( <qualquer variavel> ) ou w( <array> ) */ | |
public static function w($texto) | |
{ | |
date_default_timezone_set('America/Sao_Paulo'); | |
$fd = fopen(self::$ARQUIVO, "a"); | |
$str = "[".date("d/m/Y")." ".date("H:i:s")."]: " . self::log_array($texto); | |
fwrite($fd, $str . "\n"); | |
fclose($fd); | |
} | |
}// fim class | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment