tintoy / seqlog

Python logging integration for Seq (https://getseq.net)
https://seqlog.readthedocs.io/
MIT License
17 stars 11 forks source link

Pylance type checking complains about structured logging on the standard logger #40

Open markledwich2 opened 3 years ago

markledwich2 commented 3 years ago

Pylance now reports problems that each of the parameters do not exist

log.info('hello {name}',  name='Mark')

Error shown: No parameter named "name" (Pylance reportGeneralTypeIssues)

I asked them and they said that I should use a seq specific log function from seqlog instead of the standard one. What would be your recommended way to use seqlog and also have pylances type checking enabled?

Vacant0mens commented 1 year ago

Sorry for the delayed response to your issue.

The Pylance team was correct, in the stdlib logging module the level-based functions support **kwargs, but the base log function doesn't. **kwargs is implemented in seqlog's main log function to add properties to what it sends to the Seq server, but those properties are not passed back to the stdlib logging module functions.

How are you initializing the logging or seqlog modules?

If you don't use override_root_logger=True when you call log_to_seq() the standard logging.info() function would send the logs to the default/root logger, which is not the seqlog logger.

Looks like you were calling log.info() though, so I'm curious: how are you initializing the logging and/or seqlog modules? Could you provide a little context?

Vacant0mens commented 1 year ago

This issue seems the same as #41. which has a bit more in-depth discussion about this topic.

Also the official documentation for the stdlib logging module uses args (when provided) to merge into msg before returning the string via getMessage() or logging it via log().

The seqlog documentation may need an update in this regard (at least for clarity's sake), but technically there is a name argument for a log record that's separate from the args argument, but it's for telling the main logging module which logger to send the log to.

I'll see about updating the documentation here to reflect the above details.