Overview

Project details

The medium-level project to understand context manager implementation in Python.


Tracks: Python

240

number of points you will earn

2

launches to complete the project

5

tasks to complete the project

This project is part of the following tracks:

Learning outcomes

  • Get adapted to the EpicLaunchX learning style.
  • Understand the flow actions at EpicLaunchX.
  • Explore PR and code best practices, and earn your first points.
  • Learn more about GitHub and master the conventional commit style.
  • Use Makefile extensively, explore code formatting, linting style, etc.
  • Learn Context Managers.
  • Use Context Manager for logging logic.

Project Launches & Tasks

launch_1

  • task_1 (50 points)
    • Create a service/logs.py file to manage a logging process.

    • Create a function called log with a level argument.

    • Retrieve the root logger and the current logging level of the logger.

    • Set the logging level to the specified level.

    • In the try block, yield the logger itself.

    • In the finally block, set the logging level to its original state.

    • Remember to implement unit tests for a log method, use pytest for tests.

  • task_2 (45 points)
    • Create a configurator/settings/base.py file to configure logging configuration.

    • Create a LOGGING variable to declare initialization for StreamHandler.

    • LOGGING field must be in dict type.

    • Inside this dictionary, you must set version, disable_existing_loggers, handlers, formatters and loggers.

    • The format of the formatter must be like {datetime - level_name - log_message}

    • Remember to implement unit tests for messages, use pytest for tests.

launch_2

  • task_3 (40 points)
    • Create a domain/models.py file to manage log levels.

    • Create a LogLevel class that inherits from the Enum class.

    • Use the enum to set and check logging levels.

    • Logging levels must be DEBUG, INFO, WARNING, ERROR, CRITICAL from logging module.

    • __str__ method has to return “{class_name}.{enum_type_name}”.

    • Remember to implement unit tests for enum levels, use pytest for tests.

  • task_4 (50 points)
    • Create a domain/validators.py file to validate the level of the log.

    • Create a decorator called validate_log_level.

    • Check if the level is in the kwargs or not. If it is, it must be set to kwargs.

    • Check if the level is validated or not. If it"s not, raise KeyError. If it"s, return the LogLevel value for the corresponding level

    • The last process has to be in the different function to reduce complexity.

    • The validate_log_level method has to be called before log method.

    • Remember to implement unit tests for a validate_log_level method, use pytest for tests.

Log in to launch project