jrobinsonc
7/7/2016 - 2:35 AM

debugging tools

debugging tools

<?php
/** 
 * Using Slack
 * https://slack.com/
 */
 
define('SLACK_ENDPOINT', 'https://hooks.slack.com/services/asdfasdfasd...');

function slack_log($log)
{
    $opts = [
        'http' => [
            'method'  => 'POST',
            'header'  => 'Content-type: application/json',
            'content' => json_encode($log)
        ]
    ];

    $result = file_get_contents(SLACK_ENDPOINT, false, stream_context_create($opts));
}
<?php
/* 
 * Using Papertrail
 * https://papertrailapp.com/
 *
 * @see http://help.papertrailapp.com/
 */
 
define('PAPERTRAIL_ENDPOINT', 'logs0.papertrailapp.com:12345');

function papertrail_log($log, $component = 'staging', $program = 'MyMagicApp') 
{
    $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    
    $endpoint = parse_url(PAPERTRAIL_ENDPOINT);
    
    foreach(explode("\n", $log) as $line) {
        $log_message = "<22>" . date('M d H:i:s ') . $program . ' ' . $component . ': ' . $line;
        socket_sendto($sock, $log_message, strlen($log_message), 0, $endpoint['host'], $endpoint['port']);
    }
    
    socket_close($sock);
}
<?php
/** 
 * Using Loggly
 * https://www.loggly.com/
 */
 
define('LOGGLY_ENDPOINT', 'http://logs-00.loggly.com/inputs/s59tg6b3-sd59-85de-d5d4-f5s96ty36caa');

function loggly_log($tag, $log)
{
    $opts = [
        'http' => [
            'method'  => 'POST',
            'header'  => implode("\r\n", [
                'Content-type: application/json'
            ]),
            'content' => json_encode($log)
        ]
    ];

    return file_get_contents(sprintf(LOGGLY_ENDPOINT . '/tag/%s/', $tag), false, stream_context_create($opts));
}