virtua/shopware-basic-app-logger-bundle

为 Shopware 应用添加基本日志记录器

安装: 347

依赖者: 0

建议者: 0

安全: 0

星星: 2

关注者: 0

分支: 0

开放问题: 0

语言:Twig

类型:symfony-bundle

1.0.5 2022-07-26 13:31 UTC

This package is auto-updated.

Last update: 2024-09-26 18:31:06 UTC


README

描述

此包包含 Shopware 应用程序的完整功能日志记录器。应用程序符合 Shopware 质量指南,并将日志放在默认的 Shopware log_entry 实体中。

要求

  • PHP >= 8.0
  • Symfony 6
  • ShopwareShop 实体

安装

  • 将包仓库添加到 composer.json
"virtua/shopware-basic-app-logger-bundle": "^1.0"
  • 将包添加到 bundles.php
Virtua\ShopwareBasicAppLoggerBundle\ShopwareBasicAppLoggerBundle::class => ['all' => true]
  • 将包路由添加到 routes.yaml
shopware_app_logger_bundle_routes:
    resource: "@VirtuaShopwareBasicAppLoggerBundle/Resources/config/routes.yaml"
  • 创建新文件 config/packages/virtua_shopware_basic_app_logger.yaml,包含数据
imports:
    - { resource: '@VirtuaShopwareBasicAppLoggerBundle/Resources/config/config.yml' }
  • 运行迁移 bin/console doctrine:migrations:migrate

使用方法

#####编写此包在安装后立即完全可用。要创建新日志,请使用来自 Logger 服务的 log() 方法。作为参数,您必须提供来自 Util 目录的 LoggerData 对象。

log() 使用示例

use Virtua\ShopwareBasicAppLoggerBundle\Service\Logger;
use Virtua\ShopwareBasicAppLoggerBundle\Util\LoggerData;

/* ... */

public function __construct(Logger $logger)
{
	$this->logger = $logger;
}

/* ... */

public function exampleFunction(): void
{
	$loggerData = new LoggerData($shopId);
	$loggerData->setMessage("shopware.app.error"); //Use your appication name to identify error in logEntry
	$loggerData->setLevel(404);   //This is optional, default code is 400
	$loggerData->setContext('Your Error message', $errorData ); //errorData is optional parameter to pass additional error informations as array
	$this->logger->log($loggerData);  
}

#####读取

日志显示在 Shopware 实体 log_entry 中,可在“管理”>“系统”>“事件日志”中找到。