-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
py client: drop delphi_utils requirement, log to stderr instead #1486
Conversation
def log(evt, **kwargs): | ||
kwargs['event'] = evt | ||
kwargs['timestamp'] = time.strftime("%Y-%m-%d %H:%M:%S %z") | ||
return sys.stderr.write(str(kwargs) + "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might need a flush()
call to keep it synced
return sys.stderr.write(str(kwargs) + "\n") | |
sys.stderr.write(str(kwargs) + "\n") | |
sys.stderr.flush() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TL;DR: we don't need the flush()
.
>>> sys.stderr
<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>
>>> sys.stderr.line_buffering
True
io.TextIOWrapper
says this about line_buffering=True
If line_buffering is True, flush() is implied when a call to write contains a newline character or a carriage return.
Quality Gate passedIssues Measures |
Seems like a simple enough workaround 👍 . I was curious to learn a little about stderr and structlog. A few basic notes I found helpful, for future reference:
|
@dshemetov youre right, the |
Update: alright, so the good news is that the FileHandler branch is actually reached (which allows indicator-specific log files). The way this works out is that as long as the name variable is non-empty in import logging
logging.basicConfig(
format="%(message)s",
level=logging.DEBUG,
handlers=[logging.StreamHandler()] # This is the default handler
)
# Root logger gets the handler
root_logger = logging.getLogger()
assert root_logger.handlers
# Named loggers have no handlers by default
named_logger = logging.getLogger("named")
assert not named_logger.handlers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests look good, new log()
function with str({...})
looks good. Low risk, non-user facing change, removes lots of dependencies.
def log(evt, **kwargs): | ||
kwargs['event'] = evt | ||
kwargs['timestamp'] = time.strftime("%Y-%m-%d %H:%M:%S %z") | ||
return sys.stderr.write(str(kwargs) + "\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TL;DR: we don't need the flush()
.
>>> sys.stderr
<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>
>>> sys.stderr.line_buffering
True
io.TextIOWrapper
says this about line_buffering=True
If line_buffering is True, flush() is implied when a call to write contains a newline character or a carriage return.
This drops the requirement for the bloated
delphi_utils
package in the python client, and replaces thedelphi_utils.logger
with printing to STDERR instead.Addresses #1467
I havent tested this yet, and i imagine it is going to fail CI.