Log Shell cakephp

Asked

Viewed 97 times

1

I have a SHELL file in cakephp as below:

<?php
class AtualizarIndicadoresNormaisShell extends AppShell {
    public function atualizar() {
        //Chama model e sua action
        ClassRegistry::init('DadoIndicadoresNormal')->atualizarIndicadoresNormais();
    }
}

It calls the model below on updateIndicationsNormals():

<?php
App::uses('AppModel', 'Model');

class DadoIndicadoresNormal extends AppModel {
    ...
    function atualizarIndicadoresNormais() {
        App::import('Controller', 'DadosIndicadoresNormais');
        $atualizar = new DadosIndicadoresNormaisController;
        $atualizar->cronAtualizar();
    }
}

Here I call a controller action named cronAtualize().

Within Controller Action, how do I display a message through Shell? I used as below but returns error. Because it only works inside the Shell file. Can you help me? Or if you have an error log.

 $this->out

1 answer

0

It is really not possible to send a message to the terminal from a model or controller. The best way out in this case is to actually use an alternate log for you to track the outputs. In that case you just add the settings in config, example:

// Configure tmp/logs/shop.log to receive the two configured types (log levels), but only
// those with `orders` and `payments` as scope
CakeLog::config('shop', array(
    'engine' => 'FileLog',
    'types' => array('warning', 'error'),
    'scopes' => array('orders', 'payments'),
    'file' => 'shop.log',
));

// Configure tmp/logs/payments.log to receive the two configured types, but only
// those with `payments` as scope
CakeLog::config('payments', array(
    'engine' => 'SyslogLog',
    'types' => array('info', 'error', 'warning'),
    'scopes' => array('payments')
));

Then to make the call statically to record in the log:

CakeLog::warning('This gets written only to shops stream', 'orders');
CakeLog::warning('This gets written to both shops and payments streams', 'payments');

This information can be found better in the Cakephp documentation itself in the Logging.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.