tbaronnat/log-bundle

简单的日志捆绑系统,支持 Symfony 集成

安装: 18

依赖: 0

建议者: 0

安全性: 0

星标: 0

分支: 0

类型:symfony-bundle

v1.0.3 2024-03-13 13:09 UTC

This package is not auto-updated.

Last update: 2024-09-25 14:30:00 UTC


README

使用方法
  • 将 LoggableInterface 添加到您想要记录日志的每个实体中
  • 创建自己的 LogManager 实例,如果需要,则扩展此捆绑包中的 LogManager 或 AbstractLogManager 以添加更多数据到 LogObject,或者配置另一种方式来排除字段
  • 创建自己的 Log.php 实体,该实体扩展了 AbstractLog 并实现了 LogInterface
  • 为您自己的实体创建一个关联的存储库,并将 LogRepositoryTrait 放在里面,或者使用此文件上的 LogRepository
  • 您的当前 User 类应实现 LogCreatorInterface
  • 显示日志
排除字段注解

使用 Doctrine 注释 @LogExcludedField 排除实体中要记录的特定字段

    /**
     * @LogExcludedField()
     * @ORM\Column(name="excluded_field", type="string", length=255, nullable=true)
     */
    protected ?string $excludedField = null;
示例

显示特定类别的所有日志,针对一个用户。

    {% include '@TBaronnatLog/logs/_display_classes_user_log.html.twig' with {
        'classes': ['App\\Entity\\User', 'App\\Entity\\Documents'],
        'user': resource.user
    } %}
    {% if resource is not null and resource.id is not null %}
        {% include '@TBaronnatLog/logs/_display_resource_log.html.twig' with {
            'resource': resource
        } %}
    {% endif %}
    {% include '@TBaronnatLog/logs/_display_resources_log.html.twig' with {
        'resources':  resources,
        'logClasses': ['App\\Entity\\Documents']
    } %}