PDA

View Full Version : Mini Mods - Dev Debug Log


sweede
04-22-2008, 10:00 PM
Introduction:
This is my basic logging mechanism used in two of my current vbulletin products.

Instead of writing a text file to the file system which may or may not have been the best thing to do, i instead wrote this small plugin to facilitate logging to a database table instead.

Install:
Upload the contents of the upload folder to your vbulletin root directory.
Install the product XML file.

Usage:
There are no options that need to be set (they should be turned on/off in your plugin code).

Main Class is called DebugLog. It has one class variable, product, and two class methods, set and log.

Log takes up to 4 arguments.
log($log, $location = '', $line = '', $extra = '' )
$log is the string, array or object of the data you wish to save.
$location is commonly the function or method that you are logging.
$line is commonly __LINE__ , but in a plugin this may or may not work,
so you can set this number manually if you wish
$extra is extra information about the data you are logging such as "should never be 0"
Set takes two arguments.
set($var, $value)
$var is the variable name (currently only product is a valid variable to set).
$value is the value you wish $var to be.
in your plugin, it is advisable to setup your own debug class wrapper around the DevLog class

class MyClass
{
var $D = '';

function SetupLog()
{
global $vbulletin;
if($vbulletin->options['MyProduct_debug_enable'] && class_exists("DebugLog"))
{
$this->D = new DebugLog();
$this->D->set("product", "MyProduct");
}
}

function debug($data,$location='',$line='',$extra='')
{
global $vbulletin;
if($vbulletin->options['MyProduct_debug_enable'] && class_exists("DebugLog"))
{
$this->D->log($data,$location,$line,$extra);
}
}
function MyMethod($bar)
{
$this->debug($bar,"MyMethod");
echo $bar . " + foo";
}
}

$obj = new MyClass;
$obj->SetupLog(); // You need to seed the product so that it logs can be sorted

$obj->debug($obj,"Class Object");
//Writes Class information to the log table.

$var = $obj->MyMethod("Frank");
$obj->debug($var,"Called MyMethod");
// Writes the value of $var to the log table

you can also call the class staticly
DebugLog::log($var);
You cannot set the product with this method so it defaults to devlog

Viewing Logs:
Admincp -> Devlog ->View Logs

This is -very very- basic and will gradually be expanded. As it currently is, it will be enough to assist in debugging current problems with my plugins.

ChangeLog
v0.1 - Release
v0.2 - Cosmetic - Added Line numbers to debug log output.

sweede
04-22-2008, 10:06 PM
Some images of the AdminCP area

sweede
04-22-2008, 10:13 PM
Reserved

Illidanz
04-23-2008, 02:50 PM
Very nice one, really cool

Thanks man

*clicks Install

sweede
04-23-2008, 03:03 PM
I've found it to be pretty usefull so far. I do regret the names that i chose though.. debuglog::log is kind of.. horrible :p

Next week i plan on really cracking a peice from the admin log viewer. Currently i added Line Numbering to it, and it looks pretty reasonable.