Skip to content

Commit 221ef89

Browse files
committed
updated readme
1 parent ee2d20b commit 221ef89

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

README.md

+34-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ It takes care of
88
- **help page generation**
99
- **automatic width adjustment**
1010
- **colored output**
11+
- **optional PSR3 compatibility**
1112

1213
It is lightweight and has **no 3rd party dependencies**.
1314

@@ -83,18 +84,20 @@ passing false to the constructor.
8384
You can use the provided ``splitbrain\phpcli\Exception`` to signal any problems within your main code yourself. The
8485
exceptions's code will be used as the exit code then.
8586

87+
Stacktraces will be printed on log level `debug`.
88+
8689
## Colored output
8790

8891
Colored output is handled through the ``Colors`` class. It tries to detect if a color terminal is available and only
8992
then uses terminal colors. You can always suppress colored output by passing ``--no-colors`` to your scripts.
93+
Disabling colors will also disable the emoticon prefixes.
9094

9195
Simple colored log messages can be printed by you using the convinence methods ``success()`` (green), ``info()`` (cyan),
9296
``error()`` (red) or ``fatal()`` (red). The latter will also exit the programm with a non-zero exit code.
9397

9498
For more complex coloring you can access the color class through ``$this->colors`` in your script. The ``wrap()`` method
9599
is probably what you want to use.
96100

97-
98101
The table formatter allows coloring full columns. To use that mechanism pass an array of colors as third parameter to
99102
its ``format()`` method. Please note that you can not pass colored texts in the second parameters (text length calculation
100103
and wrapping will fail, breaking your texts).
@@ -123,3 +126,33 @@ Space for borders is automatically calculated. It is recommended to always have
123126
column to adjust for different terminal widths.
124127

125128
The table formatter is used for the automatic help screen accessible when calling your script with ``-h`` or ``--help``.
129+
130+
## PSR-3 Logging
131+
132+
The CLI class is a fully PSR-3 compatible logger (printing colored log data to STDOUT and STDERR). This is useful when
133+
you call backend code from your CLI that expects a Logger instance to produce any sensible status output while running.
134+
135+
To use this ability simply inherit from `splitbrain\phpcli\PSR3CLI` instead of `splitbrain\phpcli\CLI`, then pass `$this`
136+
as the logger instance. Be sure you have the suggested `psr/log` composer package installed.
137+
138+
![Screenshot](screenshot2.png)
139+
140+
You can adjust the verbosity of your CLI tool using the `--loglevel` parameter. Supported loglevels are the PSR-3
141+
loglevels and our own `success` level:
142+
143+
* debug
144+
* info
145+
* notice
146+
* success
147+
* warning
148+
* error
149+
* critical
150+
* alert
151+
* emergency
152+
153+
Convenience methods for all log levels are available. Placeholder interpolation as described in PSR-3 is available, too.
154+
Messages from `warning` level onwards are printed to `STDERR` all below are printed to `STDOUT`.
155+
156+
The default log level of your script can be set by overwriting the `$logdefault` member.
157+
158+
See `example/logging.php` for an example.

screenshot.png

126 KB
Loading

screenshot2.png

167 KB
Loading

0 commit comments

Comments
 (0)