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

DTT1 - Iteration 3 - General improvements - Standard logging #4888

Closed
4 tasks done
Tracked by #4871
fcaffieri opened this issue Jan 30, 2024 · 5 comments · Fixed by #4897
Closed
4 tasks done
Tracked by #4871

DTT1 - Iteration 3 - General improvements - Standard logging #4888

fcaffieri opened this issue Jan 30, 2024 · 5 comments · Fixed by #4897
Assignees

Comments

@fcaffieri
Copy link
Member

fcaffieri commented Jan 30, 2024

Epic #4871

Description

The objective of this issue is to incorporate a standard log for all modules

Tasks

  • Set up a central logger configuration.
  • Set up the same log format
  • Set logging both by console and by file
  • Set logging by module
@wazuhci wazuhci moved this to Triage in Release 4.9.0 Jan 30, 2024
@QU3B1M QU3B1M self-assigned this Jan 30, 2024
@wazuhci wazuhci moved this from Triage to In progress in Release 4.9.0 Jan 30, 2024
@QU3B1M
Copy link
Member

QU3B1M commented Jan 30, 2024

Generic Logger

  • Created a Logger class that generates loggers for the modules or files
    deployability/modules/generic/logger/logger.py
    import logging
    import yaml
    
    
    class Logger:
        """
        A Logger class that configures and provides a logger using a configuration file.
    
        Attributes:
            logger (logging.Logger): The configured logger.
        """
    
        def __init__(self, name: str) -> None:
            """
            Initializes the Logger object.
    
            Args:
                name (str): The name of the logger.
            """
            self._load_config()
            self.logger = logging.getLogger(name)
    
        def _load_config(self) -> None:
            """
            Loads the logging configuration from 'config.yaml' file.
            """
            with open('config.yaml', 'r') as f:
                config = yaml.safe_load(f.read())
                logging.config.dictConfig(config)
    
        def get_logger(self) -> logging.Logger:
            """
            Returns the configured logger.
    
            Returns:
                logging.Logger: The configured logger.
            """
            return self.logger
  • Added a central configuration for the loggers
    deployability/modules/generic/logger/config.yaml
    version: 1
    formatters:
      simple:
        format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    handlers:
      console:
        class: logging.StreamHandler
        level: DEBUG
        formatter: simple
        stream: ext://sys.stdout
      file:
        class: logging.FileHandler
        level: DEBUG
        formatter: simple
        filename: /tmp/deployability.log
    root:
      level: DEBUG
      handlers: [console, file]

Usage

This class could generate loggers for specific files or entire modules. E.g:

  • Logger for specific file/class:
    deployability/modules/generic/ansible.py
    ...
    from modules.generic.logger import Logger
        
    class Ansible:
        def __init__(self, ansible_data, path=None):
        ...
        self.logger = Logger(__name__).get_logger()
    ...
  • Logger for a entire module:
    deployability/modules/allocation/logger.py
    from modules.generic.logger import Logger
    
    logger = Logger("allocator").get_logger()

@QU3B1M QU3B1M linked a pull request Jan 31, 2024 that will close this issue
@QU3B1M
Copy link
Member

QU3B1M commented Jan 31, 2024

Update progress

  • Implemented logger on generic tools (ansible & scheme_validator)
  • Replaced logger handler of the workflow_engine with the new generic logger
  • Implemented logger on Provision module

@wazuhci wazuhci moved this from In progress to Pending review in Release 4.9.0 Feb 1, 2024
@wazuhci wazuhci moved this from Pending review to In review in Release 4.9.0 Feb 2, 2024
@pro-akim
Copy link
Member

pro-akim commented Feb 2, 2024

Review Notes

LGTM

@wazuhci wazuhci moved this from In review to Pending final review in Release 4.9.0 Feb 2, 2024
@wazuhci wazuhci moved this from Pending final review to In final review in Release 4.9.0 Feb 2, 2024
@damarisg damarisg moved this from In final review to Pending final review in Release 4.9.0 Feb 2, 2024
@wazuhci wazuhci moved this from Pending final review to In final review in Release 4.9.0 Feb 2, 2024
@fcaffieri
Copy link
Member Author

Request some improvements and changes here

@wazuhci wazuhci moved this from In final review to On hold in Release 4.9.0 Feb 2, 2024
@wazuhci wazuhci moved this from On hold to In progress in Release 4.9.0 Feb 2, 2024
@wazuhci wazuhci moved this from In progress to Pending final review in Release 4.9.0 Feb 5, 2024
@fcaffieri
Copy link
Member Author

Because the addition of modifications referring to the IDs of processes and threads requires analysis, these changes will be made in this issue #4907

LGTM

@wazuhci wazuhci moved this from Pending final review to Done in Release 4.9.0 Feb 5, 2024
@fcaffieri fcaffieri added level/task Task issue and removed level/subtask Subtask issue labels Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants