As Magento throws info into system.log
and debug.log
I can see 3 different types
Is it possible to disable main.INFO
and main.DEBUG
while keeping main.CRITICAL
to avoid large file size for logging files.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityMagento only logs these kinds of Debug information if you're in developer mode. In production, you wan't have to run the production mode. If you've never done that before, you should try it out locally first.
You can change the Magento mode to production with php bin/magento deploy:mode:set production
.
I'm currently digging through this too so here's what I know
In older versions, you could still change error_reporting
in app/bootstrap.php
Now, Magento 2 has changed to use Monolog/Logger and the log levels are hard coded as private variables in the logger code
The main log files all extend
Magento\Framework\Logger\Handler\Base.php
which has the following internal variable
/**
* @var int
*/
protected $loggerType = Logger::DEBUG;
And all the basic logs are created with their own protected $loggerType
value
For example here's \Magento\Framework\Logger\Handler\Exception.php
(System.php and Debug.php are similar, Syslog slightly different but also hard coded protected variable)
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Logger\Handler;
use Monolog\Logger;
class Exception extends Base
{
/**
* @var string
*/
protected $fileName = '/var/log/exception.log';
/**
* @var int
*/
protected $loggerType = Logger::INFO;
}
So if you just wanted to change it temporarily, the changing the protected $loggerType = Logger::INFO;
to, say, protected $loggerType = Logger::ERROR;
would do the job
If you wanted a more flexible setup, then the Magento\Framework\Logger\Handler
classes would need overriding in a module, just changing the constant
The log levels are in the psr module
const EMERGENCY = 'emergency';
const ALERT = 'alert';
const CRITICAL = 'critical';
const ERROR = 'error';
const WARNING = 'warning';
const NOTICE = 'notice';
const INFO = 'info';
const DEBUG = 'debug';
Maybe using PHP error handling from your PHP configuration (log_level). PHP can only write specific level and skip previous one.
Hopefully, it will help you.
You can use before plugin for specific function and send message as blank so file will not be grow, but it is bad way
vendor/psr/log/Psr/Log/LoggerInterface.php
There is good way to rotate log file on some interval basis on server level.
So on daily or configured time basis your file will be rotate so no large data will be there in file.
Explore more Logrotate
You can disable system logging by running command: bin/magento setup:config:set --enable-syslog-logging=false
You can disable debug logging by running command: bin/magento setup:config:set --enable-debug-logging=false
Remember to flush the cache after that: bin/magento cache:flush