3

I noticed that magento does not create any new logfiles after installing SUPEE-11086.

I tried it like this: Mage::log('test', null, 'test123.log', true);

I tried to debug the static log function in app/Mage.php and figured out that the code enters the return here:

if (!$logValidator->isValid($logDir . DS . $file)) {
    return;
}

This is a comparism of the code before the patch and after it:

Compare

I even changed permissions of the whole var folder to 777 recursively with chmod -R 777 var/

Did anyone noticed this behaviour and found a solution yet?

2

Problem is following code snippet:

if (!$logValidator->isValid($logDir . DS . $file)) {
    return;
}

This is checked the file before created. If your log file already exist inside log folder then everything will be fine. If not then this logic will not work. So move this logic after file creation with simple modification, like:

if (!is_dir($logDir)) {
    mkdir($logDir);
    chmod($logDir, 0750);
}

if (!file_exists($logFile)) {
    file_put_contents($logFile, '');
    chmod($logFile, 0640);
}

if (!$logValidator->isValid($logDir . DS . $file)) {
    if (file_exists($logFile)) {
        unlink($logFile);
    }
    return;
}

So the full method will be:

public static function log($message, $level = null, $file = '', $forceLog = false)
{
    if (!self::getConfig()) {
        return;
    }

    try {
        $logActive = self::getStoreConfig('dev/log/active');
        if (empty($file)) {
            $file = self::getStoreConfig('dev/log/file');
        }
    }
    catch (Exception $e) {
        $logActive = true;
    }

    if (!self::$_isDeveloperMode && !$logActive && !$forceLog) {
        return;
    }

    static $loggers = array();

    $level  = is_null($level) ? Zend_Log::DEBUG : $level;
    $file = empty($file) ?
        (string) self::getConfig()->getNode('dev/log/file', Mage_Core_Model_Store::DEFAULT_CODE) : basename($file);

    // Validate file extension before save. Allowed file extensions: log, txt, html, csv
    $_allowedFileExtensions = explode(
        ',',
        (string) self::getConfig()->getNode('dev/log/allowedFileExtensions', Mage_Core_Model_Store::DEFAULT_CODE)
    );
    $logValidator = new Zend_Validate_File_Extension($_allowedFileExtensions);
    $logDir = self::getBaseDir('var') . DS . 'log';

    try {
        if (!isset($loggers[$file])) {
            $logFile = $logDir . DS . $file;

            if (!is_dir($logDir)) {
                mkdir($logDir);
                chmod($logDir, 0750);
            }

            if (!file_exists($logFile)) {
                file_put_contents($logFile, '');
                chmod($logFile, 0640);
            }

            if (!$logValidator->isValid($logDir . DS . $file)) {
                if (file_exists($logFile)) {
                    unlink($logFile);
                }
                return;
            }

            $format = '%timestamp% %priorityName% (%priority%): %message%' . PHP_EOL;
            $formatter = new Zend_Log_Formatter_Simple($format);
            $writerModel = (string)self::getConfig()->getNode('global/log/core/writer_model');
            if (!self::$_app || !$writerModel) {
                $writer = new Zend_Log_Writer_Stream($logFile);
            }
            else {
                $writer = new $writerModel($logFile);
            }
            $writer->setFormatter($formatter);
            $loggers[$file] = new Zend_Log($writer);
        }

        if (is_array($message) || is_object($message)) {
            $message = print_r($message, true);
        }

        $message = addcslashes($message, '<?');
        $loggers[$file]->log($message, $level);
    }
    catch (Exception $e) {
    }
}
  • 2
    I wonder when magento will officially patch this... – Black Apr 15 at 9:17
  • Why you have used unlink method for the $logFile ? It's not there in the patch. – Parth Thakkar May 8 at 7:20
  • @ParthThakkar Because should delete the invalid file. – Sohel Rana May 8 at 7:32
  • Okay, but it will not delete default log files(system.log & extension.log), right ? – Parth Thakkar May 8 at 10:48
4

Still nothing from Magento about a V2 patch to fix the SUPEE-11086 log problem, but if you know how to patch using a .diff file, you can fix the issue using what will be the official patch.

It appears to be 2 lines that require editing in the app/mage.php file.

https://gist.github.com/piotrekkaminski/0596cae2d25bf467edbd3d3f03ab9f8f

Surprising that Magento has been quiet about this one...

1

I suggest to do not change core code and use an update like this (https://gist.github.com/mehdichaouch/99c67298b5a65f81219c9b69942b6fe7)

$installer->run("
    INSERT INTO `{$installer->getTable('core_config_data')}` (scope, scope_id, path, value)
    VALUES ('default', 0, 'dev/log/allowedFileExtensions', 'log,txt,html,csv')
    ON DUPLICATE KEY UPDATE value = 'log,txt,html,csv';
");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.