# Logging

MadelineProto provides a unified class for logging messages to the logging destination defined in settings.

Use the settings to modify the default logging destination and log verbosity:

# $settings['logger']

Logger settings

# $settings['logger']['logger']

Default: \danog\MadelineProto\Logger::ECHO_LOGGER if running from CLI, \danog\MadelineProto\Logger::FILE_LOGGER if running from browser
Description: logger mode, available logger modes:

# $settings['logger']['param']

Default: __DIR__.'/Madeline.log'
Description: optional logger parameter, for modes that require it

# $settings['logger']['logger_level']

Default: \danog\MadelineProto\Logger::VERBOSE
Description: What logger messages to show

# Example:

use danog\MadelineProto\Logger;

$settings = [
    'logger' => [
        'logger_level' => Logger::VERBOSE,
        //'logger' => Logger::ECHO_LOGGER // Can be omitted to use default values
    ]
];
$MadelineProto = new \danog\MadelineProto\API('session.madeline', $settings);

Note: when running from web, MadelineProto will also automatically enable logging of PHP errors (not MadelineProto logs) to MadelineProto.log, located in the same directory as the script that loaded MadelineProto.

# Usage:

$MadelineProto->logger($message, $level);

$message is a string, an integer, an array, or any json-encodable object.
$level (optional) is one of the following constants:

By default, $level is \danog\MadelineProto\Logger::NOTICE.

# Error reporting

MadelineProto now can report errors automatically to the bot admin.
Simply use the following method:

// $message = (string) $exception, for example
$MadelineProto->report($message);

This will automatically report the error (and send the logfile!) to the bot admin, set using the setReportPeers method:

$MadelineProto->setReportPeers(['danogentili']);

OR using the getReportPeers method of the event handler.


    /**
     * Get peer(s) where to report errors
     *
     * @return int|string|array
     */
    public function getReportPeers()
    {
        return [self::ADMIN];
    }

If you use the startAndLoop method to start update handling, all errors surfacing from the loop will be reported automatically.

Next section

This site uses cookies, as described in the cookie policy. By clicking on "Accept" you consent to the use of cookies.