Link Search Menu Expand Document


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

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


use danog\MadelineProto\Logger;
use danog\MadelineProto\Settings\Logger as LoggerSettings;

$settings = (new LoggerSettings)

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.


$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:

  • \danog\MadelineProto\Logger::FATAL_ERROR - Indicates a fatal error
  • \danog\MadelineProto\Logger::ERROR - Indicates a recoverable error
  • \danog\MadelineProto\Logger::NOTICE - Indicates an info message
  • \danog\MadelineProto\Logger::VERBOSE - Indicates a verbose info message
  • \danog\MadelineProto\Logger::ULTRA_VERBOSE - Indicates an ultra verbose

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

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


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.

If memory profiling with memprof is enabled, you can also use reportMemoryProfile() to send a pprof memory profile to all report peers.

Next section