2 namespace Consolidation\Log;
4 use Symfony\Component\Console\Output\OutputInterface;
7 * Allow a log message to by styled.
9 * Styling happens in two phases:
11 * 1. Prior to message interpolation, context variables are styled
12 * via the 'style()' method, using styles provided in the context
13 * under the '_style' key, and also using styles provided by the
14 * 'defaultStyles()' method.
16 * @see Symfony\Component\Console\Logger\ConsoleLogger::interpolate()
18 * 2. After message interpolation, an appropriate method based on the
19 * log level will be called. StyledConsoleLogger::$formatFunctionMap
20 * is used to map the LogLevel to a LogOutputStylerInterface method to call.
22 * It is possible to select the exact class to use as the log styler
23 * in the constructor of StyledConsoleLogger, and the mapping from
24 * LogLevel to format function can also be extended. It is possible to
25 * add new format methods not defined here, if desired, so long as
26 * any method named in the format function map is implemented by the
27 * selected log styler class.
29 interface LogOutputStylerInterface
31 const STYLE_CONTEXT_KEY = '_style';
34 * Return an array of default styles to use in an application.
35 * The key of the style is the variable name that the style
36 * should be applied to (or '*' to match all variables that have
37 * no specific style set), and the value is the contents of the
38 * Symfony style tag to wrap around the variable value.
41 * message: 'Running {command}'
42 * context: ['command' => 'pwd']
43 * default styles: ['*' => 'info']
44 * result: 'Running <info>pwd</>'
46 public function defaultStyles();
49 * Apply styles specified in the STYLE_CONTEXT_KEY context variable to
50 * the other named variables stored in the context. The styles from
51 * the context are unioned with the default styles.
53 public function style($context);
56 * Create a wrapper object for the output stream. If this styler
57 * does not require an output wrapper, it should just return
58 * its $output parameter.
60 public function createOutputWrapper(OutputInterface $output);
63 * Print an ordinary log message, usually unstyled.
65 public function log($output, $level, $message, $context);
68 * Print a success message.
70 public function success($output, $level, $message, $context);
73 * Print an error message. Used when log level is:
74 * - LogLevel::EMERGENCY
76 * - LogLevel::CRITICAL
79 public function error($output, $level, $message, $context);
82 * Print a warning message. Used when log level is:
85 public function warning($output, $level, $message, $context);
88 * Print a note. Similar to 'text', but may contain additional
89 * styling (e.g. the task name). Used when log level is:
94 * IMPORTANT: Symfony loggers only display LogLevel::NOTICE when the
95 * the verbosity level is VERBOSITY_VERBOSE, unless overridden in the
96 * constructor. Robo\Common\Logger emits LogLevel::NOTICE at
97 * VERBOSITY_NORMAL so that these messages will always be displayed.
99 public function note($output, $level, $message, $context);
102 * Print an error message. Not used by default by StyledConsoleLogger.
104 public function caution($output, $level, $message, $context);