@@ -8,6 +8,7 @@ It takes care of
8
8
- ** help page generation**
9
9
- ** automatic width adjustment**
10
10
- ** colored output**
11
+ - ** optional PSR3 compatibility**
11
12
12
13
It is lightweight and has ** no 3rd party dependencies** .
13
14
@@ -83,18 +84,20 @@ passing false to the constructor.
83
84
You can use the provided `` splitbrain\phpcli\Exception `` to signal any problems within your main code yourself. The
84
85
exceptions's code will be used as the exit code then.
85
86
87
+ Stacktraces will be printed on log level ` debug ` .
88
+
86
89
## Colored output
87
90
88
91
Colored output is handled through the `` Colors `` class. It tries to detect if a color terminal is available and only
89
92
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.
90
94
91
95
Simple colored log messages can be printed by you using the convinence methods `` success() `` (green), `` info() `` (cyan),
92
96
`` error() `` (red) or `` fatal() `` (red). The latter will also exit the programm with a non-zero exit code.
93
97
94
98
For more complex coloring you can access the color class through `` $this->colors `` in your script. The `` wrap() `` method
95
99
is probably what you want to use.
96
100
97
-
98
101
The table formatter allows coloring full columns. To use that mechanism pass an array of colors as third parameter to
99
102
its `` format() `` method. Please note that you can not pass colored texts in the second parameters (text length calculation
100
103
and wrapping will fail, breaking your texts).
@@ -123,3 +126,33 @@ Space for borders is automatically calculated. It is recommended to always have
123
126
column to adjust for different terminal widths.
124
127
125
128
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.
0 commit comments