First of all, I’d like to thank you all for your patience! Zendcasts takes quite a bit of time and research to put together and I’m deeply touched by all your support.
On a personal note, my wife and I are heading out of North America in a week to visit Namibia and South Africa for 3 months. I’m going to do my best to keep up Zendcasts on a weekly basis, however my connectivity and upload speed will be limited. We’ll see how it goes!
Now for today’s episode:
I was working on a project for a client the other day and noticed a couple of lines in the ErrorController for automatically logging errors with Zend_Log. In 10 minutes, you can have a fully integrated logging framework. I also implement a singleton pattern for reusing your Zend_Log configuration (defined in the application.ini) anywhere else in your application.
Grab a copy of the project or browse the repository.
Enjoy!

Thanks for another great tip.
But, you’ve said, that protected constructor can be invoked only by the class itself. But that doesn’t say clearly, that it could be also invoked by classes extending ZC_FileLogger. I have no doubts that you know the difference between ‘protected’ and ‘public’, but maybe some one doesn’t, so I mentioned it here.
BTW. Loggin in one line:
Zend_Registry::get(“log”)->info(‘Hello World!’);
I’m joking, I get the point of doing that screencast. Thanks again:)
I meant ‘protected’ and ‘private’ of course
Brilliant. Thanks for your hard work.
nice! it’s to useful thanks!
Hi John,
very nice ZendCast again, and just what i needed today
if you haven’t produced the emaillogging cast it would be very nice if you could built in something like…
if the coding runs on the developement/testingserver the logg should be written to a stream
and if the code runs on the production server it is written to a stream to but if there are warnings or errors to log then they are logged additionally to email to.
and is it much more work to log for example errors to database (just on production server) or firebug (just on developement and testingserver)???
i hope that you can consider some of my requests because i think that it makes sense to handle the logging different depends on the server.
best regards from Germany
Sascha
Hi, I hope you enjoy your stay in Southern Africa. I’m from SA, so please feel free to contact me with any questions.
Anyway, great episodes!
Thanks for this good work..
Can’t wait to see more.
Thanks for the screencast. I think it should be right to create FileLogger, EmailLogger, DatabaseLogger etc. and then create a factory class that will use object of specified type to make logging whatever you want.
P.S. I’ve updated ZF to 1.10 ’cause in 1.9.x there was no Logger resource available and in ErrorController
method $bootstrap->getResource(‘Log’) returns null,
so i changed it to $bootstrap->getPluginResource(‘Log’)->getLog().
It is a great help! Very clear!
Just one thing…
When I create the new folder ZC with the FileLogger.php, the error class ZC_FileLogger not found appears.
Maybe there is an error in the library path…but i don`t understand where…
I use Zend_Log with Firebug writer.
If I use the shortcut ZC_FileLogger, I get the the wrong origin filename and line number.
How can I fix this.
Thanks for the great tutorial.
It just answered several questions about the Zend framework that were really frustrating me.
Thanks, its very useful
When I add the bootstrap _initLog function, exceptions are no longer logged to my log file. Any idea why?
Found the problem. Since Log is a a default plugin resource (available even if you don’t explicitly create it in your bootstrap), its always available. You need to add a line to return the log at the end of the if statement in the _initLog function. Otherwise, the error controller won’t be able to find the log object when trying to log errors.
http://framework.zend.com/manual/1.10/en/zend.application.available-resources.html
thank’s for casts… realy great .
Why don’t you use your new created ZC_logger class in the error controller as well? Wouldn’t that be easier?
@Sander you could definitely integrate it in that manner. In these videos, I try and narrow my scope as much as possible so that I don’t have to rely on too much additional background knowledge in the viewer.
Thanks for this great tutorial. But i want to log my database operations like if some user add/delete/update a record in database then i have to manually call one function in model to insert that info.
user_id, operation_type,database_table etc.
So can you please tell me that instead of writing in each model i can achieve this automatically..
Thanks in advance.
Hi,
I am facing an issue in application.log file.
When I add code to application.ini, for this file immediately after creating the project, the file is created.But it does not work, if addthe same code after, I have done some other coding.
Please tell me, how tell me overcome this.
Thanks in advance.
Thanks!
Great tip!