CakePHP Database Logger Plugin
Please Support:
CakePHP Database Logger
Info:
- Version: 2.0
- Requirements: CakePHP 1.3/2.x
- Docs: CakePHP Database Logger API
- Article: CakePHP Database Logger Discussion and Examples
Watch:
Get it:
- Download Now
- git clone git://github.com/webtechnick/CakePHP-DatabaseLogger-Plugin database_logger
It's been a while since I've posted, I've been doing a lot of work on various fun projects and just haven't had the time to formally post about all the cool things I've been doing. I figured with a new plugin deserves a new blog post. So, here I am -- lets talk log files and how they suck.
For example:
Will write to /tmp/logs/error.log
This is all well and good if you're running your application on a single server, and you're a masochist who likes to copy over large log files, and open them up in an editor to actually search through it.
However, even though I'm a web developer, I'm not a masochist -- despite popular opinion. So I've developed a super simple plugin to take all those handy dandy log messages scattered around an application and save them to a database logs table instead. The benefit of this strategy is three fold.
1) Scale-ability -- as you add more app servers to handle traffic you're logs will still all be consolidated in one place.
2) Easier searches, with the built in admin interface searching through logs can be done directly in the app.
3) Free extra information with each log entry. With each log entry the requesting url, hostname, ip, and referrer is automatically logged along side it.
Next, you'll need to add two lines to your app/config/bootstrap.php file to configure your CakeLog to log to the new database logger instead of the default FileLog.
Navigate to http://www.example.com/admin/database_logger/logs to view/search/delete your logs.
Enjoy!
Log files.. more like lame files
Log files can be handy, they can serve as a barometer for how well your app is operating, and give you some clue as to how your users are using your app (or more importantly -- breaking your app). The default CakeLog settings writes log entries to a file in your /tmp/logs/ directory under the type of log you're specifying.For example:
- CakeLog::write('error', 'This will be a new entry in the /tmp/logs/error.log file');
Will write to /tmp/logs/error.log
This is all well and good if you're running your application on a single server, and you're a masochist who likes to copy over large log files, and open them up in an editor to actually search through it.
However, even though I'm a web developer, I'm not a masochist -- despite popular opinion. So I've developed a super simple plugin to take all those handy dandy log messages scattered around an application and save them to a database logs table instead. The benefit of this strategy is three fold.
1) Scale-ability -- as you add more app servers to handle traffic you're logs will still all be consolidated in one place.
2) Easier searches, with the built in admin interface searching through logs can be done directly in the app.
3) Free extra information with each log entry. With each log entry the requesting url, hostname, ip, and referrer is automatically logged along side it.
Setup
Setup is simple. Like any other plugin you'll need to clone the repository into your app/plugins/database_logger directory, and run the schema into the database to create the required logs table.- # clone plugin
- git clone git://github.com/webtechnick/CakePHP-DatabaseLogger-Plugin.git app/plugins/database_logger
- # run schema into database to create logs table.
- cake schema create database_logger -plugin database_logger
Next, you'll need to add two lines to your app/config/bootstrap.php file to configure your CakeLog to log to the new database logger instead of the default FileLog.
- //app/config/bootstrap.php
- App::import('Core','CakeLog');
Usage
Anywhere in your app where you call $this->log() or CakeLog::write the database logger will be used.- CakeLog::write('error', 'This is a detailed message logged to the database');
Navigate to http://www.example.com/admin/database_logger/logs to view/search/delete your logs.
Enjoy!