Log.class.doc

Documentation for Log.class.php Class

Author: Alberto Miranda




Basic functionality:

Log class is a basic logging engine you can instantiate inside any of your scripts
to write any text output to a text file.

Log class also provides you with some built in functions to accelerate log
creation and output formatting.

It features automatic dir and file creation and can operate in "one file per log"
or "only one file" modes.

You can easily log formatted date and Log class will automatically track
each log number using a single text file counter.

You can have as many logs as you like in different directories or in the same one,
each one with its individual counter.


Global variables:
var $logDir="";
Stores the directory specified when you create the class object.

var $logFile="";
Specifies the log filename. It will be created inside logDir.

var $countFile="";
Specifies the counter filename. It will be created inside logDir.

var $headerTitle="";
Used to create the log Header title, which is a text written in
the first lines of logFile that helps identifying its content.

var $logMode="";
"oneFile": This is the default value. It indicates the class to use
a single file for all logs. Each time a new Log is created,
contents will be appended at the end of the logFile.
"oneFilePerLog": It indicates the class to use multiple files.
One file per log will be used. Each time a new Log is created
a new autonumerated file will be created in logDir.

var $logNumber="";
Indicates actual log number, read from counter file in logDir and
incremented by one each time a Log is created.

Methods:
function Log($logDir='log', $logFile='log_', $headerTitle='LOG', $logMode='oneFile', $countFile='counter')
Class constructor. Determines the log dir, log filename, header title and log mode
for the current log proccess. See description of global variables for more details.


function writeLog($logString)
This method (or function, as you wish) is used internally and was not meant for
direct use, but it will also work. It writes $logString directly to logFile in logDir.


function logThis($string,$modifier="empty")
This is the intended method for using all the time to log content.
$string: String message to write to logFile.
$modifier:
"empty": Appends "\n", new line character, to $string.
"2n": Appends two "\n" to $string.
"3n": Appends three "\n" to $string.
"line": Writes a hardcoded "line" after $string. Actually a "-" line.
"2line": Writes two "line" separators after $string.
"nLine": Writes "\n" and a "line" separator after $string
"2nLine": Writes two "\n" and a "line" separator after $string
"n2Line": Writes "\n" and two "line" separators after $string
$string functions or "log functions":
When using log function, passed in the $string variable, $modifier
is not used.

"f:line": Writes a "line" separator to logFile.
"f:2line": Writes two "line" separators to logFile.
"f:nl": Writes a new line character, "\n", to logFile.
"f:logNumber": Writes actual log number to logFile.
"f:counter": Will use an internal counter which will increment its value
each time it is writen to logFile. Not using any separation from content.
"f:counter.nl": Internal counter followed by "\n" character.
"f:nl.counter": Internal counter preceded by "\n" charecter.
"f:nl.counter.nl": Internal counter between "\n" characters.
function get_formatted_date()
Ouputs formatted date.
Example output: 28.08.2005 - 01:14


function rmdirr($dirname)
Originally written by Aidan Lister. Thanks Aidan!
Deletes a directory and all of its content, iterating thru subfolders
(yes, it deletes ALL). It is used by Log class to delete (or clean) logDir and
all of its contents.


function clean()
It will call rmdirr() method to completely delete logDir and log content.
Just does this: $this->rmdirr($this->logDir);



Alberto Miranda
November 19, 2005 - Banfield, Buenos Aires, Argentina.

Updated on July 27, 2007
Added $countFile parameter to constructor and some new modifiers.
Modified basic functionality description.