-
Notifications
You must be signed in to change notification settings - Fork 30
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
Allow make_logger() before use_*() #85
Comments
I'm not sure if this will be possible: The other part of the design is to avoid whenever possible creating or returning "wrapping" objects. Unfortunately, there are some asyncio cases where we do this: All that said, a use-case like your describe is exactly how the loggers are intended to be used (as class-attributes). Autobahn hasn't run into this requirement yet, as you basically have to import from a framework-specific package. Since the asyncio logger already has a txaio-provided object involved, it wouldn't be too disruptive to delay it doing the "real thing" until However, another option is to structure |
The " BTW: If it gets decided to not modify
|
Ah, yes @olafmandel is right there are wrappers/txaio-provided objects in both the Twisted and asyncio cases. Thanks! And yes, I agree we should either implement the enhancement you're asking for or fix the documentation to suggest "how to organize your library". |
I find myself a little hesitant to special-case logging: since you have to structure your library to have Twisted and asyncio specific imports to use the rest of txaio, it seems way more consistent to have the same behavior for logging as well. It's also impossible to use both at once, so that's not a case to consider either. The only use-case might be that you have some "actually generic" thing that is identical for both asyncio and Twisted implementations, and doesn't call any So, I currently favor fixing the documentation... |
Please allow issuing
txaio.make_logger()
before callingtxaio.use_twisted()
ortxaio.use_asyncio()
. Use case: declaring loggers as class-attributes in a library. Then importing this library is currently only possible after first selecting the used backend. But conceptually, imports should not depend on ordering or on having any (seemingly unrelated) settings be done first.Simple example: the backend must be selected at (1) already, even though it seems that (2) should be soon enough.
Possible solutions (all allow to move the backend selection from (1) to (2)):
Move (3) to
__init__()
: this turns the class-attribute into an instance-attribute. Depending on how many instances of the class get created, this may not be what the library author wants.Make
txaio._unframework.make_logger()
return a shim that gets modified into the real logger bytxaio.start_logging()
. For this each shim objects needs to register itself (see e.g.txaio.aio._loggers
ortxaio.tx._loggers
) somake_logger
can replace it.Make
txaio._unframework.make_logger()
return a shim that replaces itself with the real logger on any call to one of its methods or raises the exception if the backend is still not selected. This seems to be more hacky compared to the above option, but it does not depend ontxaio.start_logging()
ever getting called.The text was updated successfully, but these errors were encountered: