Project Members:
phpDBLogger
What
phpDBLogger is a very small and simple php database logging class. The logs are written to a database table and a web interface can be used to look at live logs.
Features
- Very simple class.
- Very small foot print, integrates easily into any PHP application.
- Minimal configuration, you can get it up and running in minutes and also start monitoring your logs
- Log tables can be created daily or hourly based on system load
- Logs can be classified into error, debug, warning, info and trace
- Additional data for the logs can be stored in either json or serialized format. For example if you are debugging some user and you want to log an error, you can also log the entire user object or array with that log.
- Tagging system. Every log can be tagged. For example, at the top level a log can be classified as Error. But you can also tag it with additional tags. Examples of tags are network error, database error, user error.
- Simple and intuitive web interface from which you can monitor your logs
cron script to periodically process the log tables. The cron script takes all the information and merges with the Master Log table so that you can analyze logs and tags later.
Requirements
- PHP ( apache and cli modules )
- PHP PDO Library
- Database: currently tested with MySQL 5.5
- jQuery and jQuery UI ( both are included in the package)
How it works
Hourly and Daily log tables
- You can choose to create log tables daily or hourly based on the volume of logs. This might help performance as we keep the log tables trimmed down.
- Daily log tables must work for most of us. All tables are created by the script.
- If you choose daily logging, tables like log_2013_03_28 will be created
- If you choose hourly logging, tables like log_2013_03_28_12 will be created
- Table names will have YYYY_MM_DD and YYYY_MM_DD_HH formats for easy identification
How to log
require 'phpDBLogger.php';
$log = new phpDBLogger();
$log->error("This is an error statement"); // log an error
$log->warning("This is a warning statement"); // log a warning
$log->info("This is an informational statement"); // log an info
$log->debug("This is a debug message"); // log a debug message
$log->trace("This is a trace message"); // log a trace message
Storing Data with the log
Along with the logs, you can store additional data in either json or serialized format ( see config.php option )
Data can be an object or an array and can be viewed from the web interface
Check examples.php for more
require 'phpDBLogger.php';
$log = new phpDBLogger();
// log an error with additional data
$log_data = array('firstname' => 'foo', 'lastname' => 'bar');
$log->data($log_data);
$log->error("This is an error with additional data");
Tagging
If you do not need fine grained tagging, you can ignore this section
- This is the top level of tags. It has 5 types Error, Debug, Warning, Info, Trace
- Every log will have one of the primary tags.
- Additionally each log can have a second set of tags.
- For example, lets say you logged an error. But now you want to classify what kind of error it is ( like database error, network error, wrong password )
- You can associate these tags with the log and later analyze them with the web interface
- All you need to do while logging is supply a comma separated list of tags
- If you use the tagging feature, you will have to set up the cron phpDBLogger_cron.php
How to Tag
require 'phpDBLogger.php';
$log = new phpDBLogger();
// log an error with tags
$log->tags('database,file_limit,link,performance problem');
$log->error("This is an error with additional tags");
Cron phpDBLogger_cron.php
- This script will process the log tables and merge them into the logs_master table
- It will NOT process the current log table
- It will read the logs, create any new tags and associate logs with tags
- We do not do this during logging to avoid performance penalties.
- During logging, only 1 row is written quickly to the table with minimal indexes.
- After processing a table, the table will either be deleted or renamed ( see config.php )
phpDBLogger tables
- phpDBLogger creates 3 main tables logs_master, tags, logs_tags
- All daily and hourly log tables will be processed by the cron phpDBLogger_cron.php and put into this table
- Any new tags encountered will be put into the tags table
- logs_tags will have association of a log with a tag
Web Interface
Getting Started
- Download phpDBLogger
- Create the database and database tables. Use create_tables.sql. This will create a database and 3 tables.
- Create a user with full access to phpDBLogger database and note down the password.
- Open the config.php file and update ( every config variable is explained )
Quickly try phpDBLogger
- If you want to try phpDBLogger quickly, you can use the insert_logs.php script to simulate database logging and then look at the web interface.
- Do all things in the Requirements Section first
- Run the insert_logs.php from the command prompt
- The script is set to run for 10 mins, it will start entering random number of logs into the table
- Let the script run
- Open a web browser and navigate to phpDBLogger/web/index.php
- You should be able to see the logs and updates will start appearing
- Click the Session Log to see when the new data is fetched
- Don’t forget to terminate the insert_logs.php, else it will run for 10 mins and stop
- If you want to see tagging, run the phpDBLogger_cron.php and give the name of the database table. phpDBLogger_cron.php log_2013_03_28
- We need to give the table name because by default, the cron will not process the current table
phpDBLogger
What
phpDBLogger is a very small and simple php database logging class. The logs are written to a database table and a web interface can be used to look at live logs.
Features
cron script to periodically process the log tables. The cron script takes all the information and merges with the Master Log table so that you can analyze logs and tags later.
Requirements
How it works
Hourly and Daily log tables
How to log
Storing Data with the log
Along with the logs, you can store additional data in either json or serialized format ( see config.php option )
Data can be an object or an array and can be viewed from the web interface
Check examples.php for more
Tagging
If you do not need fine grained tagging, you can ignore this section
Primary Tags
Secondary Tags
If you use the tagging feature, you will have to set up the cron phpDBLogger_cron.php
require 'phpDBLogger.php';
$log = new phpDBLogger();
// log an error with tags
$log->tags('database,file_limit,link,performance problem');
$log->error("This is an error with additional tags");
Cron phpDBLogger_cron.php
phpDBLogger tables
Web Interface
Getting Started
Quickly try phpDBLogger