Giter Club home page Giter Club logo

logger's Introduction

Utopia Logger

Build Status Total Downloads Discord

Utopia Logger library is simple and lite library for logging information, such as errors or warnings. This library aims to be as simple and easy to learn and use as possible. This library is maintained by the Appwrite team.

Although the library was built for the Utopia Framework project, it is completely independent, dependency-free and can be used with any other PHP project or framework.

Getting Started

Install using composer:

composer require utopia-php/logger
<?php

require_once '../vendor/autoload.php';

use Utopia\Logger\Adapter\AppSignal;
use Utopia\Logger\Adapter\Raygun;
use Utopia\Logger\Adapter\Sentry;
use Utopia\Logger\Adapter\LogOwl;
use Utopia\Logger\Log;
use Utopia\Logger\Log\Breadcrumb;
use Utopia\Logger\Log\User;
use Utopia\Logger\Logger;

// Prepare log
$log = new Log();
$log->setAction("controller.database.deleteDocument");
$log->setEnvironment("production");
$log->setNamespace("api");
$log->setServer("digitalocean-us-001");
$log->setType(Log::TYPE_WARNING);
$log->setVersion("0.11.5");
$log->setMessage("Document efgh5678 not found");
$log->setUser(new User("efgh5678"));
$log->addBreadcrumb(new Breadcrumb(Log::TYPE_DEBUG, "http", "DELETE /api/v1/database/abcd1234/efgh5678", \microtime(true) - 500));
$log->addBreadcrumb(new Breadcrumb(Log::TYPE_DEBUG, "auth", "Using API key", \microtime(true) - 400));
$log->addBreadcrumb(new Breadcrumb(Log::TYPE_INFO, "auth", "Authenticated with * Using API Key", \microtime(true) - 350));
$log->addBreadcrumb(new Breadcrumb(Log::TYPE_INFO, "database", "Found collection abcd1234", \microtime(true) - 300));
$log->addBreadcrumb(new Breadcrumb(Log::TYPE_DEBUG, "database", "Permission for collection abcd1234 met", \microtime(true) - 200));
$log->addBreadcrumb(new Breadcrumb(Log::TYPE_ERROR, "database", "Missing document when searching by ID!", \microtime(true)));
$log->addTag('sdk', 'Flutter');
$log->addTag('sdkVersion', '0.0.1');
$log->addTag('authMode', 'default');
$log->addTag('authMethod', 'cookie');
$log->addTag('authProvider', 'MagicLink');
$log->addExtra('urgent', false);
$log->addExtra('isExpected', true);

// Sentry
$adapter = new Sentry("[YOUR_SENTRY_KEY]"), "[YOUR_SENTRY_PROJECT_ID]");
$logger = new Logger($adapter);
$logger->addLog($log);

// AppSignal
$adapter = new AppSignal("[YOUR_APPSIGNAL_KEY]");
$logger = new Logger($adapter);
$logger->addLog($log);

// Raygun
$adapter = new Raygun("[YOUR_RAYGUN_KEY]");
$logger = new Logger($adapter);
$logger->addLog($log);

// Log Owl
$adapter = new LogOwl("[YOUR_SERVICE_TICKET]");
$logger = new Logger($adapter);
$logger->addLog($log);

Adapters

Below is a list of supported adapters, and thier compatibly tested versions alongside a list of supported features and relevant limits.

Adapter Status
Sentry
AppSignal
Raygun
Log Owl

✅ - supported, 🛠 - work in progress

Tests

To run all unit tests, use the following Docker command:

docker run --rm -e TEST_RAYGUN_KEY=KKKK -e TEST_APPSIGNAL_KEY=XXXX -e TEST_SENTRY_KEY=YYYY -e TEST_SENTRY_PROJECT_ID=ZZZZ -v $(pwd):$(pwd):rw -w $(pwd) php:8.0-cli-alpine sh -c "vendor/bin/phpunit --configuration phpunit.xml tests"

Make sure to replace TEST_SENTRY_KEY and TEST_SENTRY_PROJECT_ID environment variables value with actual keys from Sentry. If your Sentry DSN is https://[email protected]/anything, then TEST_SENTRY_KEY=something and TEST_SENTRY_PROJECT_ID=anything. Optionally TEST_SENTRY_HOST can be added to specify a self-hosted Sentry instance.

Make sure to replace TEST_APPSIGNAL_KEY with key found in Appsignal -> Project -> App Settings -> Push & deploy -> Push Key

Make sure to replace TEST_RAYGUN_KEY with key found in Raygun -> Project -> Application Settings -> Api Key

To run static code analysis, use the following Psalm command:

docker run --rm -v $(pwd):$(pwd):rw -w $(pwd) php:8.0-cli-alpine sh -c "vendor/bin/psalm --show-info=true"

System Requirements

Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.

Copyright and license

The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php

logger's People

Contributors

christyjacob4 avatar eldadfux avatar lohanidamodar avatar maximilianmaihoefner avatar meldiron avatar pineappleionic avatar samarth2812 avatar vermakhushboo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.