oneuptime/php-sdk
2021-07-02 07:26:23 +01:00
..
src/Fyipe typo fix 2021-03-24 10:50:05 +01:00
tests php logger test fixed 2021-07-02 07:26:23 +01:00
.gitignore
composer.json faker adjusted 2021-03-09 11:48:00 +01:00
composer.lock faker adjusted 2021-03-09 11:48:00 +01:00
phpunit.xml
README.md updated readme with fixes 2021-03-24 00:24:27 +01:00

Fyipe SDK

A fyipe sdk for application logger that can be used to send logs about your applications created on your fypie dashboard which can also used for error tracking

Installation

Composer Install

Via Composer

$ composer require fyipe/log-php

Basic Usage for Logging

use Fyipe\FyipeLogger;

// constructor
$logger = new FyipeLogger(
    'API_URL', // https://fyipe.com/api
    'APPLICATION_LOG_ID',
    'APPLICATION_LOG_KEY'
);


// Sending a string log to the server
$item = 'This is a simple log';

$response = $logger->log($item);
// response after logging a request
var_dump($response);


// Sending an object log to the server
$item = new stdClass();
$item->user = 'Test User';
$item->page = 'Landing Page';

$response = $logger->log($item);
// response after logging a request
var_dump($response);

// alternatively, tags can be added to the logged item.
$item = 'This is a simple log';
// using a tag string
$tag = 'server-side-error';
$response = $logger->log($item, $tag);
// response after logging a request
var_dump($response);

// Using an array of strings
$tags = ['error', 'server'];
$response = $logger->log($item, $tags);
// response after logging a request
var_dump($response);

Basic Usage for Tracking

use Fyipe\FyipeTracker;

// set up tracking configurations, this is entirely optional
$option = new stdClass();
$option->maxTimeline = 5; // determine the maximum number of items allowed as timeline elements
$option->captureCodeSnippet = true; // determine if you want the library to scan your code base for the error code snippet
// constructor
$tracker = new FyipeTracker(
    'API_URL', // https://fyipe.com/api
    'ERROR_TRACKER_ID',
    'ERROR_TRACKER_KEY',
    $option // optional
);

// capturing a timeline manually
$timelineContent = new stdClass();
$timelineContent->account = 'debit';
$timelineContent->amount = '6000.00';
$timelineContent->userId = 471;
$tracker->addToTimeline('payment', $timelineContent, 'info');

// setting custom tags
$tracker->setTag('category', 'QA Tester'); // a single tag

// multiple tags
$tags = [];

// create two tags
$tagOne = new stdClass();
$tagOne->key = 'type';
$tagOne->value = 'notification';
$tagTwo = new stdClass();
$tagTwo->key = 'location';
$tagTwo->value = 'Oslo';

// add the two items to the array
array_push($tags, $tagOne, $tagTwo);

// setting the array of tags
$tracker->setTags($tags);

// capturing errors in a try and catch
try {
    // some code that might fail
} catch(Exception $e) {
    $tracker->captureException($e); // this is sent to your fyipe dashboard
}

// capturing errors using the message signature
$tracker->captureMessage('some error text');

// capturing errors authomatically

NonExistingMethod(); // calling this will trigger an error and its sent to your fyipe dashboard

API Documentation

Main API to send logs to the server.

Author: HackerBay, Inc.

new FyipeLogger($apiUrl, $applicationId, $applicationKey)

Create a constructor from the class, which will be used to send logs to the server.

Kind: Constructor Returns: null

Param Type Description
$apiUrl string The Server URL.
$applicationId string The Application Log ID.
$applicationKey string The Application Log Key.

$logger->log($log, $tags)

Logs a request of type info to the server.

Kind: method of new Fyipe\FyipeLogger Returns: Object - An object response of a success or failure.

Param Type Description
$log string | Object The content to the logged on the server.
$tags string | Array The tag(s) to be attached to the logged item on the server.

$logger->warning($warning, $tags)

Logs a request of type warning to the server.

Kind: method of new Fyipe\FyipeLogger Returns: Object - An object response of a success or failure.

Param Type Description
$warning string | Object The content to the logged on the server.
$tags string | Array The tag(s) to be attached to the logged item on the server.

$logger->error($error, $tags)

Logs a request of type error to the server.

Kind: method of new Fyipe\FyipeLogger Returns: Object - An object response of a success or failure.

Param Type Description
$error string | Object The content to the logged on the server.
$tags string | Array The tag(s) to be attached to the logged item on the server.

new FyipeTracker($apiUrl, $errorTrackerId, $errorTrackerKey, $option)

Create a constructor from the class, which will be used to track errors sent to the server.

Kind: Constructor Returns: null

Param Type Description
$apiUrl string The Server URL.
$errorTrackerId string The Error Tracker ID.
$errorTrackerKey string The Error Trakcer Key.
$option object The options to be considred by the tracker.

$options

Param Type Description
$maxTimeline int The total amount of timeline that should be captured, defaults to 5
$captureCodeSnippet boolean When set as true stack traces are automatically attached to all error sent to your fyipe dashboard.

$tracker->setTag($key, $value)

Set tag for the error to be sent to the server.

Kind: method of new Fyipe\FyipeTracker Returns: null

Param Type Description
$key string The key for the tag.
$value string The value for the tag.

$tracker->setTags([$key, $value])

Set multiple tags for the error to be sent to the server. Takes in an array

Kind: method of new Fyipe\FyipeTracker Returns: null

Param Type Description
$key string The key for the tag.
$value string The value for the tag.

$tracker->setFingerprint($fingerprint)

Set fingerprint for the next error to be captured.

Kind: method of new Fyipe\FyipeTracker Returns: null

Param Type Description
$fingerprint string | array of strings The set of string used to group error messages on the server.

$tracker->addToTimeline($category, $content, $type)

Add a custom timeline element to the next error to be sent to the server

Kind: method of new Fyipe\FyipeTracker Returns: null

Param Type Description
$category string The category of the timeline event.
$content string | Object The content of the timeline event.
$type string The type of timeline event.

$tracker->captureMessage($message)

Capture a custom error message to be sent to the server

Kind: method of new Fyipe\FyipeTracker Returns: Promise

Param Type Description
$message string The message to be sent to the server.

$tracker->captureException($error)

Capture a custom error object to be sent to the server

Kind: method of new Fyipe\FyipeTracker Returns: Promise

Param Type Description
$error object The Error Object to be sent to the server.

Contribution

  • Clone repository
  • run composer install to install dependencies
  • run composer test to run tests