yiisoft / log-target-file Goto Github PK
View Code? Open in Web Editor NEWYii Logging Library - File Target
Home Page: https://www.yiiframework.com/
License: BSD 3-Clause "New" or "Revised" License
Yii Logging Library - File Target
Home Page: https://www.yiiframework.com/
License: BSD 3-Clause "New" or "Revised" License
Yii2 should have the option to compress rollover files.
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"
}
}
}
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,
],
],
This is related to mistake made in #38. In fact, we need the opposite behavior as in yiisoft/yii2#19499
For example, extensions use here.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.