Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

The example CakePHP DatabaseLogger as a repository

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 config
Octocat-spinner-32 libs
Octocat-spinner-32 models
Octocat-spinner-32 README.textile
Octocat-spinner-32 database_logger_app_model.php
README.textile

DatabaseLogger Plugin

Log anything in CakePHP to the database.

Background

This is mostly a project to experiment with loggers, and perhaps provide alternatives to the ways in which I can check on my own application’s errors. It’s also the result of looking at how the CakePHP docs explain creating your own loggers.

Requirements

  • PHP5 For those who cannot correctly configure the plugin
  • CakePHP 1.3

Installation

[Manual]

  1. Download this: http://github.com/josegonzalez/database_logger/zipball/master
  2. Unzip that download.
  3. Copy the resulting folder to app/plugins
  4. Rename the folder you just copied to database_logger

[GIT Submodule]

In your app directory type:

git submodule add git://github.com/josegonzalez/database_logger.git plugins/database_logger
git submodule init
git submodule update

[GIT Clone]

In your plugin directory type

git clone git://github.com/josegonzalez/database_logger.git database_logger

Usage

You’ll need to run either the migration for this plugin, the schema.php, or run the schema.sql on your SQL database before proceeding. Note that the default schema is for a logs table.

Once this is complete, you should create a custom database connection for the logger. This is to ensure that CakePHP’s resultset isn’t broken by logging mechanisms. Please note that this means you will have two connections open at any one time. Unfortunately, there is no way around this limitation due to the CakePHP dbo_source.php internals. The following is an example of what you should put in your database.php


var $database_logger = array(
	'driver'        => 'mysql',
	'persistent'    => false,
	'host'          => 'localhost',
	'login'         => 'user',
	'password'      => 'password',
	'database'      => 'database',
	'prefix'        => '',
	'encoding'      => 'utf8',
);

To configure the plugin, setup the logger in either your core.php or bootstrap.php as follows:

CakeLog::config('LOG_TYPE', array(
	'engine' => 'DatabaseLogger.DatabaseLogger',
	'modelName' => '@LOG_MODEL_NAME@',
	'datasource' => 'database_logger',
	'table' => 'logs',
));

The LOG_TYPE can be set to anything you wish, like lollipop or default. The modelName key defaults to Log, and can be left off if that is desired. Note that the table name will be logs in this case, as the plugin uses a simple ClassRegistry::init() call to instantiate the model.

Options

  1. modelName : Name of the model to use for logs. Defaults to Log

Todo

  • Testing
  • Administration panel for viewing logs

License

Copyright © 2011 Jose Diaz-Gonzalez

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Something went wrong with that request. Please try again.