Browse Source

Add logging prefix

pull/14/head 2.3.3
Richard Neumann 3 years ago
parent
commit
2b9ea6bcfa
  1. 16
      rcon/source/proto.py

16
rcon/source/proto.py

@ -61,19 +61,19 @@ class Type(Enum):
return bytes(self.value) return bytes(self.value)
@classmethod @classmethod
async def aread(cls, reader: StreamReader) -> Type: async def aread(cls, reader: StreamReader, *, prefix: str = '') -> Type:
"""Read the type from an asynchronous file-like object.""" """Read the type from an asynchronous file-like object."""
LOGGER.debug('Reading type asynchronously.') LOGGER.debug('%sReading type asynchronously.', prefix)
value = await LittleEndianSignedInt32.aread(reader) value = await LittleEndianSignedInt32.aread(reader)
LOGGER.debug(' => value: %i', value) LOGGER.debug('%s => value: %i', prefix, value)
return cls(value) return cls(value)
@classmethod @classmethod
def read(cls, file: IO) -> Type: def read(cls, file: IO, *, prefix: str = '') -> Type:
"""Read the type from a file-like object.""" """Read the type from a file-like object."""
LOGGER.debug('Reading type.') LOGGER.debug('%sReading type.', prefix)
value = LittleEndianSignedInt32.read(file) value = LittleEndianSignedInt32.read(file)
LOGGER.debug(' => value: %i', value) LOGGER.debug('%s => value: %i', prefix, value)
return cls(value) return cls(value)
@ -116,7 +116,7 @@ class Packet(NamedTuple):
LOGGER.debug(' => size: %i', size) LOGGER.debug(' => size: %i', size)
id_ = await LittleEndianSignedInt32.aread(reader) id_ = await LittleEndianSignedInt32.aread(reader)
LOGGER.debug(' => id: %i', id_) LOGGER.debug(' => id: %i', id_)
type_ = await Type.aread(reader) type_ = await Type.aread(reader, prefix=' ')
LOGGER.debug(' => type: %i', type_) LOGGER.debug(' => type: %i', type_)
payload = await reader.read(size - 10) payload = await reader.read(size - 10)
LOGGER.debug(' => payload: %s', payload) LOGGER.debug(' => payload: %s', payload)
@ -136,7 +136,7 @@ class Packet(NamedTuple):
LOGGER.debug(' => size: %i', size) LOGGER.debug(' => size: %i', size)
id_ = LittleEndianSignedInt32.read(file) id_ = LittleEndianSignedInt32.read(file)
LOGGER.debug(' => id: %i', id_) LOGGER.debug(' => id: %i', id_)
type_ = Type.read(file) type_ = Type.read(file, prefix=' ')
LOGGER.debug(' => type: %i', type_) LOGGER.debug(' => type: %i', type_)
payload = file.read(size - 10) payload = file.read(size - 10)
LOGGER.debug(' => payload: %s', payload) LOGGER.debug(' => payload: %s', payload)

Loading…
Cancel
Save