tbaronnat / log-bundle
简单的日志捆绑系统,支持 Symfony 集成
v1.0.3
2024-03-13 13:09 UTC
Requires
- php: >=8.1
- doctrine/annotations: ^1.0
- doctrine/doctrine-bundle: v2.6.4
- doctrine/orm: ^2.7
- symfony/dependency-injection: ^6.0
- symfony/security-core: ^6.0
- symfony/twig-bundle: ^6.0
- twig/twig: ^2.0|^3.0
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']
} %}