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

Update logger #90

Merged
merged 2 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions polymind/core/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os
from enum import Enum
from typing import Any
from typing import Optional

from colorama import Fore, ansi
from dotenv import load_dotenv
Expand Down Expand Up @@ -33,20 +33,26 @@ def __le__(self, other):
def __gt__(self, other):
return self.value > other.value

def __str__(self) -> str:
return self.name

def __repr__(self) -> str:
return self.name

def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super().__new__(cls)
return cls._instance

def __init__(self, logger_name: str, verbose: bool = True, level: Any = logging.INFO):
def __init__(self, logger_name: str, verbose: bool = True, level: Optional[LoggingLevel] = None):
if not hasattr(self, "logger"):
load_dotenv(override=True)
self.logging_level = Logger.LoggingLevel[os.getenv("LOGGING_LEVEL", "TOOL")]
self.logging_level = level if level else Logger.LoggingLevel[os.getenv("LOGGING_LEVEL", "TOOL")]
self.logger = logging.getLogger(logger_name)
self.logger.setLevel(level=level)
self.logger.setLevel(level=self.logging_level.value)
self.formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s (%(filename)s:%(lineno)d)")
self.console_handler = logging.StreamHandler()
self.console_handler.setLevel(level=level)
self.console_handler.setLevel(level=self.logging_level.value)
self.console_handler.setFormatter(self.formatter)
self.logger.addHandler(self.console_handler)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "polymind"
version = "0.0.50" # Update this version before publishing to PyPI
version = "0.0.51" # Update this version before publishing to PyPI
description = "PolyMind is a customizable collaborative multi-agent framework for collective intelligence and distributed problem solving."
authors = ["TechTao"]
license = "MIT License"
Expand Down
Loading