Move SimpleLogger lib into app source tree

This commit is contained in:
Frédéric Guillot
2018-03-05 12:04:28 -08:00
parent a991758e98
commit 299198f718
16 changed files with 99 additions and 197 deletions

View File

@@ -314,6 +314,12 @@ return array(
'Kanboard\\Core\\Ldap\\Group' => $baseDir . '/app/Core/Ldap/Group.php',
'Kanboard\\Core\\Ldap\\Query' => $baseDir . '/app/Core/Ldap/Query.php',
'Kanboard\\Core\\Ldap\\User' => $baseDir . '/app/Core/Ldap/User.php',
'Kanboard\\Core\\Log\\Base' => $baseDir . '/app/Core/Log/Base.php',
'Kanboard\\Core\\Log\\File' => $baseDir . '/app/Core/Log/File.php',
'Kanboard\\Core\\Log\\Logger' => $baseDir . '/app/Core/Log/Logger.php',
'Kanboard\\Core\\Log\\Stderr' => $baseDir . '/app/Core/Log/Stderr.php',
'Kanboard\\Core\\Log\\Stdout' => $baseDir . '/app/Core/Log/Stdout.php',
'Kanboard\\Core\\Log\\Syslog' => $baseDir . '/app/Core/Log/Syslog.php',
'Kanboard\\Core\\Mail\\Client' => $baseDir . '/app/Core/Mail/Client.php',
'Kanboard\\Core\\Mail\\ClientInterface' => $baseDir . '/app/Core/Mail/ClientInterface.php',
'Kanboard\\Core\\Mail\\Transport\\Mail' => $baseDir . '/app/Core/Mail/Transport/Mail.php',
@@ -734,12 +740,6 @@ return array(
'Psr\\Log\\NullLogger' => $vendorDir . '/psr/log/Psr/Log/NullLogger.php',
'Psr\\Log\\Test\\DummyTest' => $vendorDir . '/psr/log/Psr/Log/Test/LoggerInterfaceTest.php',
'Psr\\Log\\Test\\LoggerInterfaceTest' => $vendorDir . '/psr/log/Psr/Log/Test/LoggerInterfaceTest.php',
'SimpleLogger\\Base' => $vendorDir . '/fguillot/simpleLogger/src/SimpleLogger/Base.php',
'SimpleLogger\\File' => $vendorDir . '/fguillot/simpleLogger/src/SimpleLogger/File.php',
'SimpleLogger\\Logger' => $vendorDir . '/fguillot/simpleLogger/src/SimpleLogger/Logger.php',
'SimpleLogger\\Stderr' => $vendorDir . '/fguillot/simpleLogger/src/SimpleLogger/Stderr.php',
'SimpleLogger\\Stdout' => $vendorDir . '/fguillot/simpleLogger/src/SimpleLogger/Stdout.php',
'SimpleLogger\\Syslog' => $vendorDir . '/fguillot/simpleLogger/src/SimpleLogger/Syslog.php',
'SimpleQueue\\Adapter\\AmqpQueueAdapter' => $vendorDir . '/fguillot/simple-queue/src/Adapter/AmqpQueueAdapter.php',
'SimpleQueue\\Adapter\\AwsSqsQueueAdapter' => $vendorDir . '/fguillot/simple-queue/src/Adapter/AwsSqsQueueAdapter.php',
'SimpleQueue\\Adapter\\BeanstalkQueueAdapter' => $vendorDir . '/fguillot/simple-queue/src/Adapter/BeanstalkQueueAdapter.php',

View File

@@ -7,7 +7,6 @@ $baseDir = dirname($vendorDir);
return array(
'SimpleValidator' => array($vendorDir . '/fguillot/simple-validator/src'),
'SimpleLogger' => array($vendorDir . '/fguillot/simpleLogger/src'),
'Pimple' => array($vendorDir . '/pimple/pimple/src'),
'PicoDb' => array($vendorDir . '/fguillot/picodb/lib'),
'Parsedown' => array($vendorDir . '/erusev/parsedown'),

View File

@@ -96,10 +96,6 @@ class ComposerStaticInitbdc3716ceecc7570f8ff9a8407f0ca0e
array (
0 => __DIR__ . '/..' . '/fguillot/simple-validator/src',
),
'SimpleLogger' =>
array (
0 => __DIR__ . '/..' . '/fguillot/simpleLogger/src',
),
),
'P' =>
array (
@@ -452,6 +448,12 @@ class ComposerStaticInitbdc3716ceecc7570f8ff9a8407f0ca0e
'Kanboard\\Core\\Ldap\\Group' => __DIR__ . '/../..' . '/app/Core/Ldap/Group.php',
'Kanboard\\Core\\Ldap\\Query' => __DIR__ . '/../..' . '/app/Core/Ldap/Query.php',
'Kanboard\\Core\\Ldap\\User' => __DIR__ . '/../..' . '/app/Core/Ldap/User.php',
'Kanboard\\Core\\Log\\Base' => __DIR__ . '/../..' . '/app/Core/Log/Base.php',
'Kanboard\\Core\\Log\\File' => __DIR__ . '/../..' . '/app/Core/Log/File.php',
'Kanboard\\Core\\Log\\Logger' => __DIR__ . '/../..' . '/app/Core/Log/Logger.php',
'Kanboard\\Core\\Log\\Stderr' => __DIR__ . '/../..' . '/app/Core/Log/Stderr.php',
'Kanboard\\Core\\Log\\Stdout' => __DIR__ . '/../..' . '/app/Core/Log/Stdout.php',
'Kanboard\\Core\\Log\\Syslog' => __DIR__ . '/../..' . '/app/Core/Log/Syslog.php',
'Kanboard\\Core\\Mail\\Client' => __DIR__ . '/../..' . '/app/Core/Mail/Client.php',
'Kanboard\\Core\\Mail\\ClientInterface' => __DIR__ . '/../..' . '/app/Core/Mail/ClientInterface.php',
'Kanboard\\Core\\Mail\\Transport\\Mail' => __DIR__ . '/../..' . '/app/Core/Mail/Transport/Mail.php',
@@ -872,12 +874,6 @@ class ComposerStaticInitbdc3716ceecc7570f8ff9a8407f0ca0e
'Psr\\Log\\NullLogger' => __DIR__ . '/..' . '/psr/log/Psr/Log/NullLogger.php',
'Psr\\Log\\Test\\DummyTest' => __DIR__ . '/..' . '/psr/log/Psr/Log/Test/LoggerInterfaceTest.php',
'Psr\\Log\\Test\\LoggerInterfaceTest' => __DIR__ . '/..' . '/psr/log/Psr/Log/Test/LoggerInterfaceTest.php',
'SimpleLogger\\Base' => __DIR__ . '/..' . '/fguillot/simpleLogger/src/SimpleLogger/Base.php',
'SimpleLogger\\File' => __DIR__ . '/..' . '/fguillot/simpleLogger/src/SimpleLogger/File.php',
'SimpleLogger\\Logger' => __DIR__ . '/..' . '/fguillot/simpleLogger/src/SimpleLogger/Logger.php',
'SimpleLogger\\Stderr' => __DIR__ . '/..' . '/fguillot/simpleLogger/src/SimpleLogger/Stderr.php',
'SimpleLogger\\Stdout' => __DIR__ . '/..' . '/fguillot/simpleLogger/src/SimpleLogger/Stdout.php',
'SimpleLogger\\Syslog' => __DIR__ . '/..' . '/fguillot/simpleLogger/src/SimpleLogger/Syslog.php',
'SimpleQueue\\Adapter\\AmqpQueueAdapter' => __DIR__ . '/..' . '/fguillot/simple-queue/src/Adapter/AmqpQueueAdapter.php',
'SimpleQueue\\Adapter\\AwsSqsQueueAdapter' => __DIR__ . '/..' . '/fguillot/simple-queue/src/Adapter/AwsSqsQueueAdapter.php',
'SimpleQueue\\Adapter\\BeanstalkQueueAdapter' => __DIR__ . '/..' . '/fguillot/simple-queue/src/Adapter/BeanstalkQueueAdapter.php',

View File

@@ -429,96 +429,6 @@
"psr-3"
]
},
{
"name": "fguillot/simpleLogger",
"version": "v1.0.1",
"version_normalized": "1.0.1.0",
"source": {
"type": "git",
"url": "https://github.com/fguillot/simpleLogger.git",
"reference": "c6831841193bb265b7900ecc8b6a8918371a7c98"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fguillot/simpleLogger/zipball/c6831841193bb265b7900ecc8b6a8918371a7c98",
"reference": "c6831841193bb265b7900ecc8b6a8918371a7c98",
"shasum": ""
},
"require": {
"php": ">=5.3.0",
"psr/log": "~1.0"
},
"time": "2016-05-07T18:01:57+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"SimpleLogger": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Frédéric Guillot"
}
],
"description": "PHP library to write logs (compatible with PSR-3)",
"homepage": "https://github.com/fguillot/simpleLogger"
},
{
"name": "symfony/finder",
"version": "v3.4.4",
"version_normalized": "3.4.4.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "613e26310776f49a1773b6737c6bd554b8bc8c6f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/613e26310776f49a1773b6737c6bd554b8bc8c6f",
"reference": "613e26310776f49a1773b6737c6bd554b8bc8c6f",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
},
"time": "2018-01-03T07:37:34+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Symfony\\Component\\Finder\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Finder Component",
"homepage": "https://symfony.com"
},
{
"name": "gregwar/captcha",
"version": "v1.1.4",
@@ -1079,5 +989,56 @@
],
"description": "Minimalist database query builder",
"homepage": "https://github.com/fguillot/picoDb"
},
{
"name": "symfony/finder",
"version": "v3.4.5",
"version_normalized": "3.4.5.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "6a615613745cef820d807443f32076bb9f5d0a38"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/6a615613745cef820d807443f32076bb9f5d0a38",
"reference": "6a615613745cef820d807443f32076bb9f5d0a38",
"shasum": ""
},
"require": {
"php": "^5.5.9|>=7.0.8"
},
"time": "2018-02-11T17:15:12+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Symfony\\Component\\Finder\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Finder Component",
"homepage": "https://symfony.com"
}
]

View File

@@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2015 Frederic Guillot
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -1,89 +0,0 @@
<?php
namespace SimpleLogger;
use Psr\Log\AbstractLogger;
use Psr\Log\LogLevel;
/**
* Base class for loggers
*
* @package SimpleLogger
* @author Frédéric Guillot
*/
abstract class Base extends AbstractLogger
{
/**
* Minimum log level for the logger
*
* @access private
* @var string
*/
private $level = LogLevel::DEBUG;
/**
* Set minimum log level
*
* @access public
* @param string $level
*/
public function setLevel($level)
{
$this->level = $level;
}
/**
* Get minimum log level
*
* @access public
* @return string
*/
public function getLevel()
{
return $this->level;
}
/**
* Dump to log a variable (by example an array)
*
* @param mixed $variable
*/
public function dump($variable)
{
$this->log(LogLevel::DEBUG, var_export($variable, true));
}
/**
* Interpolates context values into the message placeholders.
*
* @access protected
* @param string $message
* @param array $context
* @return string
*/
protected function interpolate($message, array $context = array())
{
// build a replacement array with braces around the context keys
$replace = array();
foreach ($context as $key => $val) {
$replace['{' . $key . '}'] = $val;
}
// interpolate replacement values into the message and return
return strtr($message, $replace);
}
/**
* Format log message
*
* @param mixed $level
* @param string $message
* @param array $context
* @return string
*/
protected function formatMessage($level, $message, array $context = array())
{
return '['.date('Y-m-d H:i:s').'] ['.$level.'] '.$this->interpolate($message, $context).PHP_EOL;
}
}

View File

@@ -1,48 +0,0 @@
<?php
namespace SimpleLogger;
use RuntimeException;
/**
* File logger
*
* @package SimpleLogger
* @author Frédéric Guillot
*/
class File extends Base
{
/**
* Filename
*
* @access protected
* @var string
*/
protected $filename = '';
/**
* Setup logger configuration
*
* @param string $filename Output file
*/
public function __construct($filename)
{
$this->filename = $filename;
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
*/
public function log($level, $message, array $context = array())
{
$line = $this->formatMessage($level, $message, $context);
if (file_put_contents($this->filename, $line, FILE_APPEND | LOCK_EX) === false) {
throw new RuntimeException('Unable to write to the log file.');
}
}
}

View File

@@ -1,94 +0,0 @@
<?php
namespace SimpleLogger;
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
/**
* Handler for multiple loggers
*
* @package SimpleLogger
* @author Frédéric Guillot
*/
class Logger extends AbstractLogger implements LoggerAwareInterface
{
/**
* Logger instances
*
* @access private
*/
private $loggers = array();
/**
* Get level priority
*
* @param mixed $level
* @return integer
*/
public function getLevelPriority($level)
{
switch ($level) {
case LogLevel::EMERGENCY:
return 600;
case LogLevel::ALERT:
return 550;
case LogLevel::CRITICAL:
return 500;
case LogLevel::ERROR:
return 400;
case LogLevel::WARNING:
return 300;
case LogLevel::NOTICE:
return 250;
case LogLevel::INFO:
return 200;
}
return 100;
}
/**
* Sets a logger instance on the object
*
* @param LoggerInterface $logger
* @return null
*/
public function setLogger(LoggerInterface $logger)
{
$this->loggers[] = $logger;
}
/**
* Proxy method to the real loggers
*
* @param mixed $level
* @param string $message
* @param array $context
* @return null
*/
public function log($level, $message, array $context = array())
{
foreach ($this->loggers as $logger) {
if ($this->getLevelPriority($level) >= $this->getLevelPriority($logger->getLevel())) {
$logger->log($level, $message, $context);
}
}
}
/**
* Dump variables for debugging
*
* @param mixed $variable
*/
public function dump($variable)
{
foreach ($this->loggers as $logger) {
if ($this->getLevelPriority(LogLevel::DEBUG) >= $this->getLevelPriority($logger->getLevel())) {
$logger->dump($variable);
}
}
}
}

View File

@@ -1,25 +0,0 @@
<?php
namespace SimpleLogger;
/**
* Stderr logger
*
* @package SimpleLogger
* @author Frédéric Guillot
*/
class Stderr extends Base
{
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
* @return null
*/
public function log($level, $message, array $context = array())
{
file_put_contents('php://stderr', $this->formatMessage($level, $message, $context), FILE_APPEND);
}
}

View File

@@ -1,25 +0,0 @@
<?php
namespace SimpleLogger;
/**
* Stdout logger
*
* @package SimpleLogger
* @author Frédéric Guillot
*/
class Stdout extends Base
{
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
* @return null
*/
public function log($level, $message, array $context = array())
{
file_put_contents('php://stdout', $this->formatMessage($level, $message, $context), FILE_APPEND);
}
}

View File

@@ -1,72 +0,0 @@
<?php
namespace SimpleLogger;
use RuntimeException;
use Psr\Log\LogLevel;
/**
* Syslog Logger
*
* @package SimpleLogger
* @author Frédéric Guillot
*/
class Syslog extends Base
{
/**
* Setup Syslog configuration
*
* @param string $ident Application name
* @param int $facility See http://php.net/manual/en/function.openlog.php
*/
public function __construct($ident = 'PHP', $facility = LOG_USER)
{
if (! openlog($ident, LOG_ODELAY | LOG_PID, $facility)) {
throw new RuntimeException('Unable to connect to syslog.');
}
}
/**
* Get syslog priority according to Psr\LogLevel
*
* @param mixed $level
* @return integer
*/
public function getSyslogPriority($level)
{
switch ($level) {
case LogLevel::EMERGENCY:
return LOG_EMERG;
case LogLevel::ALERT:
return LOG_ALERT;
case LogLevel::CRITICAL:
return LOG_CRIT;
case LogLevel::ERROR:
return LOG_ERR;
case LogLevel::WARNING:
return LOG_WARNING;
case LogLevel::NOTICE:
return LOG_NOTICE;
case LogLevel::INFO:
return LOG_INFO;
}
return LOG_DEBUG;
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
* @return null
*/
public function log($level, $message, array $context = array())
{
$syslogPriority = $this->getSyslogPriority($level);
$syslogMessage = $this->interpolate($message, $context);
syslog($syslogPriority, $syslogMessage);
}
}

View File

@@ -313,6 +313,8 @@ class Finder implements \IteratorAggregate, \Countable
/**
* Excludes "hidden" directories and files (starting with a dot).
*
* This option is enabled by default.
*
* @param bool $ignoreDotFiles Whether to exclude "hidden" files or not
*
* @return $this
@@ -333,6 +335,8 @@ class Finder implements \IteratorAggregate, \Countable
/**
* Forces the finder to ignore version control directories.
*
* This option is enabled by default.
*
* @param bool $ignoreVCS Whether to exclude VCS files or not
*
* @return $this