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:
113
lib/symfony/log/sfLogManager.class.php
Executable file
113
lib/symfony/log/sfLogManager.class.php
Executable file
@ -0,0 +1,113 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Log manager
|
||||
*
|
||||
* @package symfony
|
||||
* @subpackage log
|
||||
* @author Joe Simms
|
||||
* @version SVN: $Id: sfLogManager.class.php 3329 2007-01-23 08:29:34Z fabien $
|
||||
**/
|
||||
class sfLogManager
|
||||
{
|
||||
/** the default period to rotate logs in days */
|
||||
const DEF_PERIOD = 7;
|
||||
|
||||
/** the default number of log historys to store, one history is created for every period */
|
||||
const DEF_HISTORY = 10;
|
||||
|
||||
/**
|
||||
* Rotates log file.
|
||||
*
|
||||
* @param string Application name
|
||||
* @param string Enviroment name
|
||||
* @param string Period
|
||||
* @param string History
|
||||
* @param boolean Override
|
||||
*
|
||||
* @author Joe Simms
|
||||
**/
|
||||
public static function rotate($app, $env, $period = null, $history = null, $override = false)
|
||||
{
|
||||
$logfile = $app.'_'.$env;
|
||||
$logdir = sfConfig::get('sf_log_dir');
|
||||
|
||||
// set history and period values if not passed to default values
|
||||
$period = isset($period) ? $period : self::DEF_PERIOD;
|
||||
$history = isset($history) ? $history : self::DEF_HISTORY;
|
||||
|
||||
// get todays date
|
||||
$today = date('Ymd');
|
||||
|
||||
// check history folder exists
|
||||
if (!is_dir($logdir.'/history'))
|
||||
{
|
||||
mkdir($logdir.'/history', 0777);
|
||||
}
|
||||
|
||||
// determine date of last rotation
|
||||
$logs = sfFinder::type('file')->ignore_version_control()->maxdepth(1)->name($logfile.'_*.log')->in($logdir.'/history/');
|
||||
$recentlog = is_array($logs) ? array_pop($logs) : null;
|
||||
|
||||
if ($recentlog)
|
||||
{
|
||||
// calculate date to rotate logs on
|
||||
$last_rotated_on = filemtime($recentlog);
|
||||
$rotate_on = date('Ymd', strtotime('+ '.$period.' days', $last_rotated_on));
|
||||
}
|
||||
else
|
||||
{
|
||||
// no rotation has occured yet
|
||||
$rotate_on = null;
|
||||
}
|
||||
|
||||
$src_log = $logdir.'/'.$logfile.'.log';
|
||||
$dest_log = $logdir.'/history/'.$logfile.'_'.$today.'.log';
|
||||
|
||||
// if rotate log on date doesn't exist, or that date is today, then rotate the log
|
||||
if (!$rotate_on || ($rotate_on == $today) || $override)
|
||||
{
|
||||
// create a lock file
|
||||
$lock_name = $app.'_'.$env.'.lck';
|
||||
touch(sfConfig::get('sf_root_dir').'/'.$lock_name);
|
||||
|
||||
// if log file exists rotate it
|
||||
if (file_exists($src_log))
|
||||
{
|
||||
// check if the log file has already been rotated today
|
||||
if (file_exists($dest_log))
|
||||
{
|
||||
// append log to existing rotated log
|
||||
$handle = fopen($dest_log, 'a');
|
||||
$append = file_get_contents($src_log);
|
||||
fwrite($handle, $append);
|
||||
}
|
||||
else
|
||||
{
|
||||
// copy log
|
||||
copy($src_log, $dest_log);
|
||||
}
|
||||
|
||||
// remove the log file
|
||||
unlink($src_log);
|
||||
|
||||
// get all log history files for this application and environment
|
||||
$new_logs = sfFinder::type('file')->ignore_version_control()->maxdepth(1)->name($logfile.'_*.log')->in($logdir.'/history/');
|
||||
|
||||
// if the number of logs in history exceeds history then remove the oldest log
|
||||
if (count($new_logs) > $history)
|
||||
{
|
||||
unlink($new_logs[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
242
lib/symfony/log/sfLogger.class.php
Executable file
242
lib/symfony/log/sfLogger.class.php
Executable file
@ -0,0 +1,242 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
define('SF_LOG_EMERG', 0); // System is unusable
|
||||
define('SF_LOG_ALERT', 1); // Immediate action required
|
||||
define('SF_LOG_CRIT', 2); // Critical conditions
|
||||
define('SF_LOG_ERR', 3); // Error conditions
|
||||
define('SF_LOG_WARNING', 4); // Warning conditions
|
||||
define('SF_LOG_NOTICE', 5); // Normal but significant
|
||||
define('SF_LOG_INFO', 6); // Informational
|
||||
define('SF_LOG_DEBUG', 7); // Debug-level messages
|
||||
|
||||
/**
|
||||
* sfLogger manages all logging in symfony projects.
|
||||
*
|
||||
* sfLogger can be configuration via the logging.yml configuration file.
|
||||
* Loggers can also be registered directly in the logging.yml configuration file.
|
||||
*
|
||||
* This level list is ordered by highest priority (SF_LOG_EMERG) to lowest priority (SF_LOG_DEBUG):
|
||||
* - EMERG: System is unusable
|
||||
* - ALERT: Immediate action required
|
||||
* - CRIT: Critical conditions
|
||||
* - ERR: Error conditions
|
||||
* - WARNING: Warning conditions
|
||||
* - NOTICE: Normal but significant
|
||||
* - INFO: Informational
|
||||
* - DEBUG: Debug-level messages
|
||||
*
|
||||
* @package symfony
|
||||
* @subpackage log
|
||||
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
* @version SVN: $Id: sfLogger.class.php 3329 2007-01-23 08:29:34Z fabien $
|
||||
*/
|
||||
class sfLogger
|
||||
{
|
||||
protected
|
||||
$loggers = array(),
|
||||
$level = SF_LOG_EMERG,
|
||||
$levels = array(
|
||||
SF_LOG_EMERG => 'emerg',
|
||||
SF_LOG_ALERT => 'alert',
|
||||
SF_LOG_CRIT => 'crit',
|
||||
SF_LOG_ERR => 'err',
|
||||
SF_LOG_WARNING => 'warning',
|
||||
SF_LOG_NOTICE => 'notice',
|
||||
SF_LOG_INFO => 'info',
|
||||
SF_LOG_DEBUG => 'debug',
|
||||
);
|
||||
|
||||
protected static
|
||||
$logger = null;
|
||||
|
||||
/**
|
||||
* Returns the sfLogger instance.
|
||||
*
|
||||
* @return object the sfLogger instance
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (!sfLogger::$logger)
|
||||
{
|
||||
// the class exists
|
||||
$class = __CLASS__;
|
||||
sfLogger::$logger = new $class();
|
||||
sfLogger::$logger->initialize();
|
||||
}
|
||||
|
||||
return sfLogger::$logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the logger.
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
$this->loggers = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the log level for the current logger instance.
|
||||
*
|
||||
* @return string Log level
|
||||
*/
|
||||
public function getLogLevel()
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a log level for the current logger instance.
|
||||
*
|
||||
* @param string Log level
|
||||
*/
|
||||
public function setLogLevel($level)
|
||||
{
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves current loggers.
|
||||
*
|
||||
* @return array List of loggers
|
||||
*/
|
||||
public function getLoggers()
|
||||
{
|
||||
return $this->loggers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a logger.
|
||||
*
|
||||
* @param string Logger name
|
||||
*/
|
||||
public function registerLogger($logger)
|
||||
{
|
||||
$this->loggers[] = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message.
|
||||
*
|
||||
* @param string Message
|
||||
* @param string Message priority
|
||||
*/
|
||||
public function log($message, $priority = SF_LOG_INFO)
|
||||
{
|
||||
if ($this->level < $priority)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->loggers as $logger)
|
||||
{
|
||||
$logger->log((string) $message, $priority, $this->levels[$priority]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an emerg message.
|
||||
*
|
||||
* @param string Message
|
||||
*/
|
||||
public function emerg($message)
|
||||
{
|
||||
$this->log($message, SF_LOG_EMERG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an alert message.
|
||||
*
|
||||
* @param string Message
|
||||
*/
|
||||
public function alert($message)
|
||||
{
|
||||
$this->log($message, SF_LOG_ALERT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a critical message.
|
||||
*
|
||||
* @param string Message
|
||||
*/
|
||||
public function crit($message)
|
||||
{
|
||||
$this->log($message, SF_LOG_CRIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an error message.
|
||||
*
|
||||
* @param string Message
|
||||
*/
|
||||
public function err($message)
|
||||
{
|
||||
$this->log($message, SF_LOG_ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a warning message.
|
||||
*
|
||||
* @param string Message
|
||||
*/
|
||||
public function warning($message)
|
||||
{
|
||||
$this->log($message, SF_LOG_WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a notice message.
|
||||
*
|
||||
* @param string Message
|
||||
*/
|
||||
public function notice($message)
|
||||
{
|
||||
$this->log($message, SF_LOG_NOTICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an info message.
|
||||
*
|
||||
* @param string Message
|
||||
*/
|
||||
public function info($message)
|
||||
{
|
||||
$this->log($message, SF_LOG_INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a debug message.
|
||||
*
|
||||
* @param string Message
|
||||
*/
|
||||
public function debug($message)
|
||||
{
|
||||
$this->log($message, SF_LOG_DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the shutdown procedure.
|
||||
*
|
||||
* Cleans up the current logger instance.
|
||||
*/
|
||||
public function shutdown()
|
||||
{
|
||||
foreach ($this->loggers as $logger)
|
||||
{
|
||||
if (method_exists($logger, 'shutdown'))
|
||||
{
|
||||
$logger->shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
$this->loggers = array();
|
||||
}
|
||||
}
|
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