Log
[
class tree: Log
] [
index: Log
] [
all elements
]
Packages:
Analyzer
Base
Cache
Config
Container
Creator
Log
Memory
Pattern
Registry
Stat
Word
Source for file Log.php
Documentation is available at
Log.php
<?php
/**
* Mai_Log
*
* Copyright (C) 2009 Mai (Me Artificial Intelligence)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
@author
Wouter Bulten (wouterbulten@mai-ai.org)
*
@copyright
Copyright (C) 2009 Mai (Me Artificial Intelligence)
*
@license
http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
*
@link
http://www.launchpad.net/mai
*
*
@category
Mai
*
@package
Log
*
*/
/** Required files */
if
(
!
Mai
::
getAutoloader
(
))
{
//Log and http classes are needed
require_once
'Zend/Log/Writer/Stream.php'
;
if
(
Mai
::
getEnv
(
)
===
Mai
::
ENV_DEVELOPMENT
)
{
require_once
'Zend/Log/Writer/Firebug.php'
;
require_once
'Zend/Controller/Request/Http.php'
;
require_once
'Zend/Controller/Response/Http.php'
;
require_once
'Zend/Wildfire/Channel/HttpHeaders.php'
;
}
}
/**
* Mai_Log is a logger for Mai. Based on Zend_Log, firebug and firephp.
*
*
@author
Wouter Bulten (wouterbulten@mai-ai.org)
*
@copyright
Copyright (C) 2009 Mai (Me Artificial Intelligence)
*
@license
http://opensource.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3)
*
@link
http://www.launchpad.net/mai
*
*
@category
Mai
*
@package
Log
*
*/
class
Mai_Log
{
/**
*
@var
Mai_Log
Singleton instance
*/
protected
static
$_instance
;
/**
*
@var
Zend_Log
*/
protected
static
$_logger
;
/**
*
@var
Zend_Controller_Request_Http
*/
protected
static
$_request
;
/**
*
@var
Zend_Controller_Response_Http
*/
protected
static
$_response
;
/**
*
@var
Zend_Wildfire_Channel_HttpHeaders
*/
protected
static
$_channel
;
/*
* @var bool Status of the log process
*/
protected
static
$_init
=
false
;
/**
* Private constructor to prevent creation of this object.
* Creates a log object.
*
@return
void
*/
private
function
__construct
(
)
{
}
/**
* Retrieve singleton instance
*
@param
$creator
Creator of this class.
*
@return
Mai_Log
*/
public
static
function
getInstance
(
$creator
)
{
if
(
!
Mai
::
isInit
(
)
&&
!
(
$creator
instanceof
Mai
))
{
trigger_error
(
'Mai has not been setup yet. Please use Mai::init().'
,
E_USER_ERROR
)
;
}
if
(
null
===
self
::
$_instance
)
{
self
::
$_instance
=
new
self
(
)
;
}
return
self
::
$_instance
;
}
/**
* Create the required objects. Starts up the log process.
*
@param
$creator
Creator of this class.
*
@return
void
*/
public
static
function
init
(
$creator
)
{
self
::
getInstance
(
$creator
)
;
//Log to firePHP if env is development and firePHP is enabled.
if
(
Mai
::
getEnv
(
)
===
Mai
::
ENV_DEVELOPMENT
&&
Mai_Config
::
getVar
(
)
->
log
->
firephp
)
{
//Create new log object
$writer
=
new
Zend_Log_Writer_Firebug
(
)
;
self
::
$_logger
=
new
Zend_Log
(
$writer
)
;
//Create request and reponse object
self
::
$_request
=
new
Zend_Controller_Request_Http
(
)
;
self
::
$_response
=
new
Zend_Controller_Response_Http
(
)
;
//Create a new channel and set the request and response object
self
::
$_channel
=
Zend_Wildfire_Channel_HttpHeaders
::
getInstance
(
)
;
self
::
$_channel
->
setRequest
(
self
::
$_request
)
;
self
::
$_channel
->
setResponse
(
self
::
$_response
)
;
//Start buffer
ob_start
(
)
;
}
else
{
//Create a new log object
$writer
=
new
Zend_Log_Writer_Stream
(
Mai
::
baseDir
(
)
.
"/Mai/Log/Files/mai_log.log"
)
;
self
::
$_logger
=
new
Zend_Log
(
$writer
)
;
}
self
::
$_init
=
true
;
}
/**
* Send a info message to the log.
*
@return
Zend_Log
*/
public
static
function
info
(
$message
)
{
if
(
empty
(
$message
))
{
trigger_error
(
"Message is empty or not set."
,
E_USER_NOTICE
)
;
}
if
(
Mai_Config
::
getVar
(
)
->
log
->
enabled
&&
(
Mai
::
getEnv
(
)
===
Mai
::
ENV_DEVELOPMENT
||
Mai_Config
::
getVar
(
)
->
log
->
all
))
{
if
(
!
self
::
$_init
)
{
trigger_error
(
"Logger not yet started. Please use init() first."
,
E_USER_ERROR
)
;
}
self
::
$_logger
->
info
(
$message
)
;
}
}
/**
* Send output to the browser when firePHP is used.
*
@return
void
*/
public
static
function
flush
(
)
{
if
(
Mai
::
getEnv
(
)
===
Mai
::
ENV_DEVELOPMENT
&&
Mai_Config
::
getVar
(
)
->
log
->
firephp
)
{
if
(
!
self
::
$_init
)
{
trigger_error
(
"Logger not yet started. Please use init() first."
,
E_USER_ERROR
)
;
}
self
::
$_channel
->
flush
(
)
;
self
::
$_response
->
sendHeaders
(
)
;
}
}
/**
* Cloning of a singleton class is not allowed.
*
@return
void
*/
final
public
function
__clone
(
)
{
trigger_error
(
'Clone is not allowed.'
,
E_USER_ERROR
)
;
}
/**
* Function to prevent deserializing
*
@return
void
*/
public
function
__wakeup
(
)
{
trigger_error
(
'Deserializing is not allowed.'
,
E_USER_ERROR
)
;
}
}
Documentation generated on Mon, 27 Jul 2009 19:55:08 +0200 by
phpDocumentor 1.4.1