Log Shell cakephp

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 in updatingNormal ():

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

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

In it I call a controller action called cronUpdate ().

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

 $this->out
    
asked by anonymous 31.03.2017 / 22:34

1 answer

0

It is not really possible to send a message to the terminal from a model or controller. The best way out is to actually use an alternate log for you to track the outputs. In this case you just add the settings in config , for 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 write to 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 in the CakePHP documentation itself in the area. Logging .

    
04.04.2017 / 08:58