You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you set service="foo" in your child in the first example it should work.
We need to make the docs clearer here, so please allow me to explain what's going on (I'm on my phone so it'll be a longer response than usual)
Service is what defines what the function is responsible for, or part of (e.g payment service).
For Logger, the service is the logging key customers will use to search log operations for one or more functions, for example - "Search for all error, or messages like X, where service is payment".
That said, customers can set the service using explicit arguments, but typically use as an environment variable since it's used across all utilities and to avoid repetition - POWERTOOLS_SERVICE_NAME
With that hopefully explained, let's get to inheritance.
Python Logging hierarchy happens at the dot notation (service, service.child, service.child_2).
For that to work seamlessly, we name all parent Loggers, no child param, with the value defined in the service param.
For child Loggers we introspect the name of your module where Logger(child=True) is called, and name your Logger as "service.filename".
Once both Loggers are registered, and Python Logging recognises the dot notation, it fixes up the hierarchy and event propagation.
Why the first sample didn't work
Python Logger doesn't recognise as a parent + child loggers because their names are different, since service param value is different.
Parent logger is named "foo"
Child logger is named "service_undefined"
If you were to use the same service name in the Child logger that should work, as that will then be "foo.bar", where bar comes from bar.py
Why the service key isn't foo.bar
That's because of consistency. The service/application is still the same despite having multiple Loggers.
Sorry for the long explanation but hope that clarifies it - Lemme know otherwise :)
@heitorlessa Ok, perhaps I'm just not using this library correctly then. All the examples assume service, where python loggers are more typically using the logger name in the record. So I just assumed service === name for the purposes of this library.
I suppose I don't particularly care about the service name for our use case. I do care about specifically where in the module the message was generated. It looks like this module is using the location for that purpose, but that is just bar instead of the logger name (foo.bar).
Agreed, given the ability to override location formatting, documentation updates would be sufficient. Ability to suppress keys would be a nice-to-have, but I don't have a strong opinion there.
Activity
michaelbrewer commentedon Aug 27, 2020
I would suspect this is at fault:
heitorlessa commentedon Aug 27, 2020
Hey Loren - Thanks for raising this issue.
If you set service="foo" in your child in the first example it should work.
We need to make the docs clearer here, so please allow me to explain what's going on (I'm on my phone so it'll be a longer response than usual)
Service is what defines what the function is responsible for, or part of (e.g payment service).
For Logger, the service is the logging key customers will use to search log operations for one or more functions, for example - "Search for all error, or messages like X, where service is payment".
That said, customers can set the service using explicit arguments, but typically use as an environment variable since it's used across all utilities and to avoid repetition - POWERTOOLS_SERVICE_NAME
With that hopefully explained, let's get to inheritance.
Python Logging hierarchy happens at the dot notation (service, service.child, service.child_2).
For that to work seamlessly, we name all parent Loggers, no child param, with the value defined in the service param.
For child Loggers we introspect the name of your module where Logger(child=True) is called, and name your Logger as "service.filename".
Once both Loggers are registered, and Python Logging recognises the dot notation, it fixes up the hierarchy and event propagation.
Why the first sample didn't work
Python Logger doesn't recognise as a parent + child loggers because their names are different, since service param value is different.
If you were to use the same service name in the Child logger that should work, as that will then be "foo.bar", where bar comes from bar.py
Why the service key isn't foo.bar
That's because of consistency. The service/application is still the same despite having multiple Loggers.
Sorry for the long explanation but hope that clarifies it - Lemme know otherwise :)
Thanks
lorengordon commentedon Aug 27, 2020
@heitorlessa Ok, perhaps I'm just not using this library correctly then. All the examples assume
service, where python loggers are more typically using the loggernamein the record. So I just assumedservice===namefor the purposes of this library.I suppose I don't particularly care about the service name for our use case. I do care about specifically where in the module the message was generated. It looks like this module is using the
locationfor that purpose, but that is justbarinstead of the logger name (foo.bar).heitorlessa commentedon Aug 27, 2020
That is correct - location is where funcName:lineNumber will be present, hence bar:lineNo
We didn't include the name parameter for brevity, and for preventing mistakes such as name==name which wouldn't work.
michaelbrewer commentedon Aug 27, 2020
@heitorlessa personally I would prefer if "location" included the module it was benign logged from.
This would be similar to other logging libraries.
lorengordon commentedon Aug 27, 2020
Gotcha. Yeah, the function name is definitely not enough info. Is there some way we can set
locationto something likepackage.module.function:line?heitorlessa commentedon Aug 27, 2020
@michaelbrewer I think it might be easier to have an option to override log record attributes.
When we started, we heard from beta customers the opposite, as the module wasn't always valuable.
michaelbrewer commentedon Aug 27, 2020
Maybe we can allow for a custom pattern for this. As in some cases you don't want the location field to be too long.
lorengordon commentedon Aug 27, 2020
That would be fine. Coming from python logging, we're used to setting the
logformatwith our custom preferences.6 remaining items
lorengordon commentedon Aug 27, 2020
Ok, nice, so overriding
locationalready works:heitorlessa commentedon Aug 27, 2020
Yes, you can override "location", "timestamp", "level", and "datefmt" - I just haven't documented them.
If you're okay with it being this way, then we just need:
I'll check the responses tomorrow
michaelbrewer commentedon Aug 27, 2020
@lorengordon @heitorlessa - looks like documentation updates and #140 might address this.
$ POWERTOOLS_SERVICE_NAME=falcon python space.py {"location": "space.fly:7", "message": "takeoff", "level": "INFO", "service": "falcon", "sampling_rate": 0.0}lorengordon commentedon Aug 28, 2020
Agreed, given the ability to override
locationformatting, documentation updates would be sufficient. Ability to suppress keys would be a nice-to-have, but I don't have a strong opinion there.heitorlessa commentedon Aug 28, 2020
We've just merged @michaelbrewer PR on ability to suppress and order a few keys - Working on a PR for the docs piece now
heitorlessa commentedon Aug 28, 2020
@lorengordon @michaelbrewer could you please take a look and tell me whether this clarifies these and other questions?
#148
lorengordon commentedon Aug 28, 2020
@heitorlessa looks good to me! thanks!
michaelbrewer commentedon Aug 28, 2020
@heitorlessa looks good
heitorlessa commentedon Sep 7, 2020
This has now available in 1.5.0 release