PHP Classes

PHP Log File Database: Log messages to files or to a MySQL database

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 640 All time: 4,978 This week: 100Up
Version License PHP version Categories
php-logger 1.0GNU General Publi...5PHP 5, Logging
Description 

Author

This class can log messages to files or to a MySQL database.

It can add to the log messages with different warning levels: error, warning, debug and information. Messages below a given warning level may be ignored.

The messages can be appended to a log file or stored in MySQL database table.

The log file name, message prefix, database connection details and the database table name are configurable parameters.

The class can retry writing to a log file a given number of times after a period if it fails for instance if the file is temporarily locked.

Picture of Junai Hassan
Name: Junai Hassan <contact>
Classes: 1 package by
Country: Saudi Arabia Saudi Arabia
Age: ???
All time rank: 296612 in Saudi Arabia Saudi Arabia
Week rank: 312 Up3 in Saudi Arabia Saudi Arabia Up

Recommendations

Create log files
I need to create log files about the user activity.

Example

<?php

error_reporting
(E_ALL);
ini_set('display_errors', '1');

include(
'logging.php');

$logger = new Logging();

$logger->set_location('D:\logs');

//jha-- file type could be DB, File, FileAndDB
$logger->set_type(Logging::FileAndDB);

//jha-- set 3 to log all only warning and errors
//jha-- remember logs added with level higher than this level will be logged only
$logger->set_level(Logging::Warning);

//jha-- set dtabase credentails
$logger->set_db_credentails('localhost','root', '', 'test_db');

//jha-- file type could be Fixed or Daily
$logger->set_file_name(Logging::Daily,'logs','.txt');

//jha-- this will be written
$logger->write('This is Error', Logging::Error);

//jha-- this will be written
$logger->write('This is Warning', Logging::Warning);

//jha-- this will not be written
$logger->write('This is Warning', Logging::Debug);

//jha-- this will not be written
$logger->write('This is Warning', Logging::Info);

//jha-- flush logs
$logger->flush(true, true);



  Files folder image Files  
File Role Description
Plain text file logging.php Class Class for logging
Accessible without login Plain text file logging_tester.php Example Example script to test logging class
Accessible without login Plain text file logs-20130501.txt Output Sample log file
Accessible without login Plain text file read-me.txt Doc. documentation
Accessible without login Plain text file test_db.sql Data SQL table script for database logging

 Version Control Unique User Downloads Download Rankings  
 0%
Total:640
This week:0
All time:4,978
This week:100Up