splunk / eventgen

Splunk Event Generator: Eventgen
Apache License 2.0
380 stars 179 forks source link

Refactor the logging logic #264

Closed li-wu closed 5 years ago

li-wu commented 5 years ago

This is a large PR. Main changes are:

  1. Adopt structlog for better context awareness and debugging. After import the logger for example from logging_config import logger, you could use the logger as a standard logger with additional context for example:

    logger.info("Sample is loaded", name=self.sample.name, path=self.sample.path)

    Result log msg should be:

    2019-07-09 15:51:11 eventgen        INFO     MainProcess {'event': 'Logging Setup Complete.', 'name': 'sample_name', 'path': 'path_str'}

    This would be efficient for debugging especially with Splunk.

  2. Remove duplicate code especially for setup_logger, remove logger from __getstate__ and re-set the logger in __setstate__.

  3. Remove debugv from the code base.

  4. Replace warn with warning as warn is deprecated.

Things remain unchanged:

  1. Logging settings such as logging level, logger name, logging file name etc. 2.Multiprocess logging logic. I keep this part logic unchanged until a better solution to avoid performance issue etc.
  2. Ways of using the logger.