DEV Community

ESTROSEC
ESTROSEC

Posted on

I Built a Custom Python Logger Module without OOP (Console, File & DB Logging)

Table of Contents


Overview

This project is a custom logging module built from scratch in Python using Procedural programming.
It provides a structured, extensible, and lightweight way to capture, format, and store log messages across multiple output formats (console, file, and database).


Features

Key highlights of ESTROSEC’s Python Logger:

  • Multi-Type LoggingTRACE, DEBUG, INFO, SUCCESS, WARNING, ERROR, FATAL
  • Multi-Level LoggingALL, HIGH, MEDIUM, LOW
  • Multi-Output LoggingConsole, File, SQLite Database
  • Named LoggersCreate multiple loggers with custom names/categories
  • Configurable File LoggingChoose custom file paths for .log files
  • Toggleable OutputsEnable/disable console, file, or DB logging dynamically
  • Seamless Procedural IntegrationDesigned for easy integration into Procedural-based projects
  • Lightweight & ReusablePlug-and-play across Python projects

Showcase

Console Logging

  • Clean, modern formatting with coloured output
  • Format: [LoggerName] [Timestamp] [Level] Message

Console Logging

File Logging

  • Same format as console logging (no colours)
  • Stored in .log files for persistence

File Logging

Database Logging (SQLite3)

  • Logs stored in a structured SQLite database
  • Data separated into columns for easy querying & analysis
  • Current limitation: DB file stored in a fixed location (configurable in future roadmap)

Database Logging


Getting Started

1. Download the Code

Download the latest release to get the logger.py module.

2. Add to Your Project

Place the logger.py file in your project directory:

Your-Project/
 ├─ main.py
 └─ logger.py
Enter fullscreen mode Exit fullscreen mode

3. Import the Logger

import logger
Enter fullscreen mode Exit fullscreen mode

Usage

Create a Logger

log = logger.create_logger("MyLogger")
Enter fullscreen mode Exit fullscreen mode

Initialize the Logger

logger.initialize_logger(log, True, True)
Enter fullscreen mode Exit fullscreen mode

Console Logging

logger.fatal(log, "Testing Fatal Log Message %s %d %f" % ("Testing String Concat", 5, 5.5))
logger.error(log, "Testing Error Log Message %s %d %f" % ("Testing String Concat", 5, 5.5))
logger.warning(log, "Testing Warning Log Message %s %d %f" % ("Testing String Concat", 5, 5.5))
logger.success(log, "Testing Success Log Message %s %d %f" % ("Testing String Concat", 5, 5.5))
logger.information(log, "Testing Information Log Message %s %d %f" % ("Testing String Concat", 5, 5.5))
logger.debug(log, "Testing Debug Log Message %s %d %f" % ("Testing String Concat", 5, 5.5))
logger.trace(log, "Testing Trace Log Message %s %d %f" % ("Testing String Concat", 5, 5.5))
Enter fullscreen mode Exit fullscreen mode

Enable File Logging

log.set_toggle_file_logging(True)
Enter fullscreen mode Exit fullscreen mode

Enable Database Logging

logger.set_toggle_file_logging(log, True)
Enter fullscreen mode Exit fullscreen mode

Set File Path for Logs

logger.set_file_path(log, "C:\\Users\\YourName\\logs")
Enter fullscreen mode Exit fullscreen mode

Control Log Levels

Available options:

  • ALL — Logs all message types
  • HIGH — Logs FATAL, ERROR, WARNING, SUCCESS
  • MEDIUM — Logs FATAL, ERROR, WARNING
  • LOW — Logs FATAL, ERROR
logger.set_log_level(log, LogLevel.LOW)
Enter fullscreen mode Exit fullscreen mode

Tech Stack

  • Language: Python 3
  • Modules: inspect, os, enum, datetime, sqlite3
  • Tools: PyCharm, DataGrip, GitHub, Git

Roadmap

  • SQLite Logging
  • MySQL Logging
  • Multi-threaded Logging
  • Async Logging
  • Custom Log Message Types

Resources

Stay updated with new projects, tutorials, and announcements!

Want to get the latest news and updates when they come out?

We will email you with any relevant information as soon as we have it!

Send us an email with the subject line "I LOVE ESTROSEC!"
and a body of "NEWS & UPDATES YAY!"

Top comments (0)