Skip to content

Enhancement: Add default name to default seqlog logger created with log_to_seq() #57

@Vacant0mens

Description

@Vacant0mens
  • SeqLog version: 0.3.26
  • Python version: 3.11+

Disclaimer

I'm not an expert with the seqlog module. I try to do my best research before posting issues on GitHub, but I'm only human. If any of the following is inaccurate, feel free to correct me.

Also, I am willing to do the coding work for this. I just wanted to (1) have a discussion about it first (if needed), (2) track my idea and its progress, and (3) make sure I wasn't misunderstanding the way that the seqlog module was put together.

Description

(This is in response to issues #40 and #41 regarding the Usage documentation page, as well as the seqlog.log_to_seq() module-level function)

For clarity and flexibility, a name argument should be added to log_to_seq() (with a default value). It can't currently be provided by adding it as a kwarg, because logging.basicConfig() doesn't accept a name argument. If it's not set somewhere it results in the logger's name property being set to '__main__', which isn't easily searchable. (However, It is possible to call logging.getLogger(name=__name__) to get the currently-configured Logger instance if the current logger wasn't given a name, but this is not very user-friendly.)

The stdlib logging documentation states:

[The logging.setLoggerClass(klass) function] is typically called before any loggers are instantiated by applications which need to use custom logger behavior. After this call, as at any other time, do not instantiate loggers directly using the subclass; continue using the logging.getLogger() API to get your loggers.

While this may be true for a lot of use cases for the seqlog module, the log_to_seq() function should instantiate (and return) the StructuredLogger class rather than creating a default instance of it and returning SeqLogHandler. (in my opinion, returning the logger would make more sense to the users.) That way it's not assumed that StructuredLogger is the only logger or logger class that any given user will be using.

Suggested Actions

  1. Update the log_to_seq() function to accept a name argument and give it a default value (something like DefaultSeqLogger would be fine, or DefaultSeqRootLogger if override_root_logger=True).
  2. Within the log_to_seq() function, instantiate the StructuredLogger class (with name as given or its default value), assign the class a new instance of SeqLogHandler with loggerClass.addHandler() (using the same arguments to instantiate it as are currently there).
  3. Update the Usage documentation to reflect the above changes and/or expand the topic of instantiating the StructuredLogger class and its handler/s.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions