Skip to content

Commit

Permalink
#6622 Logger refactoring: remove INI options:
Browse files Browse the repository at this point in the history
- log_only_when_cli
- log_only_when_debug_parameter
  • Loading branch information
mnapoli committed Dec 17, 2014
1 parent 524565e commit bf5b7e6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 64 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This is a changelog for Piwik platform developers. All changes for our HTTP API'
* `Log.formatScreenMessage`
* These events where very specific events for an internal need (logging exceptions) and have been replaced by a more extensible solution.
* The event `Log.getAvailableWriters` has been removed: to add custom log backends, you now need to configure Monolog handlers
* The INI options `log_only_when_cli` and `log_only_when_debug_parameter` have been removed

### Deprecations
* The API method `UserSettings.getBrowserVersion` is deprecated and will be removed from May 1st 2015. Use `DevicesDetection.getBrowserVersions` instead
Expand Down
15 changes: 0 additions & 15 deletions config/global.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Interop\Container\ContainerInterface;
use Monolog\Logger;
use Piwik\Common;
use Piwik\Log;
use Piwik\Cache\Eager;
use Piwik\SettingsServer;
Expand Down Expand Up @@ -117,9 +116,6 @@
->constructor(DI\link('log.level'))
->method('setFormatter', DI\link('Piwik\Log\Formatter\LineMessageFormatter')),
'log.level' => DI\factory(function (ContainerInterface $c) {
if ($c->get('log.disabled')) {
return Log::getMonologLevel(Log::NONE);
}
if ($c->has('old_config.log.log_level')) {
$level = strtoupper($c->get('old_config.log.log_level'));
if (!empty($level) && defined('Piwik\Log::'.strtoupper($level))) {
Expand All @@ -128,17 +124,6 @@
}
return Logger::WARNING;
}),
'log.disabled' => DI\factory(function (ContainerInterface $c) {
$logOnlyCli = $c->has('old_config.log.log_only_when_cli') ? $c->get('old_config.log.log_only_when_cli') : false;
if ($logOnlyCli && !Common::isPhpCliMode()) {
return true;
}
$logOnlyWhenDebugParameter = $c->has('old_config.log.log_only_when_debug_parameter') ? $c->get('old_config.log.log_only_when_debug_parameter') : false;
if ($logOnlyWhenDebugParameter && !isset($_REQUEST['debug'])) {
return true;
}
return false;
}),
'log.file.filename' => DI\factory(function (ContainerInterface $c) {
$logPath = $c->get('old_config.log.logger_file_path');

Expand Down
52 changes: 3 additions & 49 deletions core/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
* the name of the current class is used.
*
* You can log messages using one of the public static functions (eg, 'error', 'warning',
* 'info', etc.). Messages logged with the **error** level will **always** be logged to
* the screen, regardless of whether the [log] log_writer config option includes the
* screen writer.
* 'info', etc.).
*
* Currently, Piwik supports the following logging backends:
*
* - **screen**: logging to the screen
* - **file**: logging to a file
* - **database**: logging to Piwik's MySQL database
*
* Messages logged in the console will always be logged to the console output.
*
* ### Logging configuration
*
* The logging utility can be configured by manipulating the INI config options in the
Expand All @@ -44,57 +44,11 @@
* or **VERBOSE**. Log entries made with a log level that is as or more
* severe than the current log level will be outputted. Others will be
* ignored. The default level is **WARN**.
* - `log_only_when_cli`: 0 or 1. If 1, logging is only enabled when Piwik is executed
* in the command line (for example, by the core:archive command
* script). Default: 0.
* - `log_only_when_debug_parameter`: 0 or 1. If 1, logging is only enabled when the
* `debug` query parameter is 1. Default: 0.
* - `logger_file_path`: For the file log writer, specifies the path to the log file
* to log to or a path to a directory to store logs in. If a
* directory, the file name is piwik.log. Can be relative to
* Piwik's root dir or an absolute path. Defaults to **tmp/logs**.
*
* ### Custom message formatting
*
* If you'd like to format log messages differently for different backends, you can
* implement a new `Piwik\Log\Formatter\Formatter`.
*
* If you don't care about the backend when formatting an object, implement a `__toString()`
* in the custom class.
*
* ### Custom log writers
*
* New logging backends can be added via the {@hook Log.getAvailableWriters}` event. A log
* writer is just a callback that accepts log entry information (such as the message,
* level, etc.), so any backend could conceivably be used (including existing PSR3
* backends).
*
* ### Examples
*
* **Basic logging**
*
* Log::error("This log message will end up on the screen and in a file.")
* Log::verbose("This log message uses %s params, but %s will only be called if the"
* . " configured log level includes %s.", "sprintf", "sprintf", "verbose");
*
* **Logging objects**
*
* class MyDebugInfo
* {
* // ...
*
* public function __toString()
* {
* return // ...
* }
* }
*
* try {
* $myThirdPartyServiceClient->doSomething();
* } catch (Exception $unexpectedError) {
* $debugInfo = new MyDebugInfo($unexpectedError, $myThirdPartyServiceClient);
* Log::debug($debugInfo);
* }
*
* @deprecated Inject and use Psr\Log\LoggerInterface instead of this class.
* @see \Psr\Log\LoggerInterface
Expand Down

0 comments on commit bf5b7e6

Please sign in to comment.