programster/email-logger

一款通过电子邮件记录日志的记录器,且兼容PSR-3

1.0.0 2023-04-25 16:37 UTC

This package is auto-updated.

Last update: 2024-09-25 20:01:32 UTC


README

一个通过电子邮件发送日志的PHP PSR-3 记录器。

安装

composer require programster/email-logger

示例用法

# Create an emailer, in this case using PHPMailer.
# Any emailer that implements the EmailerInterface will work
$emailer = new Programster\Emailers\PhpMailerEmailer(
    "smtp.gmail.com",
    "someemail@gmail.com",
    "app-specific-password-goes-here",
    SecurityProtocol::TLS,
    "someemail@gmail.com",
    "Senders Name",
    587,
    "noreply@someemail.com",
    "noreply"
);

# Create the email logger
$logger = new EmailLogger(
    $emailer,
    "my-service-name-here",
    new EmailSubscriber("Jenn", "jenn@somdomain.com"),
    new EmailSubscriber("Roy", "roy@anotherdomain.com"),
);

# Create some useful context for the log that might help debugging/resolving what went wrong...
$context = [
    'some' => 'details'
];

# Send the log (email)
$logger->critical("There was a critical error!", $context);

测试

在开发此包时,请务必进行测试,即使它非常基础。目前,可以通过移除 settings.php.example 文件中的 .example 扩展名并进行填写来测试。然后执行 main.php 脚本,向在设置中指定的订阅者发送电子邮件。