Skip to content

stdio_client init with errlog #645

@vincent-pli

Description

@vincent-pli

How to capture the stderr from server, I saw there is a params named: errlog, its default value is sys.stderr, that caused any stderr from server side will be print in the console/terminal

I do not like the behavior, at least I want capture the error log from server and print with prefix(maybe "error-received: {original-err}")

but I cannot figure out how to use errlog param, I write a file-like object, something like this:

class ErrorPrefixTextIO(io.TextIOBase):
    def __init__(self, original_stream=None):
        self.original_stream = original_stream or sys.stderr
    
    def write(self, message: str) -> int:
        if message.strip():
            self.original_stream.write(f"error- {message}")
            self.original_stream.flush()
        return len(message)
    
    def flush(self) -> None:
        self.original_stream.flush()

    def fileno(self) -> int:
        return self.original_stream.fileno()

    def close(self) -> None:
        if hasattr(self.original_stream, 'close'):
            self.original_stream.close()

it's not work, seems the function write is ignored at all
besides that, I also try to assign a file object to errlog, it could work, the file is write with error from server, but I cannot add any prefix to original err message. any help, thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions