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