Automatic pass to convert with php-cs-fixer
This commit is contained in:
169
src/Logger.php
169
src/Logger.php
@@ -1,16 +1,18 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework;
|
||||
|
||||
/** The logger class permit to log the information from the soft
|
||||
* It allow to debug too
|
||||
*/
|
||||
/**
|
||||
* The logger class permit to log the information from the soft
|
||||
* It allow to debug too
|
||||
*/
|
||||
class Logger
|
||||
{
|
||||
/* The logger class can be used with :
|
||||
@@ -20,60 +22,81 @@ class Logger
|
||||
$d->logfile="/tmp/toto.log";
|
||||
$d->logwrite ("Super log default");
|
||||
$d->logwrite ("Super log DEBUG", $d::DEBUG);
|
||||
$d->logwrite ("Super log NOTICE", $d::NOTICE); */
|
||||
$d->logwrite ("Super log NOTICE", $d::NOTICE);
|
||||
*/
|
||||
// TODO : Add SQL support
|
||||
/** The method to log.
|
||||
Can be display, file, syslog, stderr, session
|
||||
Can be merged with a pipe : "display|syslog|file" or put in array */
|
||||
/**
|
||||
* The method to log.
|
||||
* Can be display, file, syslog, stderr, session
|
||||
* Can be merged with a pipe : "display|syslog|file" or put in array
|
||||
*/
|
||||
public $logtype = "stderr";
|
||||
/** For logtype=file, the filename to use */
|
||||
/**
|
||||
* For logtype=file, the filename to use
|
||||
*/
|
||||
public $logfile = false;
|
||||
/** Timezone use to save the logs */
|
||||
/**
|
||||
* Timezone use to save the logs
|
||||
*/
|
||||
public $timezone = "UTC";
|
||||
/** Minimum log level in the logs */
|
||||
/**
|
||||
* Minimum log level in the logs
|
||||
*/
|
||||
public $loglevelmin = LOG_NOTICE;
|
||||
/** In Syslog mode, the facility to use
|
||||
See http://fr2.php.net/manual/en/function.openlog.php for $syslogFacility */
|
||||
/**
|
||||
* In Syslog mode, the facility to use
|
||||
* See http://fr2.php.net/manual/en/function.openlog.php for $syslogFacility
|
||||
*/
|
||||
public $syslogFacility = LOG_USER;
|
||||
/** In Syslog, prefix the log by the text */
|
||||
/**
|
||||
* In Syslog, prefix the log by the text
|
||||
*/
|
||||
public $syslogPrefix = false;
|
||||
/** Remove X entries of backtrace to see the right file generating the error
|
||||
*/
|
||||
/**
|
||||
* Remove X entries of backtrace to see the right file generating the error
|
||||
*/
|
||||
public $backTraceSkip = 1;
|
||||
/** Display the backtrace in all the messages */
|
||||
/**
|
||||
* Display the backtrace in all the messages
|
||||
*/
|
||||
public $backtraceDisplay = false;
|
||||
|
||||
/** The priorities which can be used in the priorities
|
||||
LOG_EMERG system is unusable
|
||||
LOG_ALERT action must be taken immediately
|
||||
LOG_CRIT critical conditions
|
||||
LOG_ERR error conditions
|
||||
LOG_WARNING warning conditions
|
||||
LOG_NOTICE normal, but significant, condition
|
||||
LOG_INFO informational message
|
||||
LOG_DEBUG debug-level message */
|
||||
private $priorities = array(LOG_EMERG => "EMERG",
|
||||
/**
|
||||
* The priorities which can be used in the priorities
|
||||
* LOG_EMERG system is unusable
|
||||
* LOG_ALERT action must be taken immediately
|
||||
* LOG_CRIT critical conditions
|
||||
* LOG_ERR error conditions
|
||||
* LOG_WARNING warning conditions
|
||||
* LOG_NOTICE normal, but significant, condition
|
||||
* LOG_INFO informational message
|
||||
* LOG_DEBUG debug-level message
|
||||
*/
|
||||
private $priorities = [LOG_EMERG => "EMERG",
|
||||
LOG_ALERT => "ALERT",
|
||||
LOG_CRIT => "CRITICAL",
|
||||
LOG_ERR => "ERROR",
|
||||
LOG_WARNING => "WARNING",
|
||||
LOG_NOTICE => "NOTICE",
|
||||
LOG_INFO => "INFO",
|
||||
LOG_DEBUG => "DEBUG");
|
||||
LOG_DEBUG => "DEBUG"];
|
||||
|
||||
/** Catch all the messages raised by the PHP, in trigger_error
|
||||
Use the properties of the logger to save the logs */
|
||||
/**
|
||||
* Catch all the messages raised by the PHP, in trigger_error
|
||||
* Use the properties of the logger to save the logs
|
||||
*/
|
||||
public function catchAll()
|
||||
{
|
||||
set_error_handler(array(&$this, "errorHandler"));
|
||||
set_error_handler([&$this, "errorHandler"]);
|
||||
}
|
||||
|
||||
/** The error handler to log
|
||||
* @param integer $errno The error number to use
|
||||
* @param string $errstr The error message to save
|
||||
* @param string $errfile The file which generate the error
|
||||
* @param integer $errline The line where the error is generated
|
||||
*/
|
||||
/**
|
||||
* The error handler to log
|
||||
* @param integer $errno The error number to use
|
||||
* @param string $errstr The error message to save
|
||||
* @param string $errfile The file which generate the error
|
||||
* @param integer $errline The line where the error is generated
|
||||
*/
|
||||
public function errorHandler($errno, $errstr, $errfile, $errline)
|
||||
{
|
||||
if (!(error_reporting() & $errno)) {
|
||||
@@ -130,12 +153,14 @@ class Logger
|
||||
$this->log($priority, $errstr);
|
||||
}
|
||||
|
||||
/** Store a new message log in the log manager defined by $logtype
|
||||
The message can be multiple types. An array will be stored in textual form
|
||||
but it will accept only one depth.
|
||||
The $message is not fixed, you can pass the number of parameters you want
|
||||
@param integer|null $priority Priority to use
|
||||
@param mixed ...$message Message to log */
|
||||
/**
|
||||
* Store a new message log in the log manager defined by $logtype
|
||||
* The message can be multiple types. An array will be stored in textual form
|
||||
* but it will accept only one depth.
|
||||
* The $message is not fixed, you can pass the number of parameters you want
|
||||
* @param integer|null $priority Priority to use
|
||||
* @param mixed ...$message Message to log
|
||||
*/
|
||||
public function log($priority, $message)
|
||||
{
|
||||
if ($priority === null) {
|
||||
@@ -251,26 +276,28 @@ class Logger
|
||||
} elseif (is_array($this->logtype)) {
|
||||
$logsType = $this->logtype;
|
||||
}
|
||||
if (in_array("display", $logsType)) {
|
||||
if (in_array("display", $logsType, true)) {
|
||||
$this->logdisplay($msg, $priority);
|
||||
}
|
||||
if (in_array("stderr", $logsType)) {
|
||||
if (in_array("stderr", $logsType, true)) {
|
||||
$this->logstderr($msg, $priority);
|
||||
}
|
||||
if (in_array("file", $logsType)) {
|
||||
if (in_array("file", $logsType, true)) {
|
||||
$this->logfile($msg, $priority);
|
||||
}
|
||||
if (in_array("syslog", $logsType)) {
|
||||
if (in_array("syslog", $logsType, true)) {
|
||||
$this->logsyslog($msg, $priority);
|
||||
}
|
||||
if (in_array("session", $logsType)) {
|
||||
if (in_array("session", $logsType, true)) {
|
||||
$this->logsession($msg, $priority);
|
||||
}
|
||||
}
|
||||
|
||||
/** Log $message on file
|
||||
@param string $message Message to log
|
||||
@param integer|null $priority Priority to use */
|
||||
/**
|
||||
* Log $message on file
|
||||
* @param string $message Message to log
|
||||
* @param integer|null $priority Priority to use
|
||||
*/
|
||||
private function logfile($message, $priority)
|
||||
{
|
||||
if ($this->logfile === false) {
|
||||
@@ -303,9 +330,11 @@ class Logger
|
||||
file_put_contents($this->logfile, $message, FILE_APPEND | LOCK_EX);
|
||||
}
|
||||
|
||||
/** Log $message on screen with adding date. Add the HTML flags if not in CLI.
|
||||
@param string $message Message to log
|
||||
@param integer|null $priority Priority to use */
|
||||
/**
|
||||
* Log $message on screen with adding date. Add the HTML flags if not in CLI.
|
||||
* @param string $message Message to log
|
||||
* @param integer|null $priority Priority to use
|
||||
*/
|
||||
private function logdisplay($message, $priority)
|
||||
{
|
||||
if (php_sapi_name() !== "cli") {
|
||||
@@ -324,9 +353,11 @@ class Logger
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
/** Log $message on stderr with adding date. Add the HTML flags if not in CLI.
|
||||
@param string $message Message to log
|
||||
@param integer|null $priority Priority to use */
|
||||
/**
|
||||
* Log $message on stderr with adding date. Add the HTML flags if not in CLI.
|
||||
* @param string $message Message to log
|
||||
* @param integer|null $priority Priority to use
|
||||
*/
|
||||
private function logstderr($message, $priority)
|
||||
{
|
||||
ini_set("date.timezone", $this->timezone);
|
||||
@@ -336,9 +367,11 @@ class Logger
|
||||
file_put_contents("php://stderr", "\n");
|
||||
}
|
||||
|
||||
/** Log $message on syslog
|
||||
@param string $message Message to log
|
||||
@param integer|null $priority Priority to use */
|
||||
/**
|
||||
* Log $message on syslog
|
||||
* @param string $message Message to log
|
||||
* @param integer|null $priority Priority to use
|
||||
*/
|
||||
private function logsyslog($message, $priority)
|
||||
{
|
||||
if (is_string($this->syslogFacility)) {
|
||||
@@ -405,9 +438,11 @@ class Logger
|
||||
syslog($priority, $message);
|
||||
}
|
||||
|
||||
/** Log $message on session (for debug)
|
||||
@param string $message Message to log
|
||||
@param integer|null $priority Priority to use */
|
||||
/**
|
||||
* Log $message on session (for debug)
|
||||
* @param string $message Message to log
|
||||
* @param integer|null $priority Priority to use
|
||||
*/
|
||||
private function logsession($message, $priority)
|
||||
{
|
||||
if (! isset($_SESSION)) {
|
||||
|
||||
Reference in New Issue
Block a user