Giter VIP home page Giter VIP logo

log-target-file's People

Contributors

damasco avatar dependabot-preview[bot] avatar dependabot[bot] avatar desure85 avatar devanych avatar dplusg avatar fantom409 avatar machour avatar olegbaturin avatar roxblnfk avatar rustamwin avatar samdark avatar terabytesoftw avatar viktorprogger avatar vjik avatar xepozz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

log-target-file's Issues

Configuration error.

Have an error with default configuration.

File config/params.php

<?php

declare(strict_types=1);

use Psr\Log\LogLevel;

return [

    'yiisoft/log-target-file' => [
        'fileTarget' => [
            'file' => '@runtime/logs/app.log',
            'levels' => [
                LogLevel::EMERGENCY,
                LogLevel::ERROR,
                LogLevel::WARNING,
                LogLevel::INFO,
                LogLevel::DEBUG,
            ],
            'dirMode' => 0755,
            'fileMode' => null,
        ],
        'fileRotator' => [
            'maxFileSize' => 10240,
            'maxFiles' => 5,
            'fileMode' => null,
            'rotateByCopy' => null,
            'compressRotatedFiles' => false,
        ],
    ],
];

File config/console/application.php

<?php

declare(strict_types=1);

/* @var array $params */

use Psr\Log\LoggerInterface;
use Yiisoft\Aliases\Aliases;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Sqlite\Connection;
use Yiisoft\Log\Logger;
use Yiisoft\Log\Target\File\FileRotator;
use Yiisoft\Log\Target\File\FileRotatorInterface;
use Yiisoft\Log\Target\File\FileTarget;

return [
    LoggerInterface::class => static fn (FileTarget $fileTarget) => new Logger([$fileTarget]),

    FileRotatorInterface::class => [
        'class' => FileRotator::class,
        '__construct()' => [
            $params['yiisoft/log-target-file']['fileRotator']['maxFileSize'],
            $params['yiisoft/log-target-file']['fileRotator']['maxFiles'],
            $params['yiisoft/log-target-file']['fileRotator']['fileMode'],
            $params['yiisoft/log-target-file']['fileRotator']['rotateByCopy'],
            $params['yiisoft/log-target-file']['fileRotator']['compressRotatedFiles'],
        ],
    ],

    FileTarget::class => static function (Aliases $aliases, FileRotatorInterface $fileRotator) use ($params) {
        $fileTarget = new FileTarget(
            $aliases->get($params['yiisoft/log-target-file']['fileTarget']['file']),
            $fileRotator,
            $params['yiisoft/log-target-file']['fileTarget']['dirMode'],
            $params['yiisoft/log-target-file']['fileTarget']['fileMode'],
        );

        $fileTarget->setLevels($params['yiisoft/log-target-file']['fileTarget']['levels']);

        return $fileTarget;
    },
];

Error on command php yii:

PHP Fatal error:  Uncaught ErrorException: Duplicate key "yiisoft/log-target-file => fileTarget => file" in configs:
 - config/params.php
 - config/packages/yiisoft/log-target-file/params.php
 - config/packages/yiisoft/profiler/params.php in /var/www/import/vendor/yiisoft/config/src/Config.php:373
Stack trace:
#0 /var/www/import/vendor/yiisoft/config/src/Config.php(244): Yiisoft\Config\Config->throwException()
#1 /var/www/import/vendor/yiisoft/config/src/Config.php(241): Yiisoft\Config\Config->merge()
#2 /var/www/import/vendor/yiisoft/config/src/Config.php(241): Yiisoft\Config\Config->merge()
#3 /var/www/import/vendor/yiisoft/config/src/Config.php(147): Yiisoft\Config\Config->merge()
#4 /var/www/import/vendor/yiisoft/config/src/Config.php(76): Yiisoft\Config\Config->buildGroup()
#5 /var/www/import/yii(22): Yiisoft\Config\Config->get()
#6 {main}
  thrown in /var/www/import/vendor/yiisoft/config/src/Config.php on line 373

Fatal error: Uncaught ErrorException: Duplicate key "yiisoft/log-target-file => fileTarget => file" in configs:
 - config/params.php
 - config/packages/yiisoft/log-target-file/params.php
 - config/packages/yiisoft/profiler/params.php in /var/www/import/vendor/yiisoft/config/src/Config.php on line 373

ErrorException: Duplicate key "yiisoft/log-target-file => fileTarget => file" in configs:
 - config/params.php
 - config/packages/yiisoft/log-target-file/params.php
 - config/packages/yiisoft/profiler/params.php in /var/www/import/vendor/yiisoft/config/src/Config.php on line 373

Also compiled files after command composer dump-autoload

File config/packages/yiisoft/log-target-file/params.php

<?php

declare(strict_types=1);

use Psr\Log\LogLevel;

return [
    'yiisoft/log-target-file' => [
        'fileTarget' => [
            'file' => '@runtime/logs/app.log',
            'levels' => [
                LogLevel::EMERGENCY,
                LogLevel::ERROR,
                LogLevel::WARNING,
                LogLevel::INFO,
                LogLevel::DEBUG,
            ],
            'dirMode' => 0755,
            'fileMode' => null,
        ],
        'fileRotator' => [
            'maxFileSize' => 10240,
            'maxFiles' => 5,
            'fileMode' => null,
            'rotateByCopy' => null,
            'compressRotatedFiles' => false,
        ],
    ],
];

File config/packages/yiisoft/profiler/params.php

<?php

declare(strict_types=1);

use Psr\Log\LogLevel;
use Yiisoft\Profiler\Target\FileTarget;
use Yiisoft\Profiler\Target\LogTarget;

return [
    'yiisoft/profiler' => [
        'targets' => [
            LogTarget::class => [
                'include' => [],
                'exclude' => [],
                'enabled' => true,
                'level' => LogLevel::DEBUG,
            ],
            FileTarget::class => [
                'include' => [],
                'exclude' => [],
                'enabled' => false,
                'requestBeginTime' => $_SERVER['REQUEST_TIME_FLOAT'],
                'filename' => '@runtime/profiling/{date}-{time}.txt',
                'directoryMode' => 0775,
            ],
        ],
    ],
];

File composer.json

{
  "type": "project",
  "require": {
    "php": ">=7.4.0 <8.0.0",
    "httpsoft/http-message": "^1.0.5",
    "nyholm/psr7": "^1.4@dev",
    "yiisoft/active-record": "^3.0@dev",
    "yiisoft/config": "1.0.x-dev",
    "yiisoft/db-sqlite": "^3.0@dev",
    "yiisoft/di": "^3.0@dev",
    "yiisoft/log-target-file": "^1.0",
    "yiisoft/router-fastroute": "^3.0@dev",
    "yiisoft/yii-console": "^3.0@dev",
    "yiisoft/yii-web": "^3.0@dev"
  },
  "minimum-stability": "dev",
  "prefer-stable": true,
  "autoload": {
    "psr-4": {
      "Import\\": "src"
    }
  },
  "autoload-dev": {
    "psr-4": {
      "Import\\Tests\\": "tests"
    }
  },
  "config": {
    "sort-packages": true
  },
  "scripts": {
    "serve": "yii serve",
    "post-update-cmd": [
      "Import\\Installer::postUpdate"
    ]
  },
  "extra": {
    "branch-alias": {
      "dev-master": "3.0.x-dev"
    },
    "config-plugin-options": {
      "source-directory": "config",
      "output-directory": "config/packages"
    },
    "config-plugin": {
      "common": "common/*.php",
      "params": [
        "params.php",
        "?params-local.php"
      ],
      "web": [
        "$common",
        "web/*.php"
      ],
      "console": [
        "$common",
        "console/*.php"
      ],
      "events": "events.php",
      "events-web": [
        "$events",
        "events-web.php"
      ],
      "events-console": [
        "$events",
        "events-console.php"
      ],
      "providers": "providers.php",
      "providers-web": [
        "$providers",
        "providers-web.php"
      ],
      "providers-console": [
        "$providers",
        "providers-console.php"
      ],
      "routes": "routes.php"
    }
  }
}

Add 'categories', 'except' and 'exportInterval' setters to default config

What is the expected result?

Possibility to configure default FileTarget logger through app params.

/config/di.php

FileTarget::class => static function (Aliases $aliases, FileRotatorInterface $fileRotator) use ($params) {
    $fileTarget = new FileTarget(
        $aliases->get($params['yiisoft/log-target-file']['fileTarget']['file']),
        $fileRotator,
        $params['yiisoft/log-target-file']['fileTarget']['dirMode'],
        $params['yiisoft/log-target-file']['fileTarget']['fileMode'],
    );

    $fileTarget->setLevels($params['yiisoft/log-target-file']['fileTarget']['levels']);
+    $fileTarget->setCategories($params['yiisoft/log-target-file']['fileTarget']['categories']);
+    $fileTarget->setExcept($params['yiisoft/log-target-file']['fileTarget']['except']);
+    $fileTarget->setExportInterval($params['yiisoft/log-target-file']['fileTarget']['exportInterval']);

    return $fileTarget;
},

/config/params.php

'yiisoft/log-target-file' => [
    'fileTarget' => [
        'file' => '@runtime/logs/app.log',
        'levels' => [
            LogLevel::EMERGENCY,
            LogLevel::ERROR,
            LogLevel::WARNING,
            LogLevel::INFO,
            LogLevel::DEBUG,
        ],
+        'categories' => [],
+        'except' => [],
+        'exportInterval' => 1000,
        'dirMode' => 0755,
        'fileMode' => null,
    ],
    'fileRotator' => [
        'maxFileSize' => 10240,
        'maxFiles' => 5,
        'fileMode' => null,
        'compressRotatedFiles' => false,
    ],
],

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.