Skip to content

Mekhty111/Chronolog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

⚙️ Chronolog — Smart Auto-Logger and Profiler for Python

Chronolog is an intelligent logging, profiling, and diagnostics system for Python projects.
It automatically tracks all modules, functions, and classes, measures execution time,
archives old logs, and generates detailed reports with avg / min / max / total metrics.


🌟 Why Chronolog?

Chronolog combines time (chrono) and logging (log)
creating a tool that doesn’t just write logs, but tells the story of your code’s execution over time.


🚀 Chronolog Features

  • 🔁 Automatic logging of all functions and methods
  • ⏱️ Execution time measurement with microsecond precision
  • 📊 Performance analytics — average, minimum, and maximum timings
  • 📦 Automatic archiving of logs from each session (ZIP)
  • 🧩 Support for nested modules and classes
  • 🧠 Diagnostics and detailed reports for modules, functions, and classes
  • 🕸 Call Graphs based on trace_id
  • 🗑️ Automatic cleanup of old archives
  • 💡 Built on top of Loguru — a fast and powerful logging engine

📂 Log Structure

logs/
│
├── app_info.log # INFO level logs
├── app_error.log # Errors and exceptions
└── archives/ # Archived logs (.zip)

Before each new session, Chronolog automatically archives previous logs,
keeping a clean and organized history of your program’s runs.


⚙️ Usage Example

import my_project_module
from chronolog import (
    setup_logger_for_module,
    print_all_stats,
    print_wrapped_info,
    get_global_logger
)

logger = get_global_logger()

# Wrap the module to automatically track all functions and classes
setup_logger_for_module(my_project_module)

# Run your main logic
my_project_module.main()

# After execution — print collected statistics
print_all_stats()
print_wrapped_info()

🧩 Example Module (my_project_module.py)

import time

def fetch_data():
    time.sleep(0.3)

def process_data():
    time.sleep(0.4)

class Analyzer:
    def run(self):
        time.sleep(0.2)
        self.subtask()
    
    def subtask(self):
        time.sleep(0.1)

def main():
    fetch_data()
    process_data()
    a = Analyzer()
    a.run()

📊 Example Output from Chronolog

✅ Previous logs archived to: logs/archives/logs_2025-10-27_21-03-00.zip
INFO | my_project_module.fetch_data executed in 0.3019 sec
INFO | my_project_module.process_data executed in 0.4015 sec
INFO | my_project_module.Analyzer.run executed in 0.3016 sec
INFO | my_project_module.Analyzer.subtask executed in 0.1011 sec

=== FINAL EXECUTION STATS ===
📊 Total wrapped functions: 5
📊 Total wrapped classes: 1
📊 Total tracked calls: 4

=== Module Execution Summary ===
📦 my_project_module: 4 calls | total 1.1059 sec | avg 0.2765 sec | min 0.1011 sec | max 0.4015 sec

=== Function Execution Summary ===
🔹 my_project_module.process_data: 1 calls | total 0.4015 sec
🔹 my_project_module.Analyzer.run: 1 calls | total 0.3016 sec
🔹 my_project_module.fetch_data: 1 calls | total 0.3019 sec
🔹 my_project_module.Analyzer.subtask: 1 calls | total 0.1011 sec

🧠 Diagnostics & Analytics

print_wrapped_info()   # shows all wrapped functions and classes
print_all_stats()      # prints performance and timing statistics

Chronolog can also build a call graph (Call Graph) to visualize relationships between functions.


🧰 Core Functions

Function Description

setup_logger_for_module(module_or_class)	#Automatically wraps all functions and methods
print_all_stats()	#Prints aggregated execution statistics
print_wrapped_info()	#Displays wrapped functions and classes
cleanup_old_archives(keep_last=10)	#Deletes old log archives
get_global_logger()	#Returns the active loguru.logger instance

🧾 Installation

pip install -r requirements.txt

Or simply add chronolog.py to your project and import it:

from chronolog import setup_logger_for_module

📄 License

MIT License © 2025 Author: ChronoLab / Mekhty

💬 Feedback

Ideas and suggestions are welcome! Open an Issue or Pull Request on GitHub and help make Chronolog even smarter 🧠.

About

Every millisecond tells a story. Turn your code into a live timeline—profile, log, and visualize execution with zero effort. The magic touch for performance-driven Python.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages