mirror of
https://github.com/discourse/wp-discourse.git
synced 2025-08-17 18:11:19 +08:00
* Add base log classes * Return maxFiles to normal level * Use protected class variables for folder names in folder-manager * Add unit tests for logger classes && various logger improvements * Add log viewer * Fix initialization sequence in LogViewer * Add wp-discourse settings to plugin meta * Remove metafile comments * Add partial coverage and annotate LogViewer * Add code coverage reporting and a tests readme * Tests readme xdebug section formatting * Add logging and tests to discourse-publish This abstracts remote post components to make it possible to add consistent error and log handling. Also adds basic tests coverage for discourse-publish. * Add successful publication test * Add working tests for publish_after_create and publish_after_update * Always remove test files and database upon install * Cleanup copy and assertions for existing tests * Final cleanup && verbose setting * Improve structure of publish test * Final tests, linting, security and cleanup * PHP 7.0 Compatibility * PHP 5.6 Compatibility * JSHint fixes * Update file-handler.php * Update log viewer title * Use older monolog and update file_handler function signatures * Add nonce to other view_log action * Namespace production composer packages and define build process * Update COMPOSER.md * Update FORMATTING.md * Log viewer style, naming and log-refresh improvements * Filter out all return type declarations during scoping * JsHint: Don't use default params * Update COMPOSER.md * Copy fix * Update scoper patchers notes * Address syntax issues - Remove >php7 syntax from non-required files - Add phpcs pattern exclusions to phpcs.xml - update formatting docs * discourse-publish: address all phpcs notices and add more tests Note: also added dealerdirect/phpcodesniffer-composer-installer to handle local requiring of codesniffer * Handle all phpcs warnings in lib/logs * Add todo: review phpcs exclusions to discourse-publish * Monolog cleanup - Remove unused monolog handlers, processors and formatters - Add vendor_namespaced to excluded phpcs patterns * Update CI versions to those used in composer * Switch to using composer directly in CI actions * Composer is packaged in shivammathur/setup-php * Setup PHPCS via shivammathur/setup-php * Incorrect tools key * Use vendor/bin version of phpcs * Install composer dependencies via ramsey/composer-install * Update composer.lock to composer 2 and --ignore-platform-reqs * Install lowest version of dependencies * Move dependency-versions key * Move composer-options key * Exclude vendor directory from syntax checker * Add vendor to jshintignore * Update phpcs.xml to properly exclude js css and config files * Address phpcs issues in log-viewer * Fix remaining whitespace issues created in this PR * Remove out of date sniffs and exclude specific code where necessary * Final cleanup * Properly escape html in log viewer * Remove unnecessary verbiage from documentation * Bump plugin's version to 2.2.4 Co-authored-by: Angus McLeod <angus@mcleod.org.au>
134 lines
3.5 KiB
PHP
134 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace WPDiscourse\Psr\Log;
|
|
|
|
/**
|
|
* This is a simple Logger trait that classes unable to extend AbstractLogger
|
|
* (because they extend another class, etc) can include.
|
|
*
|
|
* It simply delegates all log-level-specific methods to the `log` method to
|
|
* reduce boilerplate code that a simple Logger that does the same thing with
|
|
* messages regardless of the error level has to implement.
|
|
*/
|
|
trait LoggerTrait
|
|
{
|
|
/**
|
|
* System is unusable.
|
|
*
|
|
* @param string $message
|
|
* @param array $context
|
|
*
|
|
* @return void
|
|
*/
|
|
public function emergency($message, array $context = array())
|
|
{
|
|
$this->log(\WPDiscourse\Psr\Log\LogLevel::EMERGENCY, $message, $context);
|
|
}
|
|
/**
|
|
* Action must be taken immediately.
|
|
*
|
|
* Example: Entire website down, database unavailable, etc. This should
|
|
* trigger the SMS alerts and wake you up.
|
|
*
|
|
* @param string $message
|
|
* @param array $context
|
|
*
|
|
* @return void
|
|
*/
|
|
public function alert($message, array $context = array())
|
|
{
|
|
$this->log(\WPDiscourse\Psr\Log\LogLevel::ALERT, $message, $context);
|
|
}
|
|
/**
|
|
* Critical conditions.
|
|
*
|
|
* Example: Application component unavailable, unexpected exception.
|
|
*
|
|
* @param string $message
|
|
* @param array $context
|
|
*
|
|
* @return void
|
|
*/
|
|
public function critical($message, array $context = array())
|
|
{
|
|
$this->log(\WPDiscourse\Psr\Log\LogLevel::CRITICAL, $message, $context);
|
|
}
|
|
/**
|
|
* Runtime errors that do not require immediate action but should typically
|
|
* be logged and monitored.
|
|
*
|
|
* @param string $message
|
|
* @param array $context
|
|
*
|
|
* @return void
|
|
*/
|
|
public function error($message, array $context = array())
|
|
{
|
|
$this->log(\WPDiscourse\Psr\Log\LogLevel::ERROR, $message, $context);
|
|
}
|
|
/**
|
|
* Exceptional occurrences that are not errors.
|
|
*
|
|
* Example: Use of deprecated APIs, poor use of an API, undesirable things
|
|
* that are not necessarily wrong.
|
|
*
|
|
* @param string $message
|
|
* @param array $context
|
|
*
|
|
* @return void
|
|
*/
|
|
public function warning($message, array $context = array())
|
|
{
|
|
$this->log(\WPDiscourse\Psr\Log\LogLevel::WARNING, $message, $context);
|
|
}
|
|
/**
|
|
* Normal but significant events.
|
|
*
|
|
* @param string $message
|
|
* @param array $context
|
|
*
|
|
* @return void
|
|
*/
|
|
public function notice($message, array $context = array())
|
|
{
|
|
$this->log(\WPDiscourse\Psr\Log\LogLevel::NOTICE, $message, $context);
|
|
}
|
|
/**
|
|
* Interesting events.
|
|
*
|
|
* Example: User logs in, SQL logs.
|
|
*
|
|
* @param string $message
|
|
* @param array $context
|
|
*
|
|
* @return void
|
|
*/
|
|
public function info($message, array $context = array())
|
|
{
|
|
$this->log(\WPDiscourse\Psr\Log\LogLevel::INFO, $message, $context);
|
|
}
|
|
/**
|
|
* Detailed debug information.
|
|
*
|
|
* @param string $message
|
|
* @param array $context
|
|
*
|
|
* @return void
|
|
*/
|
|
public function debug($message, array $context = array())
|
|
{
|
|
$this->log(\WPDiscourse\Psr\Log\LogLevel::DEBUG, $message, $context);
|
|
}
|
|
/**
|
|
* Logs with an arbitrary level.
|
|
*
|
|
* @param mixed $level
|
|
* @param string $message
|
|
* @param array $context
|
|
*
|
|
* @return void
|
|
*
|
|
* @throws \Psr\Log\InvalidArgumentException
|
|
*/
|
|
public abstract function log($level, $message, array $context = array());
|
|
}
|