Skip to content

Commit 9d7225e

Browse files
committed
Console: Update documentation to describe new default behaviour
1 parent c5011a9 commit 9d7225e

File tree

5 files changed

+64
-73
lines changed

5 files changed

+64
-73
lines changed

docs/Console.md

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,57 @@
1-
## Terminal output and logging
1+
# Console
22

3-
With a similar API to the `console` object provided by web browsers, the
4-
[Console][] class[^1] provides:
3+
The Console component provides terminal output and message logging via an API
4+
similar to `console` in web browsers.
55

6-
- Familiar methods like `Console::log()` and `Console::error()`
7-
- Variants like `Console::logOnce()` and `Console::errorOnce()` to output
8-
messages once per run
6+
- Familiar methods like [Console::log()][log()] and [Console::error()][error()]
7+
- Variants like [Console::logOnce()][logOnce()] and
8+
[Console::errorOnce()][errorOnce()] to output messages once per run
99
- Output to multiple targets
1010
- Messages filtered by log level
11-
- Formatting to reflect message priority and improve readability
11+
- Formatting that reflects message priority and improves readability
12+
- Optional Markdown-like syntax for additional formatting
1213
- Colour output to TTYs
14+
- [PSR-3 (Logger Interface)][PSR-3] support via [Console::logger()][logger()]
1315

14-
### Default targets
16+
## Default targets
1517

16-
By default, [Console][] output is appended to a file in the default temporary
17-
directory, created with mode `0600` if it doesn't already exist:
18+
If no targets are registered to receive [Console][] output when a message is
19+
written:
1820

19-
```php
20-
<?php
21-
sys_get_temp_dir() . '/<script_basename>-<realpath_hash>-<user_id>.log'
22-
```
23-
24-
If the value of environment variable `console_target` is `stderr` or `stdout`,
25-
[Console][] output is also written to `STDERR` or `STDOUT` respectively.
21+
1. Output is appended to a log file in PHP's default temporary directory,
22+
created with mode `0600` if it doesn't already exist:
2623

27-
If `console_target` is not set and the script is running on the command line:
24+
```php
25+
sys_get_temp_dir() . '/<script_basename>-<realpath_hash>-<user_id>.log'
26+
```
2827

29-
- If `STDERR` is a TTY and `STDOUT` is not, console messages are written to
30-
`STDERR` so output to `STDOUT` isn't tainted
31-
- Otherwise, errors and warnings are written to `STDERR`, and informational
32-
messages are written to `STDOUT`
28+
2. If the script is running on the command line, output is also written to
29+
`STDERR`.
3330

34-
Debug messages are written to the output log but are not written to `STDOUT` or
35-
`STDERR` if environment variable `DEBUG` is empty or not set.
31+
Debug messages are suppressed unless debug mode is enabled in the environment,
32+
e.g. by setting `DEBUG=1`.
3633

37-
To override these defaults, register at least one [Console][] output target,
38-
e.g. by calling [registerTarget()][], before any other `Console` methods are
39-
called, preferably while bootstrapping your application.
34+
To override these defaults:
4035

41-
> [Application][] and [CliApplication][] always call [registerStderrTarget()][],
42-
> which registers the default `STDOUT` and `STDERR` targets and prevents
43-
> creation of the default output log. To create a log file that persists between
44-
> reboots (in your project's `var/log` directory by default), call the app
45-
> container's [logOutput()][] method.
36+
- register at least one [Console][] output target while bootstrapping your
37+
application, or
38+
- create an [Application][] or [CliApplication][] and optionally use
39+
[logOutput()][] to write output a persistent log file
4640

47-
### Output methods
41+
## Message methods
4842

4943
<!-- prettier-ignore -->
50-
| Method | Message level | Default prefix | Default output target |
51-
| --------------- | --------------------- | ---------------- | ------------------------- |
52-
| `error[Once]()` | `LEVEL_ERROR` = `3` | ` ! ` | `STDERR` |
53-
| `warn[Once]()` | `LEVEL_WARNING` = `4` | ` ^ ` | `STDERR` |
54-
| `info[Once]()` | `LEVEL_NOTICE` = `5` | `` | `STDOUT` |
55-
| `log[Once]()` | `LEVEL_INFO` = `6` | ` - ` | `STDOUT` |
56-
| `debug[Once]()` | `LEVEL_DEBUG` = `7` | ` : ` | `STDOUT` (if `DEBUG` set) |
57-
| `group()`[^2] | `LEVEL_NOTICE` = `5` | ` » ` | `STDOUT` |
58-
| `logProgress()` | `LEVEL_INFO` = `6` | `` (spinner) | `STDOUT` |
59-
60-
[^1]:
61-
Actually a facade for [ConsoleInterface][], which is backed by a shared
62-
instance of [Console][ConsoleService] by default.
63-
64-
[^2]:
65-
`Console::group()` adds a level of indentation to all `Console` output until
66-
`Console::groupEnd()` is called.
67-
68-
### Formatting
44+
| Method | Message level | Default prefix |
45+
| ---------------------------------- | --------------------- | -------------------------- |
46+
| `error()`, `errorOnce()` | `LEVEL_ERROR` = `3` | ` ! ` |
47+
| `warn()`, `warnOnce()` | `LEVEL_WARNING` = `4` | ` ^ ` |
48+
| `group()`,`groupEnd()` | `LEVEL_NOTICE` = `5` | ` » `, ` « ` |
49+
| `info()`, `infoOnce()` | `LEVEL_NOTICE` = `5` | `` |
50+
| `log()`, `logOnce()` | `LEVEL_INFO` = `6` | ` - ` |
51+
| `logProgress()`, `clearProgress()` | `LEVEL_INFO` = `6` | `` (spinner, TTY only) |
52+
| `debug()`, `debugOnce()` | `LEVEL_DEBUG` = `7` | ` : ` |
53+
54+
## Formatting
6955

7056
The following Markdown-like syntax is supported in [Console][] messages:
7157

@@ -98,13 +84,16 @@ hard line break.
9884
https://salient-labs.github.io/toolkit/Salient.Cli.CliApplication.html
9985
[Console]:
10086
https://salient-labs.github.io/toolkit/Salient.Core.Facade.Console.html
101-
[ConsoleInterface]:
102-
https://salient-labs.github.io/toolkit/Salient.Contract.Console.ConsoleInterface.html
103-
[ConsoleService]:
104-
https://salient-labs.github.io/toolkit/Salient.Console.Console.html
87+
[error()]:
88+
https://salient-labs.github.io/toolkit/Salient.Core.Facade.Console.html#_error
89+
[errorOnce()]:
90+
https://salient-labs.github.io/toolkit/Salient.Core.Facade.Console.html#_errorOnce
91+
[log()]:
92+
https://salient-labs.github.io/toolkit/Salient.Core.Facade.Console.html#_log
93+
[logger()]:
94+
https://salient-labs.github.io/toolkit/Salient.Core.Facade.Console.html#_logger
95+
[logOnce()]:
96+
https://salient-labs.github.io/toolkit/Salient.Core.Facade.Console.html#_logOnce
10597
[logOutput()]:
10698
https://salient-labs.github.io/toolkit/Salient.Container.Application.html#_logOutput
107-
[registerStderrTarget()]:
108-
https://salient-labs.github.io/toolkit/Salient.Console.Console.html#_registerStderrTarget
109-
[registerTarget()]:
110-
https://salient-labs.github.io/toolkit/Salient.Console.Console.html#_registerTarget
99+
[PSR-3]: https://www.php-fig.org/psr/psr-3/

src/Toolkit/Console/Console.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
use Throwable;
2626

2727
/**
28+
* @api
29+
*
2830
* @implements FacadeAwareInterface<ConsoleInterface>
2931
*/
3032
class Console implements ConsoleInterface, FacadeAwareInterface, Unloadable

src/Toolkit/Console/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@
1414
`salient/console` provides terminal output and message logging via an API
1515
similar to `console` in web browsers.
1616

17-
- Familiar methods like [Console::log()][log] and [Console::error()][error]
18-
- Variants like [Console::logOnce()][logOnce] and
19-
[Console::errorOnce()][errorOnce] to output messages once per run
17+
- Familiar methods like [Console::log()][log()] and [Console::error()][error()]
18+
- Variants like [Console::logOnce()][logOnce()] and
19+
[Console::errorOnce()][errorOnce()] to output messages once per run
2020
- Output to multiple targets
2121
- Messages filtered by log level
2222
- Formatting that reflects message priority and improves readability
2323
- Optional Markdown-like syntax for additional formatting
2424
- Colour output to TTYs
25-
- [PSR-3 (Logger Interface)][PSR-3] support via [Console::logger()][logger]
25+
- [PSR-3 (Logger Interface)][PSR-3] support via [Console::logger()][logger()]
2626

27-
[error]:
27+
[error()]:
2828
https://salient-labs.github.io/toolkit/Salient.Core.Facade.Console.html#_error
29-
[errorOnce]:
29+
[errorOnce()]:
3030
https://salient-labs.github.io/toolkit/Salient.Core.Facade.Console.html#_errorOnce
31-
[log]:
31+
[log()]:
3232
https://salient-labs.github.io/toolkit/Salient.Core.Facade.Console.html#_log
33-
[logger]:
33+
[logger()]:
3434
https://salient-labs.github.io/toolkit/Salient.Core.Facade.Console.html#_logger
35-
[logOnce]:
35+
[logOnce()]:
3636
https://salient-labs.github.io/toolkit/Salient.Core.Facade.Console.html#_logOnce
3737
[PSR-3]: https://www.php-fig.org/psr/psr-3/
3838

src/Toolkit/Contract/Console/ConsoleInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ public function debugOnce(
291291
);
292292

293293
/**
294-
* Print "$msg1 $msg2" or similar with level- and type-base formatting
294+
* Print "$msg1 $msg2" or similar with level- and type-based formatting
295295
*
296296
* @param string $msg1 May use inline formatting tags (see {@see escape()}).
297297
* @param string|null $msg2 Inline formatting tags have no special meaning.
@@ -309,7 +309,7 @@ public function message(
309309
);
310310

311311
/**
312-
* Print "$msg1 $msg2" or similar with level- and type-base formatting once
312+
* Print "$msg1 $msg2" or similar with level- and type-based formatting once
313313
* per run
314314
*
315315
* @param string $msg1 May use inline formatting tags (see {@see escape()}).

src/Toolkit/Core/Facade/Console.php

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)