mirror of
https://github.com/brmlab/brmbiolab_sklad.git
synced 2025-06-08 05:04:02 +02:00
Initial commit
This commit is contained in:
commit
3b93da31de
1004 changed files with 265840 additions and 0 deletions
67
lib/Cake/Log/Engine/BaseLog.php
Normal file
67
lib/Cake/Log/Engine/BaseLog.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
/**
|
||||
* Base Log Engine class
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||
* @package Cake.Log.Engine
|
||||
* @since CakePHP(tm) v 2.2
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('CakeLogInterface', 'Log');
|
||||
|
||||
/**
|
||||
* Base log engine class.
|
||||
*
|
||||
* @package Cake.Log.Engine
|
||||
*/
|
||||
abstract class BaseLog implements CakeLogInterface {
|
||||
|
||||
/**
|
||||
* Engine config
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_config = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $config Configuration array
|
||||
*/
|
||||
public function __construct($config = array()) {
|
||||
$this->config($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets instance config. When $config is null, returns config array
|
||||
*
|
||||
* Config
|
||||
*
|
||||
* - `types` string or array, levels the engine is interested in
|
||||
* - `scopes` string or array, scopes the engine is interested in
|
||||
*
|
||||
* @param array $config engine configuration
|
||||
* @return array
|
||||
*/
|
||||
public function config($config = array()) {
|
||||
if (!empty($config)) {
|
||||
foreach (array('types', 'scopes') as $option) {
|
||||
if (isset($config[$option]) && is_string($config[$option])) {
|
||||
$config[$option] = array($config[$option]);
|
||||
}
|
||||
}
|
||||
$this->_config = $config;
|
||||
}
|
||||
return $this->_config;
|
||||
}
|
||||
|
||||
}
|
85
lib/Cake/Log/Engine/ConsoleLog.php
Normal file
85
lib/Cake/Log/Engine/ConsoleLog.php
Normal file
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
/**
|
||||
* Console Logging
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||
* @package Cake.Log.Engine
|
||||
* @since CakePHP(tm) v 2.2
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('BaseLog', 'Log/Engine');
|
||||
App::uses('ConsoleOutput', 'Console');
|
||||
|
||||
/**
|
||||
* Console logging. Writes logs to console output.
|
||||
*
|
||||
* @package Cake.Log.Engine
|
||||
*/
|
||||
class ConsoleLog extends BaseLog {
|
||||
|
||||
/**
|
||||
* Output stream
|
||||
*
|
||||
* @var ConsoleOutput
|
||||
*/
|
||||
protected $_output = null;
|
||||
|
||||
/**
|
||||
* Constructs a new Console Logger.
|
||||
*
|
||||
* Config
|
||||
*
|
||||
* - `types` string or array, levels the engine is interested in
|
||||
* - `scopes` string or array, scopes the engine is interested in
|
||||
* - `stream` the path to save logs on.
|
||||
* - `outputAs` integer or ConsoleOutput::[RAW|PLAIN|COLOR]
|
||||
*
|
||||
* @param array $config Options for the FileLog, see above.
|
||||
* @throws CakeLogException
|
||||
*/
|
||||
public function __construct($config = array()) {
|
||||
parent::__construct($config);
|
||||
if (DS === '\\' && !(bool)env('ANSICON')) {
|
||||
$outputAs = ConsoleOutput::PLAIN;
|
||||
} else {
|
||||
$outputAs = ConsoleOutput::COLOR;
|
||||
}
|
||||
$config = Hash::merge(array(
|
||||
'stream' => 'php://stderr',
|
||||
'types' => null,
|
||||
'scopes' => array(),
|
||||
'outputAs' => $outputAs,
|
||||
), $this->_config);
|
||||
$config = $this->config($config);
|
||||
if ($config['stream'] instanceof ConsoleOutput) {
|
||||
$this->_output = $config['stream'];
|
||||
} elseif (is_string($config['stream'])) {
|
||||
$this->_output = new ConsoleOutput($config['stream']);
|
||||
} else {
|
||||
throw new CakeLogException('`stream` not a ConsoleOutput nor string');
|
||||
}
|
||||
$this->_output->outputAs($config['outputAs']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements writing to console.
|
||||
*
|
||||
* @param string $type The type of log you are making.
|
||||
* @param string $message The message you want to log.
|
||||
* @return bool success of write.
|
||||
*/
|
||||
public function write($type, $message) {
|
||||
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $message . "\n";
|
||||
return $this->_output->write(sprintf('<%s>%s</%s>', $type, $output, $type), false);
|
||||
}
|
||||
|
||||
}
|
220
lib/Cake/Log/Engine/FileLog.php
Normal file
220
lib/Cake/Log/Engine/FileLog.php
Normal file
|
@ -0,0 +1,220 @@
|
|||
<?php
|
||||
/**
|
||||
* File Storage stream for Logging
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||
* @package Cake.Log.Engine
|
||||
* @since CakePHP(tm) v 1.3
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('BaseLog', 'Log/Engine');
|
||||
App::uses('Hash', 'Utility');
|
||||
App::uses('CakeNumber', 'Utility');
|
||||
|
||||
/**
|
||||
* File Storage stream for Logging. Writes logs to different files
|
||||
* based on the type of log it is.
|
||||
*
|
||||
* @package Cake.Log.Engine
|
||||
*/
|
||||
class FileLog extends BaseLog {
|
||||
|
||||
/**
|
||||
* Default configuration values
|
||||
*
|
||||
* @var array
|
||||
* @see FileLog::__construct()
|
||||
*/
|
||||
protected $_defaults = array(
|
||||
'path' => LOGS,
|
||||
'file' => null,
|
||||
'types' => null,
|
||||
'scopes' => array(),
|
||||
'rotate' => 10,
|
||||
'size' => 10485760, // 10MB
|
||||
'mask' => null,
|
||||
);
|
||||
|
||||
/**
|
||||
* Path to save log files on.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_path = null;
|
||||
|
||||
/**
|
||||
* Log file name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_file = null;
|
||||
|
||||
/**
|
||||
* Max file size, used for log file rotation.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_size = null;
|
||||
|
||||
/**
|
||||
* Constructs a new File Logger.
|
||||
*
|
||||
* Config
|
||||
*
|
||||
* - `types` string or array, levels the engine is interested in
|
||||
* - `scopes` string or array, scopes the engine is interested in
|
||||
* - `file` Log file name
|
||||
* - `path` The path to save logs on.
|
||||
* - `size` Used to implement basic log file rotation. If log file size
|
||||
* reaches specified size the existing file is renamed by appending timestamp
|
||||
* to filename and new log file is created. Can be integer bytes value or
|
||||
* human reabable string values like '10MB', '100KB' etc.
|
||||
* - `rotate` Log files are rotated specified times before being removed.
|
||||
* If value is 0, old versions are removed rather then rotated.
|
||||
* - `mask` A mask is applied when log files are created. Left empty no chmod
|
||||
* is made.
|
||||
*
|
||||
* @param array $config Options for the FileLog, see above.
|
||||
*/
|
||||
public function __construct($config = array()) {
|
||||
$config = Hash::merge($this->_defaults, $config);
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets protected properties based on config provided
|
||||
*
|
||||
* @param array $config Engine configuration
|
||||
* @return array
|
||||
*/
|
||||
public function config($config = array()) {
|
||||
parent::config($config);
|
||||
|
||||
if (!empty($config['path'])) {
|
||||
$this->_path = $config['path'];
|
||||
}
|
||||
if (Configure::read('debug') && !is_dir($this->_path)) {
|
||||
mkdir($this->_path, 0775, true);
|
||||
}
|
||||
|
||||
if (!empty($config['file'])) {
|
||||
$this->_file = $config['file'];
|
||||
if (substr($this->_file, -4) !== '.log') {
|
||||
$this->_file .= '.log';
|
||||
}
|
||||
}
|
||||
if (!empty($config['size'])) {
|
||||
if (is_numeric($config['size'])) {
|
||||
$this->_size = (int)$config['size'];
|
||||
} else {
|
||||
$this->_size = CakeNumber::fromReadableSize($config['size']);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements writing to log files.
|
||||
*
|
||||
* @param string $type The type of log you are making.
|
||||
* @param string $message The message you want to log.
|
||||
* @return bool success of write.
|
||||
*/
|
||||
public function write($type, $message) {
|
||||
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $message . "\n";
|
||||
$filename = $this->_getFilename($type);
|
||||
if (!empty($this->_size)) {
|
||||
$this->_rotateFile($filename);
|
||||
}
|
||||
|
||||
$pathname = $this->_path . $filename;
|
||||
if (empty($this->_config['mask'])) {
|
||||
return file_put_contents($pathname, $output, FILE_APPEND);
|
||||
}
|
||||
|
||||
$exists = file_exists($pathname);
|
||||
$result = file_put_contents($pathname, $output, FILE_APPEND);
|
||||
static $selfError = false;
|
||||
if (!$selfError && !$exists && !chmod($pathname, (int)$this->_config['mask'])) {
|
||||
$selfError = true;
|
||||
trigger_error(__d(
|
||||
'cake_dev', 'Could not apply permission mask "%s" on log file "%s"',
|
||||
array($this->_config['mask'], $pathname)), E_USER_WARNING);
|
||||
$selfError = false;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filename
|
||||
*
|
||||
* @param string $type The type of log.
|
||||
* @return string File name
|
||||
*/
|
||||
protected function _getFilename($type) {
|
||||
$debugTypes = array('notice', 'info', 'debug');
|
||||
|
||||
if (!empty($this->_file)) {
|
||||
$filename = $this->_file;
|
||||
} elseif ($type === 'error' || $type === 'warning') {
|
||||
$filename = 'error.log';
|
||||
} elseif (in_array($type, $debugTypes)) {
|
||||
$filename = 'debug.log';
|
||||
} else {
|
||||
$filename = $type . '.log';
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate log file if size specified in config is reached.
|
||||
* Also if `rotate` count is reached oldest file is removed.
|
||||
*
|
||||
* @param string $filename Log file name
|
||||
* @return mixed True if rotated successfully or false in case of error.
|
||||
* Void if file doesn't need to be rotated.
|
||||
*/
|
||||
protected function _rotateFile($filename) {
|
||||
$filepath = $this->_path . $filename;
|
||||
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
|
||||
clearstatcache(true, $filepath);
|
||||
} else {
|
||||
clearstatcache();
|
||||
}
|
||||
|
||||
if (!file_exists($filepath) ||
|
||||
filesize($filepath) < $this->_size
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->_config['rotate'] === 0) {
|
||||
$result = unlink($filepath);
|
||||
} else {
|
||||
$result = rename($filepath, $filepath . '.' . time());
|
||||
}
|
||||
|
||||
$files = glob($filepath . '.*');
|
||||
if ($files) {
|
||||
$filesToDelete = count($files) - $this->_config['rotate'];
|
||||
while ($filesToDelete > 0) {
|
||||
unlink(array_shift($files));
|
||||
$filesToDelete--;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
158
lib/Cake/Log/Engine/SyslogLog.php
Normal file
158
lib/Cake/Log/Engine/SyslogLog.php
Normal file
|
@ -0,0 +1,158 @@
|
|||
<?php
|
||||
/**
|
||||
* Syslog logger engine for CakePHP
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||
* @package Cake.Log.Engine
|
||||
* @since CakePHP(tm) v 2.4
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('BaseLog', 'Log/Engine');
|
||||
|
||||
/**
|
||||
* Syslog stream for Logging. Writes logs to the system logger
|
||||
*
|
||||
* @package Cake.Log.Engine
|
||||
*/
|
||||
class SyslogLog extends BaseLog {
|
||||
|
||||
/**
|
||||
* By default messages are formatted as:
|
||||
* type: message
|
||||
*
|
||||
* To override the log format (e.g. to add your own info) define the format key when configuring
|
||||
* this logger
|
||||
*
|
||||
* If you wish to include a prefix to all messages, for instance to identify the
|
||||
* application or the web server, then use the prefix option. Please keep in mind
|
||||
* the prefix is shared by all streams using syslog, as it is dependent of
|
||||
* the running process. For a local prefix, to be used only by one stream, you
|
||||
* can use the format key.
|
||||
*
|
||||
* ## Example:
|
||||
*
|
||||
* {{{
|
||||
* CakeLog::config('error', array(
|
||||
* 'engine' => 'Syslog',
|
||||
* 'types' => array('emergency', 'alert', 'critical', 'error'),
|
||||
* 'format' => "%s: My-App - %s",
|
||||
* 'prefix' => 'Web Server 01'
|
||||
* ));
|
||||
* }}}
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_defaults = array(
|
||||
'format' => '%s: %s',
|
||||
'flag' => LOG_ODELAY,
|
||||
'prefix' => '',
|
||||
'facility' => LOG_USER
|
||||
);
|
||||
|
||||
/**
|
||||
* Used to map the string names back to their LOG_* constants
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_priorityMap = array(
|
||||
'emergency' => LOG_EMERG,
|
||||
'alert' => LOG_ALERT,
|
||||
'critical' => LOG_CRIT,
|
||||
'error' => LOG_ERR,
|
||||
'warning' => LOG_WARNING,
|
||||
'notice' => LOG_NOTICE,
|
||||
'info' => LOG_INFO,
|
||||
'debug' => LOG_DEBUG
|
||||
);
|
||||
|
||||
/**
|
||||
* Whether the logger connection is open or not
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_open = false;
|
||||
|
||||
/**
|
||||
* Make sure the configuration contains the format parameter, by default it uses
|
||||
* the error number and the type as a prefix to the message
|
||||
*
|
||||
* @param array $config Options list.
|
||||
*/
|
||||
public function __construct($config = array()) {
|
||||
$config += $this->_defaults;
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a message to syslog
|
||||
*
|
||||
* Map the $type back to a LOG_ constant value, split multi-line messages into multiple
|
||||
* log messages, pass all messages through the format defined in the configuration
|
||||
*
|
||||
* @param string $type The type of log you are making.
|
||||
* @param string $message The message you want to log.
|
||||
* @return bool success of write.
|
||||
*/
|
||||
public function write($type, $message) {
|
||||
if (!$this->_open) {
|
||||
$config = $this->_config;
|
||||
$this->_open($config['prefix'], $config['flag'], $config['facility']);
|
||||
$this->_open = true;
|
||||
}
|
||||
|
||||
$priority = LOG_DEBUG;
|
||||
if (isset($this->_priorityMap[$type])) {
|
||||
$priority = $this->_priorityMap[$type];
|
||||
}
|
||||
|
||||
$messages = explode("\n", $message);
|
||||
foreach ($messages as $message) {
|
||||
$message = sprintf($this->_config['format'], $type, $message);
|
||||
$this->_write($priority, $message);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the call to openlog() in order to run unit tests on it. This function
|
||||
* will initialize the connection to the system logger
|
||||
*
|
||||
* @param string $ident the prefix to add to all messages logged
|
||||
* @param int $options the options flags to be used for logged messages
|
||||
* @param int $facility the stream or facility to log to
|
||||
* @return void
|
||||
*/
|
||||
protected function _open($ident, $options, $facility) {
|
||||
openlog($ident, $options, $facility);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the call to syslog() in order to run unit tests on it. This function
|
||||
* will perform the actual write in the system logger
|
||||
*
|
||||
* @param int $priority Message priority.
|
||||
* @param string $message Message to log.
|
||||
* @return bool
|
||||
*/
|
||||
protected function _write($priority, $message) {
|
||||
return syslog($priority, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the logger connection
|
||||
*/
|
||||
public function __destruct() {
|
||||
closelog();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue