mirror of
https://github.com/atlanticbiomedical/portal-legacy.git
synced 2025-07-02 01:47:28 -04:00
initial commit
This commit is contained in:
76
lib/symfony/log/sfLogger/sfFileLogger.class.php
Executable file
76
lib/symfony/log/sfLogger/sfFileLogger.class.php
Executable file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the symfony package.
|
||||
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package symfony
|
||||
* @subpackage log
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id: sfFileLogger.class.php 3329 2007-01-23 08:29:34Z fabien $
|
||||
*/
|
||||
class sfFileLogger
|
||||
{
|
||||
protected
|
||||
$fp = null;
|
||||
|
||||
/**
|
||||
* Initializes the file logger.
|
||||
*
|
||||
* @param array Options for the logger
|
||||
*/
|
||||
public function initialize($options = array())
|
||||
{
|
||||
if (!isset($options['file']))
|
||||
{
|
||||
throw new sfConfigurationException('File option is mandatory for a file logger');
|
||||
}
|
||||
|
||||
$dir = dirname($options['file']);
|
||||
|
||||
if (!is_dir($dir))
|
||||
{
|
||||
mkdir($dir, 0777, 1);
|
||||
}
|
||||
|
||||
if (!is_writable($dir) || (file_exists($options['file']) && !is_writable($options['file'])))
|
||||
{
|
||||
throw new sfFileException(sprintf('Unable to open the log file "%s" for writing', $options['file']));
|
||||
}
|
||||
|
||||
$this->fp = fopen($options['file'], 'a');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message.
|
||||
*
|
||||
* @param string Message
|
||||
* @param string Message priority
|
||||
* @param string Message priority name
|
||||
*/
|
||||
public function log($message, $priority, $priorityName)
|
||||
{
|
||||
$line = sprintf("%s %s [%s] %s%s", strftime('%b %d %H:%M:%S'), 'symfony', $priorityName, $message, DIRECTORY_SEPARATOR == '\\' ? "\r\n" : "\n");
|
||||
|
||||
flock($this->fp, LOCK_EX);
|
||||
fwrite($this->fp, $line);
|
||||
flock($this->fp, LOCK_UN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the shutdown method.
|
||||
*/
|
||||
public function shutdown()
|
||||
{
|
||||
if ($this->fp)
|
||||
{
|
||||
fclose($this->fp);
|
||||
}
|
||||
}
|
||||
}
|
95
lib/symfony/log/sfLogger/sfWebDebugLogger.class.php
Executable file
95
lib/symfony/log/sfLogger/sfWebDebugLogger.class.php
Executable file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the symfony package.
|
||||
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package symfony
|
||||
* @subpackage log
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id: sfWebDebugLogger.class.php 3329 2007-01-23 08:29:34Z fabien $
|
||||
*/
|
||||
class sfWebDebugLogger
|
||||
{
|
||||
protected
|
||||
$webDebug = null;
|
||||
|
||||
/**
|
||||
* Initializes the web debug logger.
|
||||
*
|
||||
* @param array Logger options
|
||||
*/
|
||||
public function initialize($options = array())
|
||||
{
|
||||
if (!sfConfig::get('sf_web_debug'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->webDebug = sfWebDebug::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message.
|
||||
*
|
||||
* @param string Message
|
||||
* @param string Message priority
|
||||
* @param string Message priority name
|
||||
*/
|
||||
public function log($message, $priority, $priorityName)
|
||||
{
|
||||
if (!sfConfig::get('sf_web_debug'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// if we have xdebug, add some stack information
|
||||
$debug_stack = array();
|
||||
if (function_exists('xdebug_get_function_stack'))
|
||||
{
|
||||
foreach (xdebug_get_function_stack() as $i => $stack)
|
||||
{
|
||||
if (
|
||||
(isset($stack['function']) && !in_array($stack['function'], array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug', 'log')))
|
||||
|| !isset($stack['function'])
|
||||
)
|
||||
{
|
||||
$tmp = '';
|
||||
if (isset($stack['function']))
|
||||
{
|
||||
$tmp .= 'in "'.$stack['function'].'" ';
|
||||
}
|
||||
$tmp .= 'from "'.$stack['file'].'" line '.$stack['line'];
|
||||
$debug_stack[] = $tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get log type in {}
|
||||
$type = 'sfOther';
|
||||
if (preg_match('/^\s*{([^}]+)}\s*(.+?)$/', $message, $matches))
|
||||
{
|
||||
$type = $matches[1];
|
||||
$message = $matches[2];
|
||||
}
|
||||
|
||||
// build the object containing the complete log information.
|
||||
$logEntry = array(
|
||||
'priority' => $priority,
|
||||
'priorityString' => $priorityName,
|
||||
'time' => time(),
|
||||
'message' => $message,
|
||||
'type' => $type,
|
||||
'debugStack' => $debug_stack,
|
||||
);
|
||||
|
||||
// send the log object.
|
||||
$this->webDebug->log($logEntry);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user