For one of my projects, I wanted to have a live view of the cake log file in the admin page. What started out as some hacked controller methods, turned into a plugin that can be inserted in any random cake app. Ingredients:
- a php implementation of the unix tail command, by Paul Gregg
- a session variable to keep track of what part of the log file has been sent
- some jquery code (using the periodicalupdater plugin) that adds new lines to a div element as they appear in the log file, scrolls down so the new content becomes visible
The online demo consist of a bare cake ‘install’ with the plugin dropped into the plugins directory. As you can see, there’s no models, views or controllers. Visiting the app will actually log some messages to the debug log. To monitor the log file, visit the plugin path.
I’ve also added two links that lets you add lines to the debug log.
The theoretical advantage of using a plugin is that you can simply drop the code in the plugins directory and voila! it works!
In practice, it’s quite annoying that plugins are similar to, but not exactly structured like cake apps. For example: images and js code should be placed in the vendors folder instead of webroot. Secondly: app_model.php and app_controller.php need to be prefixed by the (singular) plugin name.
Finally, it’s not clear how to integrate the plugin with your actual cake app. Like using the app’s authentication methods to only allow ‘admin’ users to view the log file.
I’m actually not sure a plugin is the right way of implementing an online ‘tail -f’. A component might do a better job. What do you think?
The plugin can be downloaded here.
Sick of obtaining low numbers of useless visitors for your website? Well i wish to tell you about a fresh underground tactic that makes me personally $900 on a daily basis on 100% AUTOPILOT. I possibly could be here all day and going into detail but why dont you simply check their website out? There is really a excellent video that explains everything. So if your serious about producing quick hard cash this is the website for you. Auto Traffic Avalanche