Question

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?

Was it helpful?

Solution

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) {
    }
}

OTHER TIPS

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...

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';
");
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top