Microsoft Azure - php

Asked

Viewed 52 times

2

How to make Microsoft Azure capture my errors?

inserir a descrição da imagem aqui

I am currently dealing with errors with this function:

<?php


/**
  Plugin Name: TESTE
  Description: testando log novo
  Version: 1.0
  Author: Vteste
  Author URI: teste

  -------
  LICENSE: This file is subject to the terms and conditions defined in
  file 'license.txt', which is part of Advanced Access Manager source package.
 *
 */

// error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
    switch ($errno) {
    case E_USER_ERROR:
        $erro = "<b>My ERROR</b> [$errno] $errstr<br />\n";
        $erro += "  Fatal error on line $errline in file $errfile";
        $erro += ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
        $erro += "Aborting...<br />\n";
        echo $erro;
        exit(1);
        break;

    case E_USER_WARNING:
        $erro = "<b>My WARNING</b> [$errno] $errstr\n";
        break;

    case E_USER_NOTICE:
        $erro = "<b>My NOTICE</b> [$errno] $errstr\n";
        break;

    default:
        $erro = "Unknown error type: [$errno] $errstr, linha:$errline, no arquivo $errfile";
            error_log($erro);
        break;
    }

    /* Don't execute PHP internal error handler */
    return true;
}

// function to test the error handling
function scale_by_log($vect, $scale)
{
    if (!is_numeric($scale) || $scale <= 0) {
        trigger_error("log(x) for x <= 0 is undefined, you used: scale = $scale", E_USER_ERROR);
    }

    if (!is_array($vect)) {
        trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING);
        return null;
    }

    $temp = array();
    foreach($vect as $pos => $value) {
        if (!is_numeric($value)) {
            trigger_error("Value at position $pos is not a number, using 0 (zero)", E_USER_NOTICE);
            $value = 0;
        }
        $temp[$pos] = log($scale) * $value;
    }

    return $temp;
}

// set to the user defined error handler
$old_error_handler = set_error_handler("myErrorHandler");


?>

And I use the plugin Application Insights | Microsoft Azure, however it is not collecting any kind of error, so would like to send manually as could do?

1 answer

2


I’m not sure, but I believe it’s due to:

return true;

Within your Handler in the set_error_handler has the return true;, this makes instead of using the internal Handler it use only your "Handler", so internal PHP LOG can never catch the error, because you are preventing.

To try to resolve remove the return true;, a detail to own Microsoft provides an API to use Application Insights, if you’re using composer can install like this:

require: "microsoft/application-insights": "*"

Note that you must be using PHP 5.4.2+

After installing create a key and add this code with your key:

$telemetryClient = new \ApplicationInsights\Telemetry_Client();
$telemetryClient->getContext()->setInstrumentationKey('DIGITE SUA CHAVE AQUI');
$telemetryClient->trackEvent('name of your event');
$telemetryClient->flush();
  • Works with Multisite ??

  • @Kauealves multi-domains or multi-sites?

  • wordpress multisites

  • @Kauealves can not say, if the multi-site are different wordpress applications I believe you will have to configure one by one, if it is the same application with multiple domains maybe it is not necessary.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.