Monolog

Monolog is a PHP logging library used to manage and handle log messages generated by applications. It provides a flexible and structured way to record log data, such as errors, warnings, and informational messages, from different parts of an application. Monolog supports various log handlers, allowing logs to be written to different destinations, such as files, databases, email, or external services like cloud platforms. It also supports log levels, enabling developers to categorize log entries based on their severity. Monolog is widely used in PHP-based projects to ensure that applications can track and troubleshoot issues efficiently, making it easier for developers to monitor performance, identify problems, and maintain application stability.

Installation

This package can be installed via composer.

composer require seven.io/monolog

Usage

use Seven\Monolog\Config;
use Seven\Monolog\Handler;
use Monolog\Logger;

$logger = Logger('demo');
$apiKey = getenv('SEVEN_API_KEY'); // seven API key required for sending

// SMS
$cfg = [
    Config::KEY_API_KEY => $apiKey,
    Config::KEY_FLASH => 0, // 0 or 1
    Config::KEY_FOREIGN_ID => 'MyForeignID', // optional foreign ID max 64 chars consisting of a-zA-Z0-9, ._@
    Config::KEY_FROM => 'Monolog', // optional sender - max 11 alphanumeric or 16 numeric characters
    Config::KEY_LABEL => 'MyLabel', // optional label max 100 chars consisting of a-zA-Z0-9, ._@
    Config::KEY_TO => '+491234567890', // recipient(s) separated by comma
];
$handler = Handler::buildFromArray($cfg);
$logger
    ->pushHandler($handler)
    ->addCritical('critical bug');

// text-to-speech call
$cfg = [
    Config::KEY_API_KEY => $apiKey,
    Config::KEY_APP => Config::APP_VOICE,
    Config::KEY_FROM => '+4901234567890', // optional sender - must be verified or a shared inbound number
    Config::KEY_TO => '+491234567890', // recipient(s) separated by comma
];
$handler = Handler::buildFromArray($cfg);
$logger
    ->pushHandler($handler)
    ->addCritical('critical bug');
Last updated: 5 days ago