scripts/release/log.py
author Sverre Rabbelier <srabbelier@gmail.com>
Mon, 07 Sep 2009 20:06:27 +0200
changeset 2867 e8d86272e6ea
parent 1888 ef350db7f753
permissions -rw-r--r--
Use system.getHostname() everywhere Replace os.environ['HTTP_HOST'] with system.getHostname(), as a result we do not crash when 'HTTP_HOST' is unset now.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1834
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     1
# Copyright 2009 the Melange authors.
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     2
#
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     3
# Licensed under the Apache License, Version 2.0 (the "License");
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     4
# you may not use this file except in compliance with the License.
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     5
# You may obtain a copy of the License at
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     6
#
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     7
#   http://www.apache.org/licenses/LICENSE-2.0
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     8
#
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
     9
# Unless required by applicable law or agreed to in writing, software
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    10
# distributed under the License is distributed on an "AS IS" BASIS,
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    12
# See the License for the specific language governing permissions and
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    13
# limitations under the License.
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    14
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    15
"""Logging facilities.
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    16
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    17
The public interface is basically an initialization function for the
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    18
underlying Python logging module. Logging always goes to the console,
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    19
and can optionally be configured to write to a transcript file, which
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    20
will store exactly what appears on screen (minus colors).
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    21
"""
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    22
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    23
__authors__ = [
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    24
    # alphabetical order by last name, please
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    25
    '"David Anderson" <dave@natulte.net>',
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    26
    ]
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    27
1888
ef350db7f753 Style fixes for release modules.
Pawel Solyga <Pawel.Solyga@gmail.com>
parents: 1846
diff changeset
    28
1834
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    29
import logging
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    30
import sys
1834
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    31
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    32
import util
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    33
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    34
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    35
# A logging level that is even lower than DEBUG. We use this level to
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    36
# log to file only, when we need to replay something output by
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    37
# bypassing the logging system.
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    38
_TERMINAL_ECHO = 5
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    39
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    40
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    41
# Pull in the functions from the logging module, for ease of use
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    42
debug = logging.debug
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    43
info = logging.info
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    44
error = logging.error
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    45
raw = debug  # Used for logging raw output like subprocess stdout data.
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    46
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    47
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    48
# Save the actual out/err streams before init() replaces them. Users
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    49
# of the logging system can use these files if they need to bypass the
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    50
# logging system for some reason.
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    51
stdout = sys.stdout
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    52
stderr = sys.stderr
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    53
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    54
1834
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    55
class _ColorizingFormatter(logging.Formatter):
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    56
  """A logging formatter that colorizes based on log levels."""
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    57
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    58
  def format(self, record):
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    59
    msg = logging.Formatter.format(self, record)
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    60
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    61
    if record.levelno >= logging.WARNING:
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    62
      return util.colorize(msg, util.RED, bold=True)
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    63
    elif record.levelno == logging.INFO:
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    64
      return util.colorize(msg, util.GREEN)
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    65
    else:
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    66
      return msg
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    67
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    68
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    69
class _DecolorizingFormatter(logging.Formatter):
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    70
  """A logging formatter that strips color."""
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    71
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    72
  def format(self, record):
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    73
    return util.decolorize(logging.Formatter.format(self, record))
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    74
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
    75
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    76
class FileLikeLogger(object):
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    77
  """A file-like object that logs anything written to it."""
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    78
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    79
  def __init__(self):
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    80
    self._buffer = []
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    81
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    82
  def _getBuffer(self):
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    83
    data, self._buffer = ''.join(self._buffer), []
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    84
    return data
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    85
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    86
  def close(self):
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    87
    self.flush()
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    88
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    89
  def flush(self):
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    90
    raw(self._getBuffer())
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    91
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    92
  def write(self, str):
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    93
    lines = str.split('\n')
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    94
    self.writelines(lines[0:-1])
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    95
    self._buffer.append(lines[-1])
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    96
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    97
  def writelines(self, lines):
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    98
    if not lines:
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
    99
      return
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   100
    lines[0] = self._getBuffer() + lines[0]
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   101
    for line in lines:
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   102
      raw(line)
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   103
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   104
1834
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   105
def init(logfile=None):
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   106
  """Initialize the logging subsystem.
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   107
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   108
  Args:
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   109
    logfile: The filename for the transcript file, if any.
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   110
  """
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   111
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   112
  root = logging.getLogger('')
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   113
  root.setLevel(_TERMINAL_ECHO)
1834
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   114
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   115
  console = logging.StreamHandler()
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   116
  console.setLevel(logging.DEBUG)
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   117
  console.setFormatter(_ColorizingFormatter())
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   118
  root.addHandler(console)
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   119
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   120
  if logfile:
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   121
    transcript = logging.FileHandler(logfile, 'w')
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   122
    transcript.setLevel(_TERMINAL_ECHO)
1834
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   123
    transcript.setFormatter(_DecolorizingFormatter())
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   124
    root.addHandler(transcript)
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   125
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   126
  # Redirect sys.stdout and sys.stderr to logging streams. This will
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   127
  # force everything that is output in this process, even through
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   128
  # 'print', to go to both the console and the transcript (if active).
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   129
  sys.stdout = FileLikeLogger()
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   130
  sys.stderr = FileLikeLogger()
1834
0589bf1395c5 Add a log module to initialize and manage logging.
David Anderson <david.jc.anderson@gmail.com>
parents:
diff changeset
   131
1846
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   132
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   133
def terminal_echo(text, *args, **kwargs):
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   134
  """Echo a message written manually to the terminal.
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   135
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   136
  This function should be used when you want to echo into the logging
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   137
  system something that you manually wrote to the real
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   138
  stdout/stderr.
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   139
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   140
  For example, when asking the user for input, you would output the
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   141
  raw prompt to the terminal manually, read the user's response, and
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   142
  then echo both the prompt and the answer back into the logging
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   143
  system for recording.
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   144
  """
ac30e04bcbba Redirect stdout/stderr through the logging system.
David Anderson <david.jc.anderson@gmail.com>
parents: 1834
diff changeset
   145
  logging.log(_TERMINAL_ECHO, text, *args, **kwargs)