문제

사용 cakephp 의 2.4.4 을 구축하는 상호 작용하는 웹의 일부 내 응용 프로그램과는 매우 원활하게 진행되고 있습니다.Cakephp 에서는 굉장하다.

나는 지금 하는 일부 지원 배경 처리합니다.콘솔에 포탄을 것 같다는 그것을 할 수 있는 방법으로 그것은에 액세스할 수 있 모델입니다.

가 작성된 코드고 그것은 작동하지만 내가 쓰려고 하는 같은 로그를 사용하는 위한 모델입니다.모델에서 나는 afterSave 기능을 로그하는 모든 데이터베이스의 변경 및 내용의 $this->log("$model $logEntry", 'info'); 를 작성하는 로그를 보실 수 있습니다.

이 작동하지 않는 쉘에서 그러나 내가 생각합 CakeLog::write('info', "$model $logEntry"); 도 작동할 수 있지만 그것도하지 않는다.

이 필요한가요를 초기화하 CakeLog 하는 올바른 로그 파일이 있는가?

<?php
App::uses('CakeTime', 'Utility');
App::uses('CakeLog', 'Utility');

class ProcessRequestShell extends AppShell {
    //Need to access the request and monitor tables
    public $uses = array('Request');

    private function updateRequest($data){
        $model = 'Request';
        $result = $this->Request->save($data);

        $logEntry = "UPDATE ProcessRequestShell ";
        foreach ($data[$model] AS $k => $v){$logEntry .= "$k='$v' ";}
        if ($result){
            //$this->log("$model $logEntry", 'info');
            CakeLog::write('info', "$model $logEntry");
        } else {
            //$this->log("$model FAILED $logEntry", 'error');
            CakeLog::write('error', "$model FAILED $logEntry");
        }
        return($result);
    }

    public function main() {
        $options = array('conditions' => array('state' => 0, 'next_state' => 1));
        $this->Request->recursive = 0;
        $requests = $this->Request->find('all', $options);

        //See if the apply_changes_on date/time is past
        foreach ($requests AS $request){
            $this->out("Updating request ".$request['Request']['id'], 1, Shell::NORMAL);

            //Update the next_state to "ready"
            $request['Request']['state'] = 1;
            $request['Request']['next_state'] = 2;
            $this->updateRequest($request);
        }
    }
}
?>
도움이 되었습니까?

해결책

당신은 설정 기본 수신기/범위한 로그 형식?그렇지 않으면,그들은 얻지 않을 것이 기록됩니다.

// Setup a 'default' cache configuration for use in the application.
Cache::config('default', array('engine' => 'File'));

에 bootstrap.php 예를 들어

http://book.cakephp.org/2.0/en/appendices/2-2-migration-guide.html#log

다른 팁

를 설정해야 합 default 로그인 스트림 파일에 쓰기,결국에서 app/Config/bootstrap.php.

CakeLog 하지 않는 자동차-자신을 구성을 더 이상.결과적으로 로그 파일 지 않을 것이 자동으로 만들어 더 이상 없으면 스트림은 듣고 있다.는지 확인 당신은 하나 이상의 default 스트림을 설정하는 경우에,당신은 당신이 듣고 싶 모든 유형과 수준이다.일반적으로 설정할 수 있습니다,당신의 핵심 FileLog 클래스 하여 출력 app/tmp/logs/:

CakeLog::config('default', array(
    'engine' => 'File'
));

로깅→로그에 쓰 섹션의 책 2.x

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top