Skip to content

Instantly share code, notes, and snippets.

@IgorDePaula
Last active May 7, 2018 17:26
Show Gist options
  • Select an option

  • Save IgorDePaula/27d2c9faa1ecd964e411ab754a62ec96 to your computer and use it in GitHub Desktop.

Select an option

Save IgorDePaula/27d2c9faa1ecd964e411ab754a62ec96 to your computer and use it in GitHub Desktop.
<?php
require 'vendor/autoload.php';
use Telegram\Bot\Api;
error_reporting(E_ALL ^ E_NOTICE);
function getError() {
$ip = '';
if($_SERVER['REMOTE_ADDR']){
// $ip = ", usando o ip {$_SERVER['REMOTE_ADDR']}";
}
$env = getenv('SITE') ? getenv('SITE') : 'DEV';
$hora = date('H');
switch ($hora) {
case $hora < 12:
$saudacao = 'Bom dia, ';
break;
case $hora < 18:
$saudacao = 'Boa tarde, ';
break;
case $hora >= 18:
$saudacao = 'Boa noite, ';
break;
default:
$saudacao = "Desculpe, perdi a noção de tempo. ";
break;
}
$referer = '';
if(isset($_SERVER['HTTP_REFERER'])){
$referer .= ", com a referencia {$_SERVER['HTTP_REFERER']}";
}
$data = date('d/m/Y - H:i:s');
$err = error_get_last();
$erro = print_r($err, true);
$str = "{$saudacao} [{$env}] Hoje às {$data} aconteceu um erro na linha {$err['line']}, no arquivo {$err['file']} com a mensagem: {$err['message']} {$referer} {$ip}";
if (!is_null($err)) {
$telegram = new Api(TOKEN_BOT);
$message = $telegram->sendMessage([
'chat_id' => '-1001058090092',
'text' => $str
]);
}
}
function exception_handler($e) {
$ip = '';
error_log($e->getMessage());
$env = getenv('SITE') ? getenv('SITE') : 'DEV';
$hora = date('H');
switch ($hora) {
case $hora < 12:
$saudacao = 'Bom dia, ';
break;
case $hora < 18:
$saudacao = 'Boa tarde, ';
break;
case $hora >= 18:
$saudacao = 'Boa noite, ';
break;
default:
$saudacao = "Desculpe, perdi a noção de tempo. ";
break;
}
$data = date('d/m/Y - H:i:s');
$referer = '';
if(isset($_SERVER['HTTP_REFERER'])){
$referer .= ", com a referencia {$_SERVER['HTTP_REFERER']}";
}
$str = "{$saudacao} [{$env}] Hoje às {$data} aconteceu um erro na linha {$e->getLine()}, no arquivo {$e->getFile()} com a mensagem: {$e->getMessage()} {$referer} {$ip}";
if (!is_null($e)) {
$telegram = new Api(TOKEN_BOT);
$message = $telegram->sendMessage([
'chat_id' => '-1001058090092',
'text' => $str
]);
}
}
set_exception_handler('exception_handler');
register_shutdown_function('getError');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment