Adding a getChildren() method to logging.Logger

It’s been suggested that a getChildren() method be added to logging.Logger to facilitate navigating the hierarchy. I think this is a reasonable thing to add.

I’d aim to implement the method, to be documented as follows:

Returns a set of loggers which are immediate children of this logger. So for example logging.getLogger().getChildren() might return a set containing loggers named foo and bar, but a logger named foo.bar wouldn’t be included in the set. Likewise, logging.getLogger('foo').getChildren() might return a set including a logger named foo.bar, but it wouldn’t include one named foo.bar.baz.

I’d welcome any feedback you have.

1 Like

Sounds fine to me. I’m sure it can be misused, but so can everything else :slight_smile:

ISTR a discussion (years ago) about the naming convention of the logging module, and I think one of the options[1] was to leave the camelCase names there, but add anything new with snake_case conventions. This might be the first time it’s come up since then, so might be worth doing a quick search to see if it shows up.


  1. I don’t remember if this was selected or only proposed. ↩︎

1 Like

That may have been for the threading module, not logging.

1 Like

I don’t think it’s a good idea to do that. Consistency of code style locally (meaning at the module/package level) is more important.

Well this is what the previous discussion was about :slight_smile: Just remembered that it happened, and all points of view were argued out already, so if it can be found (and it applies to logging, because Eric might be right) it could save repeating the discussion.

Well if all points of view were argued out … just a bikeshed discussion, then? It doesn’t seem like it’s worth the time digging for it. I’ve already prepared the PR.

2 Likes

Pretty sure a winner was chosen, I just don’t remember which it was. (Maybe “argued out” implied more than I meant by it.)

Spent a bit of time searching and it’s not that obvious, so I guess go ahead with local consistency and if anyone wants to make a fuss then tell them to go and search harder than I did :wink:

3 Likes

This method has now been added.

2 Likes

I wonder why this method was not added initially? Were there any reasons to not add it or just nobody asked for this?

No particular reason. It was just not considered originally - nothing more than that. Generally, adding a feature vs. YAGNI is just a judgement call.