comparison vendor/wikimedia/composer-merge-plugin/src/Logger.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2 /**
3 * This file is part of the Composer Merge plugin.
4 *
5 * Copyright (C) 2015 Bryan Davis, Wikimedia Foundation, and contributors
6 *
7 * This software may be modified and distributed under the terms of the MIT
8 * license. See the LICENSE file for details.
9 */
10
11 namespace Wikimedia\Composer;
12
13 use Composer\IO\IOInterface;
14
15 /**
16 * Simple logging wrapper for Composer\IO\IOInterface
17 *
18 * @author Bryan Davis <bd808@bd808.com>
19 */
20 class Logger
21 {
22 /**
23 * @var string $name
24 */
25 protected $name;
26
27 /**
28 * @var IOInterface $inputOutput
29 */
30 protected $inputOutput;
31
32 /**
33 * @param string $name
34 * @param IOInterface $io
35 */
36 public function __construct($name, IOInterface $io)
37 {
38 $this->name = $name;
39 $this->inputOutput = $io;
40 }
41
42 /**
43 * Log a debug message
44 *
45 * Messages will be output at the "very verbose" logging level (eg `-vv`
46 * needed on the Composer command).
47 *
48 * @param string $message
49 */
50 public function debug($message)
51 {
52 if ($this->inputOutput->isVeryVerbose()) {
53 $message = " <info>[{$this->name}]</info> {$message}";
54 $this->log($message);
55 }
56 }
57
58 /**
59 * Log an informative message
60 *
61 * Messages will be output at the "verbose" logging level (eg `-v` needed
62 * on the Composer command).
63 *
64 * @param string $message
65 */
66 public function info($message)
67 {
68 if ($this->inputOutput->isVerbose()) {
69 $message = " <info>[{$this->name}]</info> {$message}";
70 $this->log($message);
71 }
72 }
73
74 /**
75 * Log a warning message
76 *
77 * @param string $message
78 */
79 public function warning($message)
80 {
81 $message = " <error>[{$this->name}]</error> {$message}";
82 $this->log($message);
83 }
84
85 /**
86 * Write a message
87 *
88 * @param string $message
89 */
90 protected function log($message)
91 {
92 if (method_exists($this->inputOutput, 'writeError')) {
93 $this->inputOutput->writeError($message);
94 } else {
95 // @codeCoverageIgnoreStart
96 // Backwards compatiblity for Composer before cb336a5
97 $this->inputOutput->write($message);
98 // @codeCoverageIgnoreEnd
99 }
100 }
101 }
102 // vim:sw=4:ts=4:sts=4:et: