MCPcopy Index your code
hub / github.com/RustPython/RustPython / StreamHandler

Class StreamHandler

Lib/logging/__init__.py:1111–1187  ·  view source on GitHub ↗

A handler class which writes logging records, appropriately formatted, to a stream. Note that this class does not close the stream, as sys.stdout or sys.stderr may be used.

Source from the content-addressed store, hash-verified

1109 return '<%s (%s)>' % (self.__class__.__name__, level)
1110
1111class StreamHandler(Handler):
1112 """
1113 A handler class which writes logging records, appropriately formatted,
1114 to a stream. Note that this class does not close the stream, as
1115 sys.stdout or sys.stderr may be used.
1116 """
1117
1118 terminator = '\n'
1119
1120 def __init__(self, stream=None):
1121 """
1122 Initialize the handler.
1123
1124 If stream is not specified, sys.stderr is used.
1125 """
1126 Handler.__init__(self)
1127 if stream is None:
1128 stream = sys.stderr
1129 self.stream = stream
1130
1131 def flush(self):
1132 """
1133 Flushes the stream.
1134 """
1135 with self.lock:
1136 if self.stream and hasattr(self.stream, "flush"):
1137 self.stream.flush()
1138
1139 def emit(self, record):
1140 """
1141 Emit a record.
1142
1143 If a formatter is specified, it is used to format the record.
1144 The record is then written to the stream with a trailing newline. If
1145 exception information is present, it is formatted using
1146 traceback.print_exception and appended to the stream. If the stream
1147 has an 'encoding' attribute, it is used to determine how to do the
1148 output to the stream.
1149 """
1150 try:
1151 msg = self.format(record)
1152 stream = self.stream
1153 # issue 35046: merged two stream.writes into one.
1154 stream.write(msg + self.terminator)
1155 self.flush()
1156 except RecursionError: # See issue 36272
1157 raise
1158 except Exception:
1159 self.handleError(record)
1160
1161 def setStream(self, stream):
1162 """
1163 Sets the StreamHandler&#x27;s stream to the specified value,
1164 if it is different.
1165
1166 Returns the old stream, if the stream was changed, or None
1167 if it wasn&#x27;t.
1168 """

Callers 1

basicConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected