apprentice (77) [Avatar] Offline
#1
[nobr]
I have tested this code successfully on my Edit view page. But now I want to move this to my Bootstrap and I think I have problems with connecting the path to my log.txt file.
How do I fix this correctly?







Websitesakrabatapplicationviewsscriptsindexedit.phtml - This works!
[pre]
<?php <br />
$writer = new Zend_Log_Writer_Stream('../var/logs/zf_log.txt'); // Websites/akrabat/var/logs/
$logger = new Zend_Log($writer);
$logger->log('message to yoda', Zend_Log::EMERG);

?>
[/pre]







Bootstrap - This doesn't work!
[pre]
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

protected function _initAutoload()
{
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH));
return $moduleLoader;


// Zend_Log
$bear = new Zend_View_Helper_BaseUrl;

$writer = new Zend_Log_Writer_Stream($bear->baseUrl().'../var/logs/zf_log.txt'); // Websites/akrabat/var/logs/
$logger = new Zend_Log($writer);

Zend_Registry::set('logger', $logger);

}
[/pre]

[/nobr]
akrabat (479) [Avatar] Offline
#2
Re: How do you put Zend_Log into bootstrap correctly?
baseUrl() is the wrong function to use... it is a URL, not a file path.

Why not use APPLICATION_PATH ?

Regards,

Rob...
apprentice (77) [Avatar] Offline
#3
Re: How do you put Zend_Log into bootstrap correctly?
Thanks for the pointer Rob, unfortunately I still can't figure out how to understand the written language in the Zend reference guide. I would like to find some small code examples with google but can't find any.
So I still don't know how to apply APPLICATION_PATH in a live experient?

Is this how you use APPLICATION_PATH? Because I still get APPLICATION Error message in the webbrowser.


____________________________________________
Bootstrap
[pre]
protected function _initAutoload()
{
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH));
return $moduleLoader;


// Zend_Log
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . "../var/logs/zf_log.txt"); // Websites/akrabat/var/logs/
$logger = new Zend_Log($writer);
Zend_Registry::set('logger', $logger);
[/pre]
apprentice (77) [Avatar] Offline
#4
Re: How do you put Zend_Log into bootstrap correctly?
Manning forum engine is full of bugs so I had to separate my post in 2 separate sections. smilie
The below code creates the APPLICATION Error message when used together with the above Bootstrap code!








Websitesakrabatapplicationviewsscriptsindexedit.phtml - This doesn't work!
[pre]


<center>View script for controller index and script/action name edit</center>

<?php echo $this->form; ?>

<?php <br />
/*
$writer = new Zend_Log_Writer_Stream('../var/logs/zf_log.txt'); // Websites/akrabat/var/logs/
$logger = new Zend_Log($writer);
$logger->log('message to yoda', Zend_Log::EMERG);
*/


$logger = Zend_Registry::get('logger');
$logger->log('message to yoda', Zend_Log::EMERG);


?>
[/pre]
akrabat (479) [Avatar] Offline
#5
Re: How do you put Zend_Log into bootstrap correctly?
What does
[pre]
Zend_Debug::dump(APPLICATION_PATH . "../var/logs/zf_log.txt")
[/pre]
give?

Also, what is error?

Rob...
apprentice (77) [Avatar] Offline
#6
Re: How do you put Zend_Log into bootstrap correctly?
Adding this line in Edit view page.





[pre]Zend_Debug::dump(APPLICATION_PATH . "../var/logs/zf_log.txt")[/pre]





Gives me the string(50) message but only if I disable this code in Edit view page:





[pre]
/*
$logger = Zend_Registry::get('logger');
$logger->log('message to yoda', Zend_Log::EMERG);
*/
[/pre]





[pre]string(50) "C:Websitesat2application../var/logs/zf_log.txt"[/pre]








Regarding the Error message from before it doesn't say anything useful just this.
But only when the above Yoda code is enabled in Edit view page.
akrabat (479) [Avatar] Offline
#7
Re: How do you put Zend_Log into bootstrap correctly?
Well that shows one problem.

Try:
[pre]
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . "/../var/logs/zf_log.txt");
[/pre]

Regards,

Rob...
apprentice (77) [Avatar] Offline
#8
Re: How do you put Zend_Log into bootstrap correctly?
.
.
1.) I changed the logfile name everywhere because ZF MVC doesn't like underscores in folder and file names. Just in case it's the one causing problems.



2.) I also created another logfile structure directly under /application folder. Just in case it's the one causing problems.



3.) My Edit view page looks like this when I test different ways in Bootstrap file.
http://pastebin.com/m62377a84



4.) I have tried 16 different ways to connect to a logfile in Bootstrap which you can see here.
http://pastebin.com/m763b14bd



I still get Application errors. smilie

apprentice (77) [Avatar] Offline
#9
Re: How do you put Zend_Log into bootstrap correctly?
Has nobody else played with Zend_Log? I can't find any usable documentation/guides/blogs on the Internet smilie
lsco (2) [Avatar] Offline
#10
Re: How do you put Zend_Log into bootstrap correctly?
> Has nobody else played with Zend_Log? I can't find
> any usable documentation/guides/blogs on the Internet
> smilie

The following links are all I have come up with in my research. Everything else is way out of date and the Zend docs don't really cover the MVC use of Zend_Log, perhaps I just don't know where to look.
I am yet to implement anything log related so would be keen to know if these help you. I'm still to finish some other aspects before I dive into Zend_Log myself. Getting Doctrine ORM integrated and working in Zend was tricky enough smilie

http://www.nabble.com/Use-of-zend_Log-within-MVC-Framework-td18961620.html
http://www.mail-archive.com/fw-general@lists.zend.com/msg22273.html
apprentice (77) [Avatar] Offline
#11
Re: How do you put Zend_Log into bootstrap correctly?
.
.
<h2>INDEX</h2>
==============

- History
- Solution
- Summary
- Codes

==============


<h3>History</h3>
I've been avoiding the ZF mailing list for almost a year now. Because I sort of created a World War 3 with the WineHQ people 2 years ago. About the use of:

Forums vs. Mailing lists

It seems like elite programmers only like to use Mailing lists while regular people like to use Forums. So I had to face my fears in the end anyways in order to find my answers.



<h3>Solution</h3>
Anyhow I had nowhere to go but go join the Darkside smilie
By signing up on that ZF mailing list like this forum sticky recommend in the first place:

Announcement: Useful Zend Framework resources

Then I just sent my question and within 2 days I got a pretty accurate advice back. And voila problem solved.

Bootstrap
http://pastebin.com/f788c3a29

Edit view page
http://pastebin.com/f5f45c31f



<h3>Summary</h3>
I still prefer to use a database driven forum like this though it's easier to organize information. And it has a hidden dimension that those stubborn WineHQ-Mailing-list-only-people refuse to see. Forums build communities much better than maling lists I think. There I've said it smilie now I feel more at peace.

Still Manning forum engine is horrible compared to 99% of all other communities' forum engines on the Internet.

Zend_Log seems pretty useless from a newbie perspective maybe not for veterans. But when you do a *combo henge* with Zend_Log and Zend_Db_Profiler like described in the book. Then you can measure SQL times and start to play with database optimizations.



<h3>Codes</h3>
In case the Pastebin.com codes gets removed in the future here I paste it into the horrible Manning forum engine. There I said it again. smilie

Bootstrap
http://pastebin.com/f788c3a29

Edit view page
http://pastebin.com/f5f45c31f



Bootstrap
[pre]
<?php <br />
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

protected function _initAutoload()
{
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH));
return $moduleLoader;
}

function _initViewHelpers()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();

$view->doctype('XHTML1_STRICT');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$view->headTitle()->setSeparator(' - ');
$view->headTitle('Batman');
}

protected function _initSyslog()
{
// Zend_Log
//$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '../var/logs/zf_log.txt'); // Websites/akrabat/application/var/logs/
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/../var/logs/zf_log.txt'); // Websites/akrabat/var/logs/

$logger = new Zend_Log($writer);
Zend_Registry::set('logger', $logger);
}

}
[/pre]



Edit view page
[pre]


<center>View script for controller index and script/action name edit</center>

<?php echo $this->form; ?>

<?php <br />
/*
$writer = new Zend_Log_Writer_Stream('../var/logs/zf_log.txt'); // Websites/akrabat/var/logs/
$logger = new Zend_Log($writer);
$logger->log('message to yoda1', Zend_Log::EMERG);
*/


$logger = Zend_Registry::get('logger');
$logger->log('message to yoda 3', Zend_Log::EMERG);


// Zend_Debug::dump(APPLICATION_PATH . '/../var/logs/boogieman.txt');



?>
[/pre]
lsco (2) [Avatar] Offline
#12
Re: How do you put Zend_Log into bootstrap correctly?
Hi Apprentice

Thanks for the informative post. I can't bring myself to join another mailing list as the need to constantly monitor chatter to extract the pearl's of wisdom is a chore. There is definitely the benefit of getting questions answered by the "elite programmers" smilie

Then again if the published examples and documentation were a little more fleshed out the mailing list members would get less annoying requests about the same stuff over and over. Anyone posting to a mailing list knows you get either of two responses, a friendly one (often far too rare) or the RTFM N00B! one.

This forum is now one of the only places to find a working Zend_Log bootstrap example, searching the mailing lists is a pain and they obviously don't get spidered too well.

Personally I've been making efforts to return to places where I found a dead end and report on what allowed me to get past that point. Doctrine ORM was a prime example, I had an old example that no longer applied, a confusing example that didn't quite work and a textual explanation of why that didn't work... the solution was left for me to integrate it all and spend hours messing around.

Again thanks for providing your examples.

Manning should get vBulletin smilie

Elton
apprentice (77) [Avatar] Offline
#13
Re: How do you put Zend_Log into bootstrap correctly?
vBulletin would be great Sitepoint uses it and look how many active members there are.


Around 2500 people when I surfed over there.



I wish Rob would have published for Sitepoint instead of Manning then the ZF community would've exploded much more quickly. Dinosaur Manning! smilie







1st edit

(my smiley isn't even working like it did from the previous post)



2nd edit

(now it worked after my 1st edit where nothing was changed, it's so Manning.)