Priti's Technical Corner

December 16, 2012

How to use ‘Formatters’ in Zend_log


Pre-requiste : Zend_Log Understanding

Usually, Zend_log will log the messages in below format.

‘%timestamp% %priorityName% (%priority%): %message%’;

Example:

“2012-09-18T14:39:21+05:30 (INFO) 6 : Error Cacthed”

My requirement was to have SQL logs which will ONLY Log SQL statement Something like,

INSERT INTO Test VALUES (2,’Jhon’);
INSERT INTO Test VALUES (3,’Katy’);
Update Test SET name=’Jon’ where Id=2;

1. Define a format as per your requirement
$format = ‘%message%’. PHP_EOL;

2. Instantiate Zend_Log_Formatter_Simple class and pass the user defined format
$formatter = new Zend_Log_Formatter_Simple($format);

3. Create Writer
$writerArr=array(‘stream’=>$filePath,’mode’=>’a’);
$writer=Zend_Log_Writer_Stream::factory($writerArr);
$log->addWriter($writer);

4. Apply the formatter to writer
$formatter->format(array(‘message’=>$sql));
$writer->setFormatter($formatter);

5. Write sql in the file
$log->log($sql, 7);

Where in $Log=new Zend_log(); and $filePath is path to the log file.

Simple enough :).

December 14, 2012

Understanding why WAMPServer is unable to launch!


When your WAMPserver Icon is RED. Following are some suggestion to find the root cause
> Click wampserver Icon
> Click Apache
> Select Service
> test port 80
Command line will prompt on your screen and will show you message

Case 1: When Port 80 is not used by any application
Your port 80 is not actually used

Case 2: If it is used by some other application
Your port 80 is actually used by:
– APPLICATION NAME –

Press enter to exit

If you are witnessing Case 2 , Good you find the root cause and you can fix it. This happen when you install some app which use port 80. The widely known application is SKype.

If you are witnessing Case 1, Then why it is not working !

I was excited to know the reason so I pushed myself a bit ..I tried following

On window
NET START wampapache

output:
C:\Documents and Settings\priti.solanki>NET START wampapache
System error 5 has occurred.

Access is denied.

Ah ! System error, Then I recollected yesterday before leaving my workplace I received some updates on my machine. So,

I have to call my system administrator to provide access right on my machine. Now, I run WAMPServer under administrative rights,
It was revoke in yesterday updated received on my machine.

So, If after window updates you WAMPserver do not start normally then you can check as above and find the reason why it is not working.
For me, my problems resolves here. Hope this post help you to collect some information about your problem.

Create a free website or blog at WordPress.com.

%d bloggers like this: