paragonie/monolog-quill

Chronicle实例写入的Monolog处理器

v0.3.0 2024-05-08 17:17 UTC

This package is auto-updated.

Last update: 2024-09-08 18:10:57 UTC


README

Build Status Latest Stable Version Latest Unstable Version License Downloads

需要PHP 7.1或更高版本。

想要使用Monolog将安全事件写入Chronicle吗?

此库使用Quill将日志消息转录到Chronicle实例。这可以是公开或私有的Chronicle。

安装

composer require paragonie/monolog-quill

使用方法

<?php

use Monolog\Logger;
use ParagonIE\MonologQuill\QuillHandler;
use ParagonIE\Quill\Quill;
use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\Sapient\CryptographyKeys\{
    SigningSecretKey,
    SigningPublicKey
};

// Create a Quill for writing data to the Chronicle instance 
$quill = (new Quill())
    ->setChronicleURL('https://chronicle-public-test.paragonie.com/chronicle')
    ->setServerPublicKey(
        new SigningPublicKey(
            Base64UrlSafe::decode('3BK4hOYTWJbLV5QdqS-DFKEYOMKd-G5M9BvfbqG1ICI=')
        )
    )
    ->setClientID('**Your Client ID provided by the Chronicle here**')
    ->setClientSecretKey(
        new SigningSecretKey('/* Loaded from the filesystem or something. */')
    );

// Push the Handler to Monolog
$log = new Logger('security');
$handler = (new QuillHandler($quill, Logger::ALERT));
$log->pushHandler($handler);

// Now security events will be logged in your Chronicle
$log->alert(
    'User bob logged in at ' .
    ((new DateTime())->format(\DateTime::ATOM))
);

加密消息记录

只需通过setEncryptionKey()方法将SealingPublicKeySharedEncryptionKey实例传递给处理器,即可加密日志消息。

$handler->setEncryptionKey(
    new SealingPublicKey('/* Loaded from the filesystem or something. */')
);

加密消息记录 - 完整示例

<?php

use Monolog\Logger;
use ParagonIE\MonologQuill\QuillHandler;
use ParagonIE\Quill\Quill;
use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\Sapient\CryptographyKeys\{
    SealingPublicKey,
    SigningSecretKey,
    SigningPublicKey
};

// Create a Quill for writing data to the Chronicle instance 
$quill = (new Quill())
    ->setChronicleURL('https://chronicle-public-test.paragonie.com/chronicle')
    ->setServerPublicKey(
        new SigningPublicKey(
            Base64UrlSafe::decode('3BK4hOYTWJbLV5QdqS-DFKEYOMKd-G5M9BvfbqG1ICI=')
        )
    )
    ->setClientID('**Your Client ID provided by the Chronicle here**')
    ->setClientSecretKey(
        new SigningSecretKey('/* Loaded from the filesystem or something. */')
    );

// Push the Handler to Monolog
$log = new Logger('security');
$handler = (new QuillHandler($quill, Logger::ALERT));

// Set this to an instance of SealingPublicKey or SharedEncryptionKey:
$handler->setEncryptionKey(
    new SealingPublicKey('/* Loaded from the filesystem or something. */')
);

$log->pushHandler($handler);

// Now security events will be logged in your Chronicle
$log->alert(
    'User bob logged in at ' .
    ((new DateTime())->format(\DateTime::ATOM))
);