According to https://github.com/googleapis/google-cloud-python/blob/master/logging/google/cloud/logging/client.py#L309 get_default_handler has no parameters.
But if I need to set a custom logName into stackdriver logs, I need to pass name="foo" both to AppEngineHandler and CloudLoggingHandler
(moreover, from what I understand there is no way to setup the ContainerEngineHandler)
If you are calling client.get_default_handler() in your code, you can assign the name attribute (or property, for the GCE case) directly:
from google.cloud.logging import Client
client = Client()
handler = client.get_default_handler()
handler.name = 'foo'
Hi.
I tried setting manually the property, but it's not working.
Looking at the sources, if get_default_handler() returns a google.cloud.logging.handlers.handlers.CloudLoggingHandler instance, you need to set handler.transport.worker._cloud_logger.name = 'foo' because the actual message is sent in another thread, but honestly is not something I like to have running in production.
I have not looked at the other implementations, but I suspect the problem could be the same.
Hi
could you please re-open the issue?
Please explain the usecase more clearly. Setting the name of the handler during construction is no different thatn assigning it after construction.
I'm not against using the name property after the construction.
What I said is that it's not working.
I have looked at the sources and from what I understand CloudLoggingHandler doesn't look up at the name property.
In fact at the moment, in my code I set the nested (private) property handler.transport.worker._cloud_logger.name to set up the name.
OK, so the issue is that CloudLoggingHandler and AppEngineHandler both kick off their transports in their __init__, before any user-assigned name could influence the transport's name. ContainerEngineHandler doesn't have an __init__, and its name property derives from the stdlib logging.StreamHandler.
I think the solution is in two parts:
ContainerEngineHandler.__init__, taking an optional name (defaulting to None. If passed a name, the constructor should assign it (via the stdlib property).**kw to Client.get_default_handler, and pass it through utouched to whichever handler is chosen.