Question

I would like to log some variables such as $mageRunCode before it hits:

Mage::run($mageRunCode, $mageRunType);

It appears that Mage::log and even the Zend logging facility don't seem to log out to an arbitrary file output here. How would one do this properly?

Was it helpful?

Solution

Any specific reason you got to do it before mage::run is called in index.php? Are you concerned they get changed?

Attempting to log at that point would require you to adjust core file (index.php) which is not good practice.

Some flow:

In Mage::run you get:

self::$_app->run(array(
                'scope_code' => $code,
                'scope_type' => $type,
                'options'    => $options,
            ));

The variables you are interested in is unchanged at this point.

in Mage_Core_Model_App::run you get this line of code:

Mage::register('application_params', $params);

thus magento internals nicely saves the params used for you in the registry.

To log them, you can use the event 'controller_front_init_before' which is one of the earliest (usable) events fired.

In that event you can pull the saved params, and log them.

$params = mage::registry('application_params');

To note is that this would place a drastic overhead on your sites performance, as it will log on every request. Curious why you would need to do log them?

Earliest usable event

OTHER TIPS

I am assuming that you are trying to log stuff in developer mode/local environment, and you want to fiddle around.

If you want to log something in magento to a custom log file, you can use

Mage::log($myVariable, null, 'myVariable.log');

For this, you need to have logging enabled on the admin backend. This will log stuff to magento_root/var/log/myVariable.log

Tip: You can also print the whole backtrace (for some other deeply laid code) using

Mage::log(Varien_Debug::backtrace(true, true), null, 'backtrace.log');

The advantage of printing the whole backtrace is you can see the exact method/xml flow your call is following to reach that point in execution, anywhere within the php code. Of course, this outputs the result to magento_root/var/log/backtrace.log

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top