| core_lang

# Class: Bs_Logger Source Location: /core/lang/Bs_Logger.class.php
### Class Overview
Is the interface to handle the log messages that occur during the execution of a program. #### Author(s): Sam Blum <at blueshoes dot org> #### Version: 4.3.$Revision: 1.2 $ $Date: 2003/08/18 20:23:48 $ #### Copyright: blueshoes.org | ### Variables $_APP $_bsDb $_logDir $_logProperty $_readyToLog $_targetDbOK $_targetDirOK | ### Methods Bs_Logger createLogTable dropLogTable getTargetStatus loadPropertyArray loadPropertyFile log setDb setDir test _init
### Inherited Variables | ### Inherited Methods
### Class Details [line 118] Is the interface to handle the log messages that occur during the execution of a program. Bs_Logger is not extended from Bs_Object to keep it more independent and to give Bs_Object the possibility to use this class itself. 2 goals: To be able to dynamically change the logging behavior, thus modify filtering add/remove log-targets. even with live systems. (something doesn't work? just log in, change the logger conf file, and see where the code goes through and what happens.) Use as little CPU as possable. Use After an include the pseudo static Object $Bs_Logger is immediately available and runs a default initialization routine (see below) that fetches the property file (see below) and sets the default log-dir and DB. Property file settings may be overriden with calls to setDir() and setDb(). Default Initialization Routine Try to include the property file 'Bs_Logger.conf.php' from $_SERVER['DOCUMENT_ROOT'] . '../Bs_Logger.conf.php'. If 'file' is an (active) output target in the property settings then set the log dir to $_SERVER['DOCUMENT_ROOT'] . '../bs_log/'. Create dir if not existing. If 'db' is an active output target AND the $GLOBALS['bsDb'] object is set <= for sam: really? AND? not OR? --andrej AND $this->_APP['db']['main'] is set use the dsn of $this->_APP['db']['main'] to connect to DB. NOTE: Point 3) may seems a little odd but is used to put the logs in DB Property File 2D Array full of information. Every entry represents a log target and an expression that is matched with the log message elements (the msg, msgType, phpFile, ...). If the expresion does *not* match, the next entry is taken for match. If match succeeds the log is written and if 'Hit And Quit' is TRUE the logger quits, otherwise the next entry is matched. The main structure of one entry in 'Bs_Logger.conf.php' is:
       $bs_logger_logProperty[] = array (
         'active'       => FALSE, // If this entry is active or not
         'hitNquit'     => FALSE, // 'Hit And Quit'. Stop looking for further hits if match is TRUE
         'target'       => '',    // One of 'file' or 'db'
         'targetName'   => '',    // file- or table- name (depens on target above)
         'regEx'        => 'return (preg_match("/aa.*$/i", $msg) OR eregi("error", $msgType));'
       )
The PHP-vars that you may use in the 'regEx' are : $msg, $msgType, $_line_, $_func_, $_file_ (Message, Meassage Type, PHP Line Nr., PHP Function Name and PHP File Name ) By modifying the Bs_Logger.conf.php file by hand or with the BS_LogAdmin.class.php tool we are able to take dynamically influence on the Logger.
     How it works:
     -------------
          Log-call ----*
                       |
                    +--V--------------------------------------+
                    |         Bs_Logger.class.php             |
                    |   Get global info like SID              |
              *-->  |   Filter 1 -match-> write to DB or File |
              |     |   Filter 2 -match-> write to DB or File |
              |     |      :                                  |
              |     |   Filter n -match-> write to DB or File |
       include once +-----------------------------------------+
              |
        +-----------------------------+
        |Bs_Logger.conf.php (Property)|
        | Holding filters and targets |
        +-----------------------------+
#### Tags:
version: | 4.3.$Revision: 1.2 $ $Date: 2003/08/18 20:23:48 $
copyright: | blueshoes.org
author: | Sam Blum <at blueshoes dot org>
[ Top ] ### Class Variables #### $_APP = [line 130] reference to the global settings array $APP.
Type: | array
[ Top ] #### $_bsDb = NULL [line 163] instance of subclassed BS_Db.
Type: | object
[ Top ] #### $_logDir = NULL [line 157] Dir to where to write the log-files.
Type: | string
[ Top ] #### $_logProperty = NULL [line 124] the property array (see text in header).
Type: | array
[ Top ] #### $_readyToLog = FALSE [line 137] used to indicate if logging is possible to the defined target. FALSE==Config file has not be read jet. Optimisation to avoid disk read when not used.
Type: | bool
[ Top ] #### $_targetDbOK = FALSE [line 151] used to indicate if logging is possible to the defined target. If FALSE see PHP error log. Can't log to file.
Type: | bool
[ Top ] #### $_targetDirOK = FALSE [line 144] used to indicate if logging is possible to the defined target. If FALSE see PHP error log. Can't log to file.
Type: | bool
[ Top ] ### Class Methods ### constructor Bs_Logger [line 170]
`Bs_Logger Bs_Logger( )`
Constructor See text in header. [ Top ] ### method createLogTable [line 383]
`void createLogTable( [mixed $tblName = ''], string $tableName)`
Creates the table for the log entries Connection to the DB must be OK (see setDb). A 'CREATE TABLE IF NOT EXISTS' will be used. NOTE: The table name must end with 'Log'. It will otherwise be appended. #### Tags:
see: | Bs_Logger::setDb()
#### Parameters:
string | $tableName | The table name to create. *Must* end with 'Log'
[ Top ] ### method dropLogTable [line 424]
`void dropLogTable( [mixed $tblName = ''], string $tableName)`
Drops the table for the log entries Connection to the DB must be OK (see setDb). A 'DROP TABLE IF EXISTS' will be used. NOTE: The table name must end with 'Log'. It will otherwise be appended. #### Tags:
see: | Bs_Logger::setDb()
#### Parameters:
string | $tableName | The table name to drop. *Must* end with 'Log'
[ Top ] ### method getTargetStatus [line 293]
`mixed getTargetStatus( [string $targetKey = NULL])`
Get the status of the target 'db' or 'dir'. If TURE target seams OK If FALSE then target had an error on init or is not used. #### Tags:
return: | bool or hash with bool value for the targets.
#### Parameters:
string | $targetKey | 'db' or 'dir' (optional if not set, returns hash)
[ Top ] ### method loadPropertyArray [line 474]
`bool loadPropertyArray( array $prop)`
#### Tags:
return: | TRUE
see: | $this->loadPropertyFile()
access: | public
#### Parameters:
array | $prop |
[ Top ] ### method loadPropertyFile [line 450]
`bool loadPropertyFile( string $fileAndPath)`
#### Tags:
return: | (see Bs_Error::getLastError() in case you get FALSE)
see: | Bs_Logger::loadPropertyArray(), Bs_Error::getLastError()
access: | public
#### Parameters:
string | $fileAndPath |
[ Top ] ### method log [line 220]
`void log( string $msg, string $msgType, int $_line_, [int $_func_ = '-?-'], [string $_file_ = '-?-'], [bool $test = FALSE])`
The log call #### Parameters:
string | $msg | Keep it short. DB will take max 255 char.
string | $msgType | You're free to set what you want, eg ERROR or WARNING or ...
int | $_line_ | The __LINE__
int | $_func_ | The function name (use __FUNCTION__ with PHP 4.3.0)
string | $_file_ | The __FILE__ (only basename will be stored)
bool | $test | (optional) Default is FALSE. If TRUE will not log; will only set the 'hit' hash.
[ Top ] ### method setDb [line 314]
`bool setDb( hash $dsn)`
Init the Logger with the DB to write the log-info. #### Tags:
return: | TRUE if OK FALSE on error.
see: | Bs_Error::getLastError()
#### Parameters:
hash | $dsn | DB Server Name hash.
[ Top ] ### method setDir [line 347]
`bool setDir( string $logDir)`
Init the Logger with the dir to write the log-files. #### Tags:
return: | TRUE if OK FALSE on error.
see: | Bs_Error::getLastError()
#### Parameters:
string | $logDir | full path (no file) to the log-dir.
[ Top ] ### method test [line 483]
`void test( mixed $msg, mixed $msgType, mixed $_line_, mixed $_func_, mixed $_file_, mixed $logProperty)`
[ Top ] ### method _init [line 178]
`void _init( )`
Init logger. Called on very first use. Reads config file in $_SERVER['DOCUMENT_ROOT'] [ Top ] Documentation generated on Mon, 29 Dec 2003 21:11:43 +0100 by phpDocumentor 1.2.3