Skip to content

Commit

Permalink
Added log level attribute to the phpcs task. (#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
siad007 authored Sep 28, 2019
1 parent 127e3c6 commit a9335c5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion classes/phing/tasks/ext/PhpCSTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*/
class PhpCSTask extends Task
{
use LogLevelAware;

/**
* A php source code filename or directory
*
Expand All @@ -50,6 +52,7 @@ class PhpCSTask extends Task
public function __construct()
{
$this->cmd = new Commandline();
$this->logLevelName = 'info';
parent::__construct();
}

Expand Down Expand Up @@ -123,7 +126,7 @@ public function main()
$exe->setTaskName($this->getTaskName());
$exe->setExecutable($this->bin);
$exe->setCheckreturn($this->checkreturn);
$exe->setLevel('info');
$exe->setLevel($this->logLevelName);
$exe->setExecutable($toExecute->getExecutable());
$exe->createArg()->setLine(implode(' ', $toExecute->getArguments()));
$exe->main();
Expand Down
6 changes: 6 additions & 0 deletions classes/phing/tasks/system/element/LogLevelAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
trait LogLevelAware
{
protected $logLevel = Project::MSG_VERBOSE;
protected $logLevelName = 'verbose';

This comment has been minimized.

Copy link
@mimmi20

mimmi20 Sep 30, 2019

Contributor

Why dont you use PSR-3 LogLevels?

This comment has been minimized.

Copy link
@siad007

siad007 Oct 2, 2019

Author Member

@mimmi20 PSR-3 support was never implemented in phing nor in ant. We could maybe think of a PSR-3 aware logger to support the missing log levels for custom tasks. Any contributing on this are very welcome. Feel free to add a feature request for further discussion.


/**
* Set level of log messages generated (default = verbose)
Expand All @@ -36,18 +37,23 @@ public function setLevel($level): void
switch ($level) {
case 'error':
$this->logLevel = Project::MSG_ERR;
$this->logLevelName = 'error';
break;
case 'warning':
$this->logLevel = Project::MSG_WARN;
$this->logLevelName = 'warning';
break;
case 'info':
$this->logLevel = Project::MSG_INFO;
$this->logLevelName = 'info';
break;
case 'verbose':
$this->logLevel = Project::MSG_VERBOSE;
$this->logLevelName = 'verbose';
break;
case 'debug':
$this->logLevel = Project::MSG_DEBUG;
$this->logLevelName = 'debug';
break;
default:
throw new BuildException(
Expand Down
15 changes: 15 additions & 0 deletions docs/guide/en/source/appendixes/optionaltasks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8752,6 +8752,21 @@ Note that you can omit both startpoint and track attributes in this case
<entry><literal>false</literal></entry>
<entry>No</entry>
</row>
<row>
<entry><literal>level</literal></entry>
<entry><literal role="type">String</literal></entry>
<entry>Set the log level of generated messages.
Change this to <literal>verbose</literal>,
if you only want output in verbose mode for example.
Valid log levels are one of
<literal>debug</literal>,
<literal>info</literal>,
<literal>verbose</literal>,
<literal>warning</literal> or
<literal>error</literal></entry>
<entry><literal>info</literal></entry>
<entry>No</entry>
</row>
</tbody>
</tgroup>
</table>
Expand Down
11 changes: 11 additions & 0 deletions etc/phing-grammar.rng
Original file line number Diff line number Diff line change
Expand Up @@ -5043,6 +5043,17 @@
<data type="boolean"/>
</attribute>
</optional>
<optional>
<attribute name="level" a:defaultValue="info">
<choice>
<value>error</value>
<value>warning</value>
<value>info</value>
<value>verbose</value>
<value>debug</value>
</choice>
</attribute>
</optional>
</interleave>
</element>
</define>
Expand Down
2 changes: 1 addition & 1 deletion test/etc/tasks/ext/phpcs/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
</target>

<target name="testPhpCs">
<phpcs bin="../../../../../bin/phpcs" file="../../../../../classes/phing/dispatch" checkreturn="false" ignoreAnnotations="true" />
<phpcs bin="../../../../../bin/phpcs" file="../../../../../classes/phing/dispatch" level="debug" checkreturn="false" ignoreAnnotations="true" />
</target>
</project>

0 comments on commit a9335c5

Please sign in to comment.