Skip to content
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

Fixes #76 #78

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Fixes #76 #78

wants to merge 12 commits into from

Conversation

piotrmaslanka
Copy link
Collaborator

@piotrmaslanka piotrmaslanka commented Dec 13, 2024

Since this introduces some breaking changes, I'd invite @tintoy to express what should be left.

Right now everything can be configured using logging.config.dictConfig() including CLEF, override_root_logger and use_structured_logging

Also, this adds an option for ConsoleStructuredLogHandler to output to stderr. It's a config option.

I've tested it on my staging environment.

Also, I wonder, because right now by configuring one handler you can change the feature flags globally (for other loggers), shouldn't we move that to private properties of SeqLogHandlers? Because this behavior is not immediately obvious and somewhat astonishing.

Also, current implementation allows you to configure whether to use CLEF on the level of a ConsoleStructuredLogHandler, which is a code smell (and just plainly doesn't make sense, as a ConsoleStructuredLogHandler will never have to deal with CLEF), which amounts to, how one physicist put it as "spooky action at a distance".

I suggest we slowly shift towards per-handler configuration instead of global feature flags.

@piotrmaslanka piotrmaslanka marked this pull request as ready for review December 13, 2024 20:10
@tintoy
Copy link
Owner

tintoy commented Dec 13, 2024

Thanks! I’m hoping to give this my full attention sometime over the weekend.

@tintoy
Copy link
Owner

tintoy commented Dec 14, 2024

BTW, I agree with you about feature flags; that started off as something truly global but over time has started to include things that should be per-logger. Part of the problem is that our loggers are created by the logging library (which appears to only support a global configuration). But it’s been ages since I looked at it so if you know of a more-specific configuration mechanism then I’m happy for us to use that.

@piotrmaslanka
Copy link
Collaborator Author

piotrmaslanka commented Dec 14, 2024

I suggest the following solution:

  • the things that should stay local (like using CLEF or not reporting failures) will be moved into the constructor of the SeqLogHandler
  • the things that should stay global (like global properties) - they will still stay global

But I still have the following problems:

  • overriding the logger can't be done via dictConfig(), so it has to stay as a separate method, preferably to be invoked by the user before they even touch logging - logging.setLoggerClass(StructuredLogger) has a nice ring to it
  • either the behaviour of StructuredLogger will continue on global properties or we reimplement dictConfig() to allow people to configure their loggers. Right now, this is not possible, as they are allowed to take only 2 arguments - name and level, and I would like to keep it that way, lest we unleash hell. Imagine - every logger variable in each module could behave in a different way. This is pure madness.

Or:

  • We can define our own dictConfig() that will do the job, pop some parameters, and hand over the rest to Python's dictConfig() that will take a bunch of keys like use_structured_logging or override_logger. I think this is the best solution, overall. fileConfig()'s just not worth that much since they changed the syntax, and I suggest we entirely abandon it.

What say you, @tintoy ?

@tintoy
Copy link
Owner

tintoy commented Dec 15, 2024

Yeah, I think part of the problem is that python's logging module is essentially global

We can define our own dictConfig() that will do the job

This was what configure_from_dict was meant to handle but it has gradually mutated over time 🙂

logging.setLoggerClass(StructuredLogger) has a nice ring to it

I'm hoping we can provide a more intuitive API to do this (just a function like use_seq_structured_logging() or similar) because, while consumers need to set the logger class, it's not all that obvious why they need to set the logger class.

I would like to keep it that way, lest we unleash hell

No argument here 😂

If we had to, I guess we could introduce a logger-name-or-regex approach to individual logger instance configuration, but again, it might start to feel a bit like reinventing the logging module 🤪

We can define our own dictConfig() that will do the job, pop some parameters, and hand over the rest to Python's dictConfig() that will take a bunch of keys like use_structured_logging or override_logger. I think this is the best solution, overall. fileConfig()'s just not worth that much since they changed the syntax, and I suggest we entirely abandon it.

Yes - this feels much cleaner to me, too. I'm not too fussed about removing functionality that doesn't make sense as long as we sketch out a migration path for existing consumers in the docs ("migrating from v0.x" could include a workaround for the fact that fileConfig() has changed, such as "load YAML from file into dict, and call seqlog's configure_from_dict)...

docs/usage.rst Outdated Show resolved Hide resolved
@tintoy
Copy link
Owner

tintoy commented Dec 15, 2024

I like the if_not_configured, too. Much more deterministic!

Copy link
Owner

@tintoy tintoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor suggestions in the PR comments, but either way this looks good to me 🙂

@piotrmaslanka
Copy link
Collaborator Author

piotrmaslanka commented Dec 20, 2024

@tintoy I've decided to practically completely refactor the project and move all of the configuration into the dictionary/YAML.

I'm currently testing it on my staging environment for my production (so far everything works), and it seems that you can now configure it with a single command.

I'm re-requesting a review.

@piotrmaslanka piotrmaslanka requested a review from tintoy December 20, 2024 14:57
@tintoy
Copy link
Owner

tintoy commented Dec 20, 2024

Cheers - will take a look at this later today 🙂

@tintoy
Copy link
Owner

tintoy commented Dec 21, 2024

Will take a closer look on my computer but, at first glance (hooray for Code Spaces - even on an iPhone 😂), this looks great!

@tintoy
Copy link
Owner

tintoy commented Dec 22, 2024

Had a look on a full-size monitor and, yep, this looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean up the mess related to configure_from_file and configure_from_dict Help with implementation
2 participants