Challenge: Create a Company's Logging System

Get an overview of a company's logging system and implement it using common design patterns.

Problem statement

A software development company is facing challenges in managing its application’s logging system. The lack of a centralized mechanism for managing logs across various modules has led to inconsistencies and difficulties in debugging. To address this issue, the company aims to implement the Singleton design pattern to create a robust and unified logging system.

Tasks

Implement the following tasks in your programming challenge:

Design the Singleton logger

  • Create a Logger class that will act as the singleton instance.
  • Ensure that the Logger class has a private constructor to prevent direct instantiation.
  • Implement a static method that provides access to the single instance of the Logger class.

Logging functionality

  • Integrate the Logger singleton into various modules of the application.

  • Implement logging methods within the Logger class, such as log_info(), log_warning(), and log_error().

  • Demonstrate how the Logger class can maintain a single instance across multiple parts of the application.

Thread safety

  • Address potential thread-safety issues by modifying the Logger class.
  • Research and implement a mechanism to ensure the singleton instance is created thread-safe.
  • Verify the Logger's behavior by simulating concurrent logging requests from multiple threads.

Note: You may practice writing your code in the playground below before moving to its solution lesson.

Get hands-on with 1200+ tech skills courses.