Yii Framework Forum: [help] log di class action - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[help] log di class action membuat custom log di class action Rate Topic: ***** 1 Votes

#1 User is offline   aveBean 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 23-October 10
  • Location:Jakarta

Posted 23 October 2010 - 10:16 AM

hi guys,

gw ada problem nih, soal buat log di class action

sample casenya gini nih

class DummyController extends Controller 
{
    public function actions() {
	return array('test' => 'application.controllers.dummy.TestAction');
    }
    public function actionTestLog(){
        Yii::log('test log','info','custom'); // ini ngelog di file
    }
}


trus sample class actionnya seperti ini
class TestAction extends CAction
{
    public function run() {
	Yii::log('test log','info','custom'); // ini gak ngelog ? tanya kenapa??
    }
}


configurasi lognya seperti ini
'log'=>array(
    'class'=>'CLogRouter',
    'routes'=>array(
	array(
	    'class'=>'CFileLogRoute',
	    'levels'=>'trace,info,error,warning,debug',
	    'categories'=>'custom',
	    'logPath'=>dirname(__FILE__).'/../runtime/',
	    'logFile'=>'app.custom.'.date("Ymd").'.log'
	),
     ),
),


kalo yang di function actionTestLog() itu ngelog di file.
nah yang di class action test itu yang gak ngelog di file.

mohon pencerahannya dari senior2... udah butek ni pala... :D
Yii Rocks!!
BabyStore
0

#2 User is offline   aveBean 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 23-October 10
  • Location:Jakarta

Posted 23 October 2010 - 11:36 AM

hahha my bad, udah solve...

ternyata sistem logging di YII gak realtime yah. log di simpan pada array yang hingga akhir script baru di execute ama log router.

dikarenakan di script saya yang sesungguhnya ada exit nya, yang mengakibatkan proses php terhenti dan Yii blom sempat menuliskan lognya... baru dikumpulkan saja ... OMG...


ada cara (config) untuk merubah jadi realtime gak yah... yah walaupun plus-minus... kadang tiap orang punya kebutuhannya masing2

hehhehe
Yii Rocks!!
BabyStore
0

#3 User is offline   aveBean 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 23-October 10
  • Location:Jakarta

Posted 23 October 2010 - 02:20 PM

gw ada solusi nih buat yang butuh realtime logging.

caranya extends class CLogRouter
class LogRouter extends CLogRouter
{
	public function init(){
		parent::init();
		Yii::app()->detachEventHandler('onEndRequest',array($this,'processLogs'));
		Yii::getLogger()->autoFlush = 1;		
	}
	
	public function collectLogs($event)	{
		parent::processLogs($event);
	}
}


extend juga class CFileLogRoute
class FileLogRoute extends CFileLogRoute
{
    public function collectLogs($logger, $processLogs=false)
    {
        $logs=$logger->getLogs($this->levels,$this->categories);
	$this->logs = $logs;
	if($processLogs)
	{
	    if($this->filter!==null)
		Yii::createComponent($this->filter)->filter($this->logs);
	    if(!empty($this->logs))
		$this->processLogs($this->logs);
	}
    }
}


trus config main.php nya sedikit dirubah
'log'=>array(
    'class'=>'application.components.LogRouter', // ini diarahkan ke class extend yang kita buat
    'routes'=>array(
	array(
  	    'class'=>'application.components.FileLogRoute', // ini juga
	    'levels'=>'trace,info,error,warning',
	),
    ),
),


tidak disarankan untuk yang menggunakan email logging.... bisa flood bos!!
Yii Rocks!!
BabyStore
0

#4 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 541
  • Joined: 21-June 10

Posted 23 October 2010 - 09:36 PM

Sep.. thank you gan atas petunjuknya :D

belum coba sih, tapi kecepatan loading berkurang signifikan gak yah?
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#5 User is offline   aveBean 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 23-October 10
  • Location:Jakarta

Posted 24 October 2010 - 03:25 AM

View Postjunxiong, on 23 October 2010 - 09:36 PM, said:

Sep.. thank you gan atas petunjuknya :D

belum coba sih, tapi kecepatan loading berkurang signifikan gak yah?


kalo kecepatanya loadingnya + execution pastinya berkurang... tapi saya rasa tidak signifikan...
ini buat case yang perlu logging secara realtime... seperti yang saya perlukan saat ini....
tapi kalo yang tidak perlu logging realtime sepertinya tidak usah dirubah. design logging yii sudah bagus.
Yii Rocks!!
BabyStore
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users