Drush: lib/Drush/Log/Logger.php Source File

Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * Contains \Drush\Log\Logger.
6  *
7  * This is the actual Logger for Drush that is responsible
8  * for logging messages.
9  *
10  * This logger is designed such that it can be provided to
11  * other libraries that log to a Psr\Log\LoggerInterface.
12  * As such, it takes responsibility for passing log messages
13  * to backend invoke, as necessary (c.f. drush_backend_packet()).
14  *
15  * Drush supports all of the required log levels from Psr\Log\LogLevel,
16  * and also defines its own. See Drush\Log\LogLevel.
17  *
18  * Those who may wish to change the way logging works in Drush
19  * should therefore NOT attempt to replace this logger with their
20  * own LoggerInterface, as it will not work. It would be okay
21  * to extend Drush\Log\Logger, or perhaps we could provide a way
22  * to set an output I/O object here, in case output redirection
23  * was the only thing that needed to be swapped out.
24  */
25 
26 namespace Drush\Log;
27 
29 use Psr\Log\AbstractLogger;
30 use Robo\Log\RoboLogger;
31 use Symfony\Component\Console\Output\OutputInterface;
32 
33 class Logger extends RoboLogger {
34 
35  public function __construct(OutputInterface $output) {
36  parent::__construct($output);
37  }
38 
39  public function log($level, $message, array $context = array()) {
40  // Convert to old $entry array for b/c calls
41  $entry = $context + [
42  'type' => $level,
43  'message' => $message,
44  'timestamp' => microtime(TRUE),
45  'memory' => memory_get_usage(),
46  ];
47 
48  // Drush\Log\Logger should take over all of the responsibilities
49  // of drush_log, including caching the log messages and sending
50  // log messages along to backend invoke.
51  // TODO: move these implementations inside this class.
52  $log =& drush_get_context('DRUSH_LOG', array());
53  $log[] = $entry;
54  if ($level != LogLevel::DEBUG_NOTIFY) {
55  drush_backend_packet('log', $entry);
56  }
57 
58  if (drush_get_context('DRUSH_NOCOLOR')) {
59  $red = "[%s]";
60  $yellow = "[%s]";
61  $green = "[%s]";
62  }
63  else {
64  $red = "\033[31;40m\033[1m[%s]\033[0m";
65  $yellow = "\033[1;33;40m\033[1m[%s]\033[0m";
66  $green = "\033[1;32;40m\033[1m[%s]\033[0m";
67  }
68 
69  $verbose = drush_get_context('DRUSH_VERBOSE');
70  $debug = drush_get_context('DRUSH_DEBUG');
71  $debugnotify = drush_get_context('DRUSH_DEBUG_NOTIFY');
72 
73  // Save the original level in the context name, then
74  // map it to a standard log level.
75  $context['name'] = $level;
76  switch ($level) {
77  case LogLevel::WARNING :
78  case LogLevel::CANCEL :
79  $type_msg = sprintf($yellow, $level);
80  $level = LogLevel::WARNING;
81  break;
82  case 'failed' : // Obsolete; only here in case contrib is using it.
83  case LogLevel::EMERGENCY : // Not used by Drush
84  case LogLevel::ALERT : // Not used by Drush
85  case LogLevel::ERROR :
86  $type_msg = sprintf($red, $level);
87  break;
88  case LogLevel::OK :
89  case 'completed' : // Obsolete; only here in case contrib is using it.
90  case LogLevel::SUCCESS :
91  case 'status': // Obsolete; only here in case contrib is using it.
92  // In quiet mode, suppress progress messages
93  if (drush_get_context('DRUSH_QUIET')) {
94  return TRUE;
95  }
96  $type_msg = sprintf($green, $level);
97  $level = LogLevel::NOTICE;
98  break;
99  case LogLevel::NOTICE :
100  $type_msg = sprintf("[%s]", $level);
101  break;
102  case 'message' : // Obsolete; only here in case contrib is using it.
103  case LogLevel::INFO :
104  if (!$verbose) {
105  // print nothing. exit cleanly.
106  return TRUE;
107  }
108  $type_msg = sprintf("[%s]", $level);
109  $level = LogLevel::INFO;
110  break;
111  case LogLevel::DEBUG_NOTIFY :
112  $level = LogLevel::DEBUG; // Report 'debug', handle like 'preflight'
113  case LogLevel::PREFLIGHT :
114  if (!$debugnotify) {
115  // print nothing unless --debug AND --verbose. exit cleanly.
116  return TRUE;
117  }
118  $type_msg = sprintf("[%s]", $level);
119  $level = LogLevel::DEBUG;
120  break;
121  case LogLevel::BOOTSTRAP :
122  case LogLevel::DEBUG :
123  default :
124  if (!$debug) {
125  // print nothing. exit cleanly.
126  return TRUE;
127  }
128  $type_msg = sprintf("[%s]", $level);
129  $level = LogLevel::DEBUG;
130  break;
131  }
132 
133  // When running in backend mode, log messages are not displayed, as they will
134  // be returned in the JSON encoded associative array.
135  if (drush_get_context('DRUSH_BACKEND')) {
136  return;
137  }
138 
139  $columns = drush_get_context('DRUSH_COLUMNS', 80);
140 
141  $width[1] = 11;
142  // Append timer and memory values.
143  if ($debug) {
144  $timer = sprintf('[%s sec, %s]', round($entry['timestamp']-DRUSH_REQUEST_TIME, 2), drush_format_size($entry['memory']));
145  $entry['message'] = $entry['message'] . ' ' . $timer;
146  }
147 
148  $message = $entry['message'];
149 /*
150  // Drush-styled output
151 
152  $message = $this->interpolate(
153  $message,
154  $this->getLogOutputStyler()->style($context)
155  );
156 
157  $width[0] = ($columns - 11);
158 
159  $format = sprintf("%%-%ds%%%ds", $width[0], $width[1]);
160 
161  // Place the status message right aligned with the top line of the error message.
162  $message = wordwrap($message, $width[0]);
163  $lines = explode("\n", $message);
164  $lines[0] = sprintf($format, $lines[0], $type_msg);
165  $message = implode("\n", $lines);
166  $this->getErrorStreamWrapper()->writeln($message);
167 */
168  // Robo-styled output
169  parent::log($level, $message, $context);
170  }
171 }

File

doxygen/html/Logger_8php_source.html
View source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Drush: lib/Drush/Log/Logger.php Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Drush
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_97aefd0d527b934f1d99a682da8fe6a9.html">lib</a></li><li class="navelem"><a class="el" href="dir_7b370e47d51b6becf2e7a17c4b4a6c45.html">Drush</a></li><li class="navelem"><a class="el" href="dir_cca3ff55e07cf2aea2edabd4ec122dfd.html">Log</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Logger.php</div>  </div>
</div><!--header-->
<div class="contents">
<a href="Logger_8php.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;&lt;?php</div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * @file</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * Contains \Drush\Log\Logger.</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> * This is the actual Logger for Drush that is responsible</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> * for logging messages.</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * This logger is designed such that it can be provided to</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> * other libraries that log to a Psr\Log\LoggerInterface.</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> * As such, it takes responsibility for passing log messages</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> * to backend invoke, as necessary (c.f. drush_backend_packet()).</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> * Drush supports all of the required log levels from Psr\Log\LogLevel,</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="comment"> * and also defines its own. See Drush\Log\LogLevel.</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="comment"> * Those who may wish to change the way logging works in Drush</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="comment"> * should therefore NOT attempt to replace this logger with their</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="comment"> * own LoggerInterface, as it will not work.  It would be okay</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment"> * to extend Drush\Log\Logger, or perhaps we could provide a way</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="comment"> * to set an output I/O object here, in case output redirection</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="comment"> * was the only thing that needed to be swapped out.</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="keyword">namespace </span>Drush\Log;</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;use <a class="code" href="classDrush_1_1Log_1_1LogLevel.html">Drush\Log\LogLevel</a>;</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;use Psr\Log\AbstractLogger;</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;use Robo\Log\RoboLogger;</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;use  Symfony\Component\Console\Output\OutputInterface;</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;</div>
<div class="line"><a name="l00033"></a><span class="lineno"><a class="code" href="classDrush_1_1Log_1_1Logger.html">   33</a></span>&#160;<span class="keyword">class </span><a class="code" href="classDrush_1_1Log_1_1Logger.html">Logger</a> <span class="keyword">extends</span> RoboLogger {</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;    <span class="keyword">public</span> <span class="keyword">function</span> __construct(OutputInterface $output) {</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;      parent::__construct($output);</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;    }</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;    <span class="keyword">public</span> <span class="keyword">function</span> log($level, $message, array $context = array()) {</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;      <span class="comment">// Convert to old $entry array for b/c calls</span></div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;      $entry = $context + [</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;        <span class="stringliteral">&#39;type&#39;</span> =&gt; $level,</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        <span class="stringliteral">&#39;message&#39;</span> =&gt; $message,</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        <span class="stringliteral">&#39;timestamp&#39;</span> =&gt; microtime(TRUE),</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        <span class="stringliteral">&#39;memory&#39;</span> =&gt; memory_get_usage(),</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;      ];</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;      <span class="comment">// Drush\Log\Logger should take over all of the responsibilities</span></div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;      <span class="comment">// of drush_log, including caching the log messages and sending</span></div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;      <span class="comment">// log messages along to backend invoke.</span></div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;      <span class="comment">// TODO: move these implementations inside this class.</span></div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;      $log =&amp; <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_LOG&#39;</span>, array());</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;      $log[] = $entry;</div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;      <span class="keywordflow">if</span> ($level != LogLevel::DEBUG_NOTIFY) {</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;        <a class="code" href="backend_8inc.html#a38490210d77373f3d8492caf4e9a3190">drush_backend_packet</a>(<span class="stringliteral">&#39;log&#39;</span>, $entry);</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;      }</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;      <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_NOCOLOR&#39;</span>)) {</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        $red = <span class="stringliteral">&quot;[%s]&quot;</span>;</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        $yellow = <span class="stringliteral">&quot;[%s]&quot;</span>;</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;        $green = <span class="stringliteral">&quot;[%s]&quot;</span>;</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;      }</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;      <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;        $red = <span class="stringliteral">&quot;\033[31;40m\033[1m[%s]\033[0m&quot;</span>;</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;        $yellow = <span class="stringliteral">&quot;\033[1;33;40m\033[1m[%s]\033[0m&quot;</span>;</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;        $green = <span class="stringliteral">&quot;\033[1;32;40m\033[1m[%s]\033[0m&quot;</span>;</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;      }</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;      $verbose = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_VERBOSE&#39;</span>);</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;      $debug = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_DEBUG&#39;</span>);</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;      $debugnotify = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_DEBUG_NOTIFY&#39;</span>);</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;      <span class="comment">// Save the original level in the context name, then</span></div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;      <span class="comment">// map it to a standard log level.</span></div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;      $context[<span class="stringliteral">&#39;name&#39;</span>] = $level;</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;      <span class="keywordflow">switch</span> ($level) {</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;        <span class="keywordflow">case</span> LogLevel::WARNING :</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;        <span class="keywordflow">case</span> LogLevel::CANCEL :</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;          $type_msg = sprintf($yellow, $level);</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;          $level = LogLevel::WARNING;</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;          <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;        <span class="keywordflow">case</span> <span class="stringliteral">&#39;failed&#39;</span> : <span class="comment">// Obsolete; only here in case contrib is using it.</span></div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;        <span class="keywordflow">case</span> LogLevel::EMERGENCY : <span class="comment">// Not used by Drush</span></div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;        <span class="keywordflow">case</span> LogLevel::ALERT : <span class="comment">// Not used by Drush</span></div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;        <span class="keywordflow">case</span> LogLevel::ERROR :</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;          $type_msg = sprintf($red, $level);</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;          <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;        <span class="keywordflow">case</span> LogLevel::OK :</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;        <span class="keywordflow">case</span> <span class="stringliteral">&#39;completed&#39;</span> : <span class="comment">// Obsolete; only here in case contrib is using it.</span></div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;        <span class="keywordflow">case</span> LogLevel::SUCCESS :</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;        <span class="keywordflow">case</span> <span class="stringliteral">&#39;status&#39;</span>: <span class="comment">// Obsolete; only here in case contrib is using it.</span></div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;          <span class="comment">// In quiet mode, suppress progress messages</span></div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;          <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_QUIET&#39;</span>)) {</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;            <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;          }</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;          $type_msg = sprintf($green, $level);</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;          $level = LogLevel::NOTICE;</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;          <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;        <span class="keywordflow">case</span> LogLevel::NOTICE :</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;          $type_msg = sprintf(<span class="stringliteral">&quot;[%s]&quot;</span>, $level);</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;          <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;        <span class="keywordflow">case</span> <span class="stringliteral">&#39;message&#39;</span> : <span class="comment">// Obsolete; only here in case contrib is using it.</span></div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;        <span class="keywordflow">case</span> LogLevel::INFO :</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;          <span class="keywordflow">if</span> (!$verbose) {</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;            <span class="comment">// print nothing. exit cleanly.</span></div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;            <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;          }</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;          $type_msg = sprintf(<span class="stringliteral">&quot;[%s]&quot;</span>, $level);</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;          $level = LogLevel::INFO;</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;          <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;        <span class="keywordflow">case</span> LogLevel::DEBUG_NOTIFY :</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;          $level = LogLevel::DEBUG; <span class="comment">// Report &#39;debug&#39;, handle like &#39;preflight&#39;</span></div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;        <span class="keywordflow">case</span> LogLevel::PREFLIGHT :</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;          <span class="keywordflow">if</span> (!$debugnotify) {</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;            <span class="comment">// print nothing unless --debug AND --verbose. exit cleanly.</span></div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;            <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;          }</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;          $type_msg = sprintf(<span class="stringliteral">&quot;[%s]&quot;</span>, $level);</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;          $level = LogLevel::DEBUG;</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;          <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;        <span class="keywordflow">case</span> LogLevel::BOOTSTRAP :</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;        <span class="keywordflow">case</span> LogLevel::DEBUG :</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;        <span class="keywordflow">default</span> :</div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;          <span class="keywordflow">if</span> (!$debug) {</div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;            <span class="comment">// print nothing. exit cleanly.</span></div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;            <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;          }</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;          $type_msg = sprintf(<span class="stringliteral">&quot;[%s]&quot;</span>, $level);</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;          $level = LogLevel::DEBUG;</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;          <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;      }</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;      <span class="comment">// When running in backend mode, log messages are not displayed, as they will</span></div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;      <span class="comment">// be returned in the JSON encoded associative array.</span></div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;      <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_BACKEND&#39;</span>)) {</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;        <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;      }</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;      $columns = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_COLUMNS&#39;</span>, 80);</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;      $width[1] = 11;</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;      <span class="comment">// Append timer and memory values.</span></div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;      <span class="keywordflow">if</span> ($debug) {</div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;        $timer = sprintf(<span class="stringliteral">&#39;[%s sec, %s]&#39;</span>, round($entry[<span class="stringliteral">&#39;timestamp&#39;</span>]-DRUSH_REQUEST_TIME, 2), drush_format_size($entry[<span class="stringliteral">&#39;memory&#39;</span>]));</div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;        $entry[<span class="stringliteral">&#39;message&#39;</span>] = $entry[<span class="stringliteral">&#39;message&#39;</span>] . <span class="charliteral">&#39; &#39;</span> . $timer;</div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;      }</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;</div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;      $message = $entry[<span class="stringliteral">&#39;message&#39;</span>];</div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;<span class="comment">/*</span></div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;<span class="comment">      // Drush-styled output</span></div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;<span class="comment">      $message = $this-&gt;interpolate(</span></div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;<span class="comment">          $message,</span></div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;<span class="comment">          $this-&gt;getLogOutputStyler()-&gt;style($context)</span></div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;<span class="comment">      );</span></div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;<span class="comment">      $width[0] = ($columns - 11);</span></div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;<span class="comment">      $format = sprintf(&quot;%%-%ds%%%ds&quot;, $width[0], $width[1]);</span></div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;<span class="comment">      // Place the status message right aligned with the top line of the error message.</span></div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;<span class="comment">      $message = wordwrap($message, $width[0]);</span></div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;<span class="comment">      $lines = explode(&quot;\n&quot;, $message);</span></div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;<span class="comment">      $lines[0] = sprintf($format, $lines[0], $type_msg);</span></div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;<span class="comment">      $message = implode(&quot;\n&quot;, $lines);</span></div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;<span class="comment">      $this-&gt;getErrorStreamWrapper()-&gt;writeln($message);</span></div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;<span class="comment">*/</span></div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;      <span class="comment">// Robo-styled output</span></div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;      parent::log($level, $message, $context);</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;    }</div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;}</div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Nov 2 2016 07:29:07 for Drush by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.2
</small></address>
</body>
</html>